-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartat
More file actions
executable file
·48 lines (37 loc) · 929 Bytes
/
Copy pathstartat
File metadata and controls
executable file
·48 lines (37 loc) · 929 Bytes
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
#!/bin/bash
# set program to run
prog=$1
# set timing options
if [ $# -ge 2 ]; then
time=$2
else
echo "usage: startat \"command\" starttime timetorun"
echo "example: startat \"cowsay you rule\" 14:20 10"
echo "note: for timetorun syntax options see \"man sleep\""
exit
fi
if [ $# -ge 3 ]; then
timetorun=$3
else
echo "No timetorun specified, won't stop."
fi
# echo -n "Using current day: "
# echo $(date +"%a %d.")
# calc start and finish time
goal=$(date --date="$(date +"%a %b %d") $time $(date +"%Z %Y")" +%s)
start=$(date +%s)
tleft=`expr $goal - $start`
if [ $tleft -lt 0 ]; then
echo "Error: time passed already."
exit
fi
# sleep until the time has come
sleep $tleft
# run the program in background
$prog &
sleep $timetorun
progname=$(echo $prog | cut -d " " -f1)
if [ "$progname" = "sudo" ]; then
progname=$(echo $prog | cut -d " " -f2)
fi
sudo pkill -x $progname