LinuxQuestions.org

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

petenyce 10-14-2005 08: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 08: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 08: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 09: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 09: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 10: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 10: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 10:28 AM

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

petenyce 10-14-2005 10: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 11:35 AM

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

-Prasanta

fast_rizwaan 10-14-2005 11:42 AM

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 11:56 AM

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 12: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 12: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 12: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

JJX 10-14-2005 12:37 PM

type to a shell:

cron /etc/crontab
so it will read that file ;)

rathodr@meeract 01-01-2006 07:56 PM

I know this is quite late in posting -- and you may have a soln. already. Just to follow-up, I noticed the MAILTO=ROOT. Since Linux is case sensative, would it make a difference if it was changed to MAILTO=root ?

Just a thought.

morrolan 01-04-2006 11:13 AM

OK, What are you trying to run?

Is it an executable script? (chmod 700 scriptname.sh)? What does the script do? You say it is set to run an exe - is that an executable file, or an exe as in the Windows sense of *.exe? Does the script itself run, without using cron? The reason I ask is because if the script itself has a problem, cron won't run it (tries and fails basically).

Now I don't really know cron, but everyone else seems to think that your /etc/cron.daily/crontab will work, so I'm just looking for other possible causes.


------------
EDIT: I've just noticed that this thread is 3 months old...


All times are GMT -5. The time now is 11:13 AM.