mirror of
https://github.com/narkoz/hacker-scripts
synced 2025-08-24 03:17:11 +00:00
Add perl/fucking-coffee.pl
Dependencies: - DateTime - Net::Telnet - YAML
This commit is contained in:
parent
4e17743407
commit
c7bce5514c
49
perl/fucking-coffee.pl
Executable file
49
perl/fucking-coffee.pl
Executable file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use DateTime;
|
||||
use YAML;
|
||||
use Net::Telnet;
|
||||
|
||||
# Config
|
||||
my $conf = Load( <<'...' );
|
||||
---
|
||||
coffee_machine_ip: 10.10.42.42
|
||||
password: 1234
|
||||
password_prompt: Password:
|
||||
delay_before_brew: 17
|
||||
delay: 24
|
||||
...
|
||||
|
||||
# Skip on weekends
|
||||
my $date = DateTime->now;
|
||||
if ( $date->day_of_week >= 6 ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
# Exit early if no sessions with my username are found
|
||||
open( my $cmd_who, '-|', 'who' ) || die "Cannot pipe who command ". $!;
|
||||
|
||||
my @sessions = grep {
|
||||
m/$ENV{'USER'}/
|
||||
} <$cmd_who>;
|
||||
|
||||
close $cmd_who;
|
||||
|
||||
exit if ( scalar( @sessions ) == 0 );
|
||||
|
||||
sleep $conf->{'delay_before_brew'};
|
||||
|
||||
my $con = Net::Telnet->new(
|
||||
'Host' => $conf->{'coffee_machine_ip'},
|
||||
);
|
||||
|
||||
$con->watifor( $conf->{'password_prompt'} );
|
||||
$con->cmd( $conf->{'password'} );
|
||||
$con->cmd( 'sys brew' );
|
||||
sleep $conf->{'delay'};
|
||||
$con->cmd( 'sys pour' );
|
||||
$con->close;
|
||||
|
Loading…
x
Reference in New Issue
Block a user