LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron Job Daily (http://www.linuxquestions.org/questions/linux-newbie-8/cron-job-daily-372979/)

petenyce 10-14-2005 09:02 AM

Cron Job Daily
 
I hav ea exe that i would liek to run every hour every day. Now i placed my file script.sh in my cron daily folder now how do i set it to run?

Any examples would be great i dont know what the next step is


thanks

blindcoder 10-14-2005 09:04 AM

If it is in the cron.daily folder, that should be enough. It just needs to be executable (chmod +x <filename>).

HTH,
Benjamin

petenyce 10-14-2005 09:32 AM

but
 
where do i set the time so it runs daily or on the hour? or if i want it to run at a cetain time? dont i have to set some paremeters? if i place it in the folder how does it know when to run at a cetain time?

blindcoder 10-14-2005 10:29 AM

that depends on distribution.
ROCK, for example, runs the /etc/cron.daily/* files every night at 5 AM. Other distributions might have different times.
If you want to be certain, put the file into ~/bin and enter it into your crontab.
For example, to have a script run every night at 5 AM:
Code:

0 5 * * * ~/bin/script.sh
HTH,
Benjamin

petenyce 10-14-2005 10:48 AM

in my conjob
 
in my cron job i have below. I have script.sh in my root folder and i want it to run every day at 1045am. Heres what i have. Now the last line is what i added. also what does this mean ~/bin is that the root bin folder?

SHELL=/BIN/BASH
PATH=/sbin:/bin:/user/sbin:/usr/bin
MAILTO=ROOT
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.hourly
22 4 * * 0 root run-parts /etc/cron.hourly
42 4 1 * 0 root run-parts /etc/cron.hourly
45 10 * * * ~/script.sh


thanks

blindcoder 10-14-2005 11:02 AM

Re: in my conjob
 
Quote:

Originally posted by petenyce
also what does this mean ~/bin is that the root bin folder?
~/bin means the "bin" directory in the users home directory. ~/ always references the home directory. For a user account, this is usually /home/<username> and for the root user this is usually /root/

Quote:


SHELL=/BIN/BASH
PATH=/sbin:/bin:/user/sbin:/usr/bin

Shouldn't that be "/usr/sbin"?

Quote:


MAILTO=ROOT
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.hourly
22 4 * * 0 root run-parts /etc/cron.hourly
42 4 1 * 0 root run-parts /etc/cron.hourly
45 10 * * * ~/script.sh

This looks not quite right. If this is /etc/crontab you need to modify the last line:
Code:

45 10 * * * root ~/script.sh
The /etc/crontab has a slightly different syntax than the crontab you can edit with the command "crontab -e"
Code:

/etc/crontab:
MINUTE HOUR DAY_OF_MONTH MONTH DAY OF WEEK USER COMMAND

that means that you can have commands in /etc/crontab run as any user you like.
Code:

crontab -e
MINUTE HOUR DAY_OF_MONTH MONTH DAY OF WEEK COMMAND

These commands can only run as the user that the crontab belongs to.

HTH,
Benjamin

petenyce 10-14-2005 11:19 AM

ok
 
im sorry just very confused. in my crontab file i have

SHELL=/BIN/BASH
PATH=/sbin:/bin:/user/sbin:/usr/bin
MAILTO=ROOT
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.hourly
22 4 * * 0 root run-parts /etc/cron.hourly
42 4 1 * 0 root run-parts /etc/cron.hourly
18 11 * * * root ~/script.sh



this does nothing. just wnat my script to run by itself?

thanks

blindcoder 10-14-2005 11:28 AM

Where is the script currently? Try adding the full path to the script, not using ~/.

petenyce 10-14-2005 11:34 AM

ok
 
my script is currently in my root folder. I m logged in as root and have full priviledges. almost their? i wnat the script to run now at 1140 am


SHELL=/BIN/BASH
PATH=/sbin:/bin:/user/sbin:/usr/bin
MAILTO=ROOT
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.hourly
22 4 * * 0 root run-parts /etc/cron.hourly
42 4 1 * 0 root run-parts /etc/cron.hourly
40 11 * * * root /root/script.sh

prasanta 10-14-2005 12:35 PM

The above should work provided the script is executable. You must have restarted your cron daemon.

-Prasanta

fast_rizwaan 10-14-2005 12:42 PM

You can use "at" command also:

add this line at the end of your "script.sh"

echo "$HOME/script.sh"| at now + 1 hour

this will execute the script every hour ;)

prasanta 10-14-2005 12:56 PM

Quote:

You can use "at" command also:
The at command is used to run jobs only once at a given time. If you need to run the job every minute or so one can put it in the cron job.

-Prasanta

petenyce 10-14-2005 01:04 PM

almost
 
well i dont get it. my script.sh is in my root folder. i restarted the crond dameon. and nothing seems to work..... im trying to run my exe at any time today to see if it works. this code below is in my crontab file? Cna i have a example to get this to run


SHELL=/BIN/BASH
PATH=/sbin:/bin:/user/sbin:/usr/bin
MAILTO=ROOT
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.hourly
22 4 * * 0 root run-parts /etc/cron.hourly
42 4 1 * 0 root run-parts /etc/cron.hourly
05 13 * * * root /root/script.sh

prasanta 10-14-2005 01:15 PM

My crontab file looks like this.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.daily
47 6 * * 7 root test -x /usr/sbin/anacron || run-parts --report /etc/cron.weekly
52 6 1 * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.monthly
10 * * * * root /sbin/login.py

I have created a file named login.py file in /sbin. It is running in every 10 mins. I restarted my cron daemon and it works every 10 mins.

-Prasanta

petenyce 10-14-2005 01:36 PM

almost
 
i changed my script below and it dosent run my script???
im logged in as root and placed my file in /usr/local/sbin. im trying to run this script every so minutes to test??

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=ROOT
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.hourly
22 4 * * 0 root run-parts /etc/cron.hourly
42 4 1 * 0 root run-parts /etc/cron.hourly
35 * * * * root /sbin/script.sh


All times are GMT -5. The time now is 04:11 PM.