Executing a command from shell, but with a delay?
Is there a way to execute a command, but with a specified time delay? I know this can be done with cron but I was wondering if it was possible from the command line. I thought perhaps there was some way to do this via multiple commands per line, e.g. for the command 'rm test.txt':
Code:
[~]# <delay command>; rm test.txt |
I think the command you're looking for is 'sleep'. E.g.
Code:
$ sleep 4; rm test.txt |
the 'at' command also allows you to execute a command at a specified time/date, or a specified amount of time in the future.
|
Thanks, sleep and at are what I was looking for.
For sleep, is there any way multiple commands per line can be executed in the background? For instance, the following gives the error: Code:
# sleep 5 &; rm -f test.php & It took me a while to find the 'at' syntax, apparently you have to do one of the following for 'rm -f test.php': Code:
# echo "rm -f test.php" | at HH:MM Also for 'at', my atd daemon wasn't started; '/sbin/service atd status' said 'atd is stopped', and trying to use at gave the error 'Can't open /var/run/atd.pid to signal atd. No atd running?'. I had to start the atd daemon with: Code:
/usr/sbin/atd |
1. the way to make a group of cmds execute in the background is to put them in a separate file and call that, where the 1st line is the normal sleep cmd.
2. /etc/rc.local is really for the global env (run by root at startup). .bashrc is on a per user basis (as that's where the file is). If you always want atd running, there should be a proper set of stop/start scripts already in /etc/rc.d. Try the chkconfig cmd or there is usually a Services option on the menu, where you can say which runlevels you want it active for. |
Thanks. There is an 'atd' in the /etc/rc.d/init.d directory, but it wasn't running at startup until I placed /usr/sbin/atd in /etc/rc.local. Not sure what's going on there.
|
That's because you're not supposed to put it in /etc/rc.local. Use menu option or chkconfig to make it start itself properly, see the dirs under /etc/rc.d
Ps please post your distro/ver in your profile: GNU/Linux is just a generic name... |
All times are GMT -5. The time now is 01:43 AM. |