Link to home
Start Free TrialLog in
Avatar of cer113
cer113Flag for Canada

asked on

Running script 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

I already asked this question but the answer was not there

Ok how do i get mail notification that this script was run

I dont see any confirmation that script is running

Thanks
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Your question is still not clear.

Here is the answer of your original question:
https://www.experts-exchange.com/questions/27039930/Running-scripts-with-Cron.html?anchorAnswerId=35766842#a35766842

Your issue is how to make sure if your script run of not.

> When I run it it will show me content of the directory.
Based on your description of your script, you need to pile the output to a file
crontab -e
*/15 * * * * source /home/<user>/.bashrc; /usr/src/script > /tmp/output.log 2>&1

replace <user> for your login name.

1. Change */15 to * so it run every minute for testing
2. Make sure every commands in your /usr/src/script have full path.
or add
export PATH=/usr/bin:/bin:/usr/local/bin
into /usr/src/script  (second line)


Check /tmp/output.log

For email notification, you need to put "redirect your output to file" within your /usr/src/script. Not in the crontab -e.
Then
crontab -e
MAILTO=youremail@dmain.com
*/15 * * * * source /home/<user>/.bashrc; /usr/src/script
ASKER CERTIFIED SOLUTION
Avatar of sshah254
sshah254

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial