#!/usr/bin/perl ############################################# # UpdateIP.pl - dyndns client # # Jeff Israel # # Licences under GPL # ###################################### # Usage # # Type bed.pl -h or bed.pl --help for Usage # # Command line usage Example: # zymos@zymos scripts]$ bed.pl 3d 4h 9m # # Sandard usage example: # [zymos@zymos scripts]$ bed # # Enter time to sleep(ex. 1d 3h 5m)> 3d 4h 9m # # ###################################### # Configure # programs to be killed gently $program[0] = "dcgui-qt"; $program[1] = "python /home/zymos/BitTorrent-3.4.2/btdownloadcurses.py"; # bed.pl absolute location including bed.pl # ie /home/jimmy/scripts/bed.pl $bedlocation = "/home/zymos/scripts/bed.pl"; # perls location $perllocation = "/usr/bin/perl"; ######################################### # Split the time up into d h m s and return in seconds sub timessplit { @times = split(/ /,$time); $i=0; foreach $temp (@times) { if($temp =~ /d/) { $day = $temp; $day =~ s/d//; } elsif($temp =~ /h/) { $hour = $temp; $hour =~ s/h//; } elsif($temp =~ /m/) { $min = $temp; $min =~ s/m//; } elsif($temp =~ /s/) { $seconds = $temp; $seconds =~ s/s//; } } $_ = $day*60*60*24 + $hour*60*60 + $min*60 + $seconds; } #################################################3 # Prints time pritty like sub timedisplay{ $time = $_; if($time>=86400) { $day = int($time / 86400); print $day,"d "; $time = $time - $day*86400; } if($time>=3600) { $hour = int($time / 3600); print $hour,"h "; $time = $time - $hour*3600; } if($time>=60) { $min = int($time / 60); print $min ,"m "; $time = $time - $min*60; } } #################################################### # Beginging $error = 0; if ($ARGV[0] ne "popup"){ if ($#ARGV + 1 == 0){ print "\nEnter time to sleep(ex. 1d 3h 5m)> "; $time = ; chomp($time); } else{ $time = $ARGV[0] . " " . $ARGV[1] . " " . $ARGV[3]; print "\ntime entered : $time\n"; } $interval = 60; $sec = timessplit()/$interval; $timeleft = $sec; #print "\n $time \n $interval \n $sec \n"; if($time =~ /[0-9]m/ | $time =~ /[0-9]d/ |$time =~ /[0-9]h/){ for($i=1;$i <= $interval; $i++) { #system "clear"; print "["; for($j=1;$j <= $interval; $j++) { if($j<=$i) {print "#";} else {print "-";} } $timeleft = ($timeleft - $sec/60); $timeleft2 = sprintf("%.1f", $timeleft); # &timedisplay($sec); print "]Time:$timeleft2 \n"; sleep($sec); } print "\a"; system "sleep 1"; print "\a"; system "sleep 1"; print "\a"; system "sleep 1"; print "\a"; system "sleep 1"; print "\a"; system "sleep 1"; print "\n\n 60 Seconds before programs get killed (Ctrl-c to kill)\n"; system "xterm -e $perllocation $bedlocation popup&"; sleep(60); foreach $prog (@program) { system "kill -2 \`ps -C \"$prog\" -o pid --no-headers\`"; print "kill -2 \`ps -C \"$prog\" -o pid --no-headers\` \n\n"; } print "\n\n 60 Seconds before System Shutdown (Ctrl-c to kill)\n"; sleep(60); print "halting !!!!!!!!!!!!!!!!\n\n"; #system "halt -p"; } else { print "\n Formating Error!!!!!!!!! \n"; $error = 1; } } elsif ($ARGV[0] eq "popup"){ print <; system "kill \`ps -C bed.pl -o pid --no-headers\`"; } if ($error == 1){ print < 3d 4h 9m # # EndUsage }