Both the watch and timeout GNU utilities are very hands for monitoring and putting limits on scripts and programs
using the watch command to repeatedly run a command
#Run the df command every 5 seconds
watch -n 5 df
#run the df command every 5 seconds and highlight the differences
watch -n 5 -d df
Using the timeout command from coreutils to limit the length of time a process can run
timeout 5 top
The timeout command accepts as integer followed by an option unit of either s m h d seconds minutes hours days
Using the at atd atrm commands to schedule once off jobs
If you just want to run some simple command line tools you can enter the commands interactively.
at now + 1 min
warning: commands will be executed using /bin/sh
at> echo seamus > test.txt
at> ^d
If you have a shell script with your commands you can simply use the "-f" option
at -f ./job.sh now + 3 min
Using echo to schedule a job, this is handy to call from another script
echo "echo seamus > test.txt" | at now + 1 min
List the jobs in the queue.
atq
Show the contents of a particular job.
at -c <job number>
Removing a job.
atq
13 Sun Aug 16 22:12:00 2015 a guess
16 Sun Aug 16 22:12:00 2015 a guess
14 Sun Aug 16 22:12:00 2015 a guess
15 Sun Aug 16 22:12:00 2015 a guess
atrm 14
atq
13 Sun Aug 16 22:12:00 2015 a guess
16 Sun Aug 16 22:12:00 2015 a guess
15 Sun Aug 16 22:12:00 2015 a guess
Crontab layout
# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 6) (Sunday=0 or 7)
# | | | | |
* * * * * command to be executed
A little script I wrote back in 2004
#!/bin/bash
if [ $# -le 0 ]
then
echo "USSAGE = count (number) (delay) (command)"
exit
fi
count=$1
while [ $count -ne 0 ]
do
"$3" && sleep $2
count=$(( $count -1 ))
done