You are not logged in.
Pages: 1
Topic closed
I would like to run a simple shell script every hour. I have crond in my /etc/rc.conf. How can I go about configuring it to run the script every hour? And would it be any different to run a PHP script every hour?
Last edited by tony5429 (2008-06-07 01:17:22)
Offline
$ crontab -e
0 * * * * /bin/sh /path/to/script
cron will email you any output from the command, so consider redirecting the output of the script if there is any
0 * * * * /bin/sh /path/to/script 2>&1 > /dev/null
For php, just use /usr/bin/php /path/to/script. Also see 'man crontab' for more examples and explanation of the syntax.
Offline
Alternatively, you can symlink the script to the /etc/cron.hourly directory:
ln -s /path/to/script.sh /etc/cron.hourly/myscript.sh
There's also /etc/cron.daily and /etc/cron.yearly
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
there is another way to do it
* */1 * * * /bin/sh /path/to/script
is there any different between them??
Offline
there is another way to do it
* */1 * * * /bin/sh /path/to/script
is there any different between them??
Yes - that will still run every minute, of every hour
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
edward.al wrote:there is another way to do it
* */1 * * * /bin/sh /path/to/script
is there any different between them??
Yes - that will still run every minute, of every hour
*/60 * * * * /bin/sh /path/to/script
it run every 60 minutes, not every hour at minute 0 ?:/
Offline
*/60 * * * * /bin/sh /path/to/script
it run every 60 minutes, not every hour at minute 0 ?:/
Yes, that will... What you originally posted wouldn't
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Thanks! It works! One question though... I am creating the shell script directly in /etc/cron.hourly. How do I tell that not to send me an e-mail of the output each time it runs?
Offline
Inside your script, you'll have to redirect everything that produces output to /dev/null
For example:
echo "this is output" > /dev/null
If you want to suppress error output too, use the &> redirector:
echo "this is output" &> /dev/null
If I have a script like that, I find it easier to add it to the crontab (using crontab -e) and just redirect the output of the whole script:
*/60 * * * * /path/to/script > /dev/null
Last edited by fukawi2 (2008-06-06 11:28:31)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Perfect; thanks!
Offline
Hrm... actually I am running into a problem... In each case below, I am showing the contents of my shell script (/etc/cron.hourly/shcrontest.sh)...
This works, but sends me an e-mail each time:
mkdir /home/karam/shcrontestworked
This fails to ever create the directory:
echo "mkdir /home/karam/shcrontestworked" > /dev/null
This also fails to ever create the directory:
echo "mkdir /home/karam/shcrontestworked" &> /dev/null
I do have it set to chmod +x (-rwxr-xr-x). I am sure I am missing something very simple here. Can anyone help?
Offline
Got it!
mkdir /home/karam/shcrontestworked > /dev/null 2>&1
Last edited by tony5429 (2008-06-07 07:24:10)
Offline
That's it - sorry, I can see how I was confusing in my last post
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
hm..
neat..
Last edited by veranyon (2010-02-15 01:24:53)
ArchLinux x86_64 /AMD Phenom x4 9550/4 GB RAM/ASUS M3N78-EM/GeForce 9800 GT/DELL 2408 VFP
[img]http://img17.imageshack.us/img17/3443/111bzf.gif[/img]
Offline
Holy ancient thread Batman!
Offline
Pages: 1
Topic closed