cer113
asked on
Running scripts with Cron
Hi
I am practicing with Linux OS (openSUSE11.3) and I would like to get some information how to run script with Cron. For example I have small script under /usr/src directory and it is called script. When I run it it will show me content of the directory.
How would i configure this script for example to run every 15 minutes for example. or for example every day at certain time
Thanks
I am practicing with Linux OS (openSUSE11.3) and I would like to get some information how to run script with Cron. For example I have small script under /usr/src directory and it is called script. When I run it it will show me content of the directory.
How would i configure this script for example to run every 15 minutes for example. or for example every day at certain time
Thanks
> for example every day at certain time
for example, 1:35AM everyday
35 1 * * * /usr/src/script > /dev/null 2>&1
The first five fields are
minute hour day month week
do
man crontab
for more details.
for example, 1:35AM everyday
35 1 * * * /usr/src/script > /dev/null 2>&1
The first five fields are
minute hour day month week
do
man crontab
for more details.
This is a very good and useful URL for the same.
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
ASKER
Ok i got that part OK
how do I start cron service because right now
ps -af | grep crond
root 2236 1971 0 01:12 pts/2 00:00:00 grep crond
which means cron is not running
how do I start cron service because right now
ps -af | grep crond
root 2236 1971 0 01:12 pts/2 00:00:00 grep crond
which means cron is not running
#/etc/init.d/crond start
# chkconfig cront on
# chkconfig cront on
As root
rccron restart
rccron restart
One correct
# chkconfig crond start (It will start crond service after reboot of your system)
# chkconfig crond start (It will start crond service after reboot of your system)
By the way, it seems there are some issue with OpenSuSE 11 crond.
http://fixunix.com/suse/538817-opensuse-11-0-crond-dies.html
http://forums.opensuse.org/english/get-technical-help-here/applications/407585-cronjob-not-longer-working-suse-11-0-a.html
You might want to get the latest patches for your OS and check the system log for some clues since your crond is disappeared, which should start at boot up by default.
http://fixunix.com/suse/538817-opensuse-11-0-crond-dies.html
http://forums.opensuse.org/english/get-technical-help-here/applications/407585-cronjob-not-longer-working-suse-11-0-a.html
You might want to get the latest patches for your OS and check the system log for some clues since your crond is disappeared, which should start at boot up by default.
ASKER
cron service is started but the script was never run. I cant see output of the script and it is supposed to run every 15 minutes
You can not see output on your screen, If you want to see the output then you have to ridirect it in a file, then you would be able to see it.
ASKER
how do I do redirect to a file
15 * * * * /root/your_script.sh > /your_directory/output.txt -`date '+%m-%d-%Y:%H%M'`
It will redirect output in a new file with date and time.
It will redirect output in a new file with date and time.
ASKER
15 * * * * /usr/src/script > /home/noc/output.txt-`date '+%m-%d-%Y:%H%M'`
so this would work
my script is under /usr/src/script where script is name of the script
and redirects to /home/noc/output.txt
so this would work
my script is under /usr/src/script where script is name of the script
and redirects to /home/noc/output.txt
Yes, This should work.
ASKER
unfortunately no luck with this. I cant see any output in output.txt file it is empty
Check the logs in
/var/log/cron.log
If it says something.
/var/log/cron.log
If it says something.
ASKER
there is no cron.log under /var/log
could you please list the contect of of /var/log/ and paste the output here.
# ls -la /var/log/ | grep -i cron
# ls -la /var/log/ | grep -i cron
ASKER
ls -la /var/log/ | grep -i cron shows nothing
i started service with service cron start but nothing
i started service with service cron start but nothing
# ps -ef | grep -i cron (Is it showing anything)
ASKER
ps -ef | grep -i cron
root 4512 1 0 05:01 ? 00:00:00 /usr/sbin/cron
root 4946 3244 0 05:33 pts/1 00:00:00 grep -i cron
root 4512 1 0 05:01 ? 00:00:00 /usr/sbin/cron
root 4946 3244 0 05:33 pts/1 00:00:00 grep -i cron
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
no it didnt create file at all in tmp
i guess this is very hard task to do so i guess i will have to leave this to ask someone in person
i guess this is very hard task to do so i guess i will have to leave this to ask someone in person
ASKER
still have a question
by running this command it doesnt show my script is running
This way it is just outputting something in file but how do i know my script is running
by running this command it doesnt show my script is running
This way it is just outputting something in file but how do i know my script is running
ASKER
yes your command created a file in tmp
chmod +x /usr/src/script
2. setup cron job
crontab -e
*/15 * * * * /usr/src/script > /dev/null 2>&1
or
0,15,30,45 * * * * /usr/src/script > /dev/null 2>&1
(run at every 15 minutes at time 0, 15, 30, 45 each hour)