Running script with cron

cer113
cer113 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
Your question is still not clear.

Here is the answer of your original question:
http://www.experts-exchange.com/OS/Linux/Q_27039930.html#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
Commented:
To put a script in cron, use the following command (logged in as the user / root)

crontab -e

make entries in the format

m h dom mon dow command

where
m = min (0 - 59)
h = hour (0 - 24)
dom = day of month (1- 31)
mon = month of the year (1 - 12)
dow = day of week (mon, tue, etc.)
command = command to run

so you could have something like
0-59/15 * * * * /usr/src/script

Do 'man crontab' to get all the options.

Or check here - http://adminschoice.com/crontab-quick-reference

Ss

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial