LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-14-2005, 08:02 AM   #1
petenyce
Member
 
Registered: Sep 2005
Posts: 39

Rep: Reputation: 15
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
 
Old 10-14-2005, 08:04 AM   #2
blindcoder
ROCK Linux
 
Registered: Dec 2003
Location: Berlin, Germany
Distribution: Crystal ROCK
Posts: 108

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

HTH,
Benjamin
 
Old 10-14-2005, 08:32 AM   #3
petenyce
Member
 
Registered: Sep 2005
Posts: 39

Original Poster
Rep: Reputation: 15
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?
 
Old 10-14-2005, 09:29 AM   #4
blindcoder
ROCK Linux
 
Registered: Dec 2003
Location: Berlin, Germany
Distribution: Crystal ROCK
Posts: 108

Rep: Reputation: 15
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
 
Old 10-14-2005, 09:48 AM   #5
petenyce
Member
 
Registered: Sep 2005
Posts: 39

Original Poster
Rep: Reputation: 15
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

Last edited by petenyce; 10-14-2005 at 09:53 AM.
 
Old 10-14-2005, 10:02 AM   #6
blindcoder
ROCK Linux
 
Registered: Dec 2003
Location: Berlin, Germany
Distribution: Crystal ROCK
Posts: 108

Rep: Reputation: 15
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
 
Old 10-14-2005, 10:19 AM   #7
petenyce
Member
 
Registered: Sep 2005
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
Old 10-14-2005, 10:28 AM   #8
blindcoder
ROCK Linux
 
Registered: Dec 2003
Location: Berlin, Germany
Distribution: Crystal ROCK
Posts: 108

Rep: Reputation: 15
Where is the script currently? Try adding the full path to the script, not using ~/.
 
Old 10-14-2005, 10:34 AM   #9
petenyce
Member
 
Registered: Sep 2005
Posts: 39

Original Poster
Rep: Reputation: 15
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

Last edited by petenyce; 10-14-2005 at 10:36 AM.
 
Old 10-14-2005, 11:35 AM   #10
prasanta
Member
 
Registered: Mar 2005
Location: India
Distribution: Debian
Posts: 368

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

-Prasanta
 
Old 10-14-2005, 11:42 AM   #11
fast_rizwaan
Member
 
Registered: Oct 2002
Location: Hyderabad, India
Distribution: Slackware 10.1
Posts: 34

Rep: Reputation: 15
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
 
Old 10-14-2005, 11:56 AM   #12
prasanta
Member
 
Registered: Mar 2005
Location: India
Distribution: Debian
Posts: 368

Rep: Reputation: 37
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
 
Old 10-14-2005, 12:04 PM   #13
petenyce
Member
 
Registered: Sep 2005
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
Old 10-14-2005, 12:15 PM   #14
prasanta
Member
 
Registered: Mar 2005
Location: India
Distribution: Debian
Posts: 368

Rep: Reputation: 37
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
 
Old 10-14-2005, 12:36 PM   #15
petenyce
Member
 
Registered: Sep 2005
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
updatedb daily cron job TranceDude Linux - Software 12 08-25-2005 12:09 PM
Semi-Daily Cron Job Apollo77 Linux - General 8 01-13-2004 02:17 PM
save daily from cron job the whole Web servers data cccc Linux - General 2 09-09-2003 01:28 PM
cron.daily MrJoshua Linux - General 2 03-19-2003 12:09 PM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration