-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbed
executable file
·211 lines (185 loc) · 5.65 KB
/
bed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/perl
######################################
#
# bed v2.0
#
#
#
#
#Usage
#
# Type bed -h or bed --help for Usage
#
# Command line usage Example:
# zymos@zymos scripts]$ bed 3d 4h 9m
#
# Sandard usage example:
# [zymos@zymos scripts]$ bed
#
# Enter time to sleep(ex. 1d 3h 5m)> 3d 4h 9m
#
#
#
######################################
# Configure
# bed.pl absolute location including bed.pl
# ie /home/jimmy/scripts/bed.pl
$bedlocation = "/usr/scripts/bed";
$xtermlocation = "/usr/bin/xterm";
# perls location
$perllocation = "/usr/bin/perl";
$shutdown_command = '/usr/scripts/shut';
#########################################
# 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 = <STDIN>;
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 "$xtermlocation -e $perllocation $bedlocation popup&";
print "\n\n 60 Seconds before System Shutdown (Ctrl-c to kill)\n";
sleep(60);
print "halting !!!!!!!!!!!!!!!!\n\n";
# system "/sbin/shutdown -hP 1";
system "$shutdown_command";
}
else {
print "\n Formating Error!!!!!!!!! \n";
$error = 1;
}
}
elsif ($ARGV[0] eq "popup"){
print <<EndWarn;
#########################################################################
#///////////////////////////////////////////////////////////////////////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\**\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#/////////////////////////////////%%@*//////////////////////////////////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\%%%@*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#/////////////////////////////////%%%@*/////////////////////////////////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\%%%@*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#/////////////////////////////////%%%@*/////////////////////////////////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\%%%@*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#/////////////////////////////////%%@*//////////////////////////////////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\%%@*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#//////////////////////////////////%@*//////////////////////////////////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\@*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#//////////////////////////////////@////////////////////////////////////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#//////////////////////////////////**///////////////////////////////////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\%%@*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#/////////////////////////////////%%@*//////////////////////////////////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#///////////////////////////////////////////////////////////////////////#
#////Your/Computer/Will/Shutdown/In/Two/Min/If/You/Don't/Kill/bed////#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#########################################################################
EndWarn
print "Hit Enter to Kill bed ";
$time = <STDIN>;
system "kill \`ps -C bed -o pid --no-headers\`";
}
if ($error == 1){
print <<EndUsage;
######################################
# Usage
#
# Type bed -h or bed --help for Usage i.e.this
#
# Command line usage Example:
# [person\@computer scripts]\$ bed 3d 4h 9m
#
# Sandard usage example:
# [person\@computer scripts]\$ bed
#
# Enter time to sleep(ex. 1d 3h 5m)> 3d 4h 9m
#
#
EndUsage
}