File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ # !/usr/bin/perl
2
+
3
+ use strict;
4
+ use warnings;
5
+
6
+ use DateTime;
7
+ use YAML;
8
+ use Net::Telnet;
9
+
10
+ # Config
11
+ my $conf = Load( <<'...' );
12
+ ---
13
+ coffee_machine_ip: 10.10.42.42
14
+ password: 1234
15
+ password_prompt: Password:
16
+ delay_before_brew: 17
17
+ delay: 24
18
+ ...
19
+
20
+ # Skip on weekends
21
+ my $date = DateTime-> now;
22
+ if ( $date -> day_of_week >= 6 ) {
23
+ exit ;
24
+ }
25
+
26
+ # Exit early if no sessions with my username are found
27
+ open ( my $cmd_who , ' -|' , ' who' ) || die " Cannot pipe who command " . $! ;
28
+
29
+ my @sessions = grep {
30
+ m /$ENV {'USER'}/
31
+ } <$cmd_who >;
32
+
33
+ close $cmd_who ;
34
+
35
+ exit if ( scalar ( @sessions ) == 0 );
36
+
37
+ sleep $conf -> {' delay_before_brew' };
38
+
39
+ my $con = Net::Telnet-> new(
40
+ ' Host' => $conf -> {' coffee_machine_ip' },
41
+ );
42
+
43
+ $con -> watifor( $conf -> {' password_prompt' } );
44
+ $con -> cmd( $conf -> {' password' } );
45
+ $con -> cmd( ' sys brew' );
46
+ sleep $conf -> {' delay' };
47
+ $con -> cmd( ' sys pour' );
48
+ $con -> close ;
49
+
You can’t perform that action at this time.
0 commit comments