Cron Tab
Cron Tab
Cron Tab
UNIX?
by nixCraft on April 16, 2006 212 comments LAST UPDATED January 21, 2014
in Commands, Linux, UNIX
How do I add cron job under Linux or UNIX like operating system?
Cron job are used to schedule commands to be executed periodically. You can setup commands
or scripts, which will repeatedly run at a set time. Cron is one of the most useful tool in Linux or
UNIX like operating systems. The cron service (daemon) runs in the background and constantly
checks the /etc/crontab file, and /etc/cron.*/ directories. It also checks the
/var/spool/cron/ directory.
crontab command
Tutorial details
Difficulty
Intermediate (rss)
Root privileges
Yes
Requirements
crond
Estimated completion time 20m
crontab is the command used to install, deinstall or list the tables (cron configuration file) used to
drive the cron(8) daemon in Vixie Cron. Each user can have their own crontab file, and though
these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to
use crontab command for editing or setting up your own cron jobs.
that requires root like privileges. The sixth field (see below for field description) is the
name of a user for the command to run as. This gives the system crontab the ability to run
commands as any user.
2. The user crontabs: User can install their own cron jobs using the crontab command. The
sixth field is the command to run, and all commands run as the user who created the
crontab
Note: This faq features cron implementations written by Paul Vixie and included in many Linux
distributions and Unix like systems such as in the popular 4th BSD edition. The syntax is
compatible with various implementations of crond.
OR
1 2 3 4 5 /root/backup.sh
Where,
1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
* * * * command to be executed
- - - | | | |
| | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | ------- Month (1 - 12)
| --------- Day of month (1 - 31)
----------- Hour (0 - 23)
OR
1 2 3 4 5 USERNAME /path/to/script.sh
Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am ..., everyday, enter:
23 0-23/2 * * * /root/scripts/perl/perlscript.pl
asterisk in the hour time field would be equivalent to every hour or an asterisk in the
month field would be equivalent to every month.
2. The comma (,) : This operator specifies a list of values, for example: "1,5,10,15,20, 25".
3. The dash (-) : This operator specifies a range of values, for example: "5-15" days ,
in the hours field to specify command execution every other hour. Steps are also
permitted after an asterisk, so if you want to say every two hours, just use */2.
To mail output to particular email account let us say vivek@nixcraft.in you need to define
MAILTO variable as follows:
MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1
See "Disable The Mail Alert By Crontab Command" for more information.
@yearly
@annually
(same as @yearly)
@monthly
@weekly
@daily
@midnight
(same as @daily)
@hourly
Examples
Run ntpdate command every hour:
@hourly /path/to/ntpdate
First, the environment must be defined. If the shell line is omitted, cron will use the default,
which is sh. If the PATH variable is omitted, no default will be used and file locations will need
to be absolute. If HOME is omitted, cron will use the invoking users home directory.
Additionally, cron reads the files in /etc/cron.d/ directory. Usually system daemon such as saupdate or sysstat places their cronjob here. As a root user or superuser you can use following
directories to configure cron jobs. You can directly drop your scripts here. The run-parts
command run scripts or programs in a directory via /etc/crontab file:
Directory
Description
/etc/cron.d/
Put all scripts here and call them from /etc/crontab file.
/etc/cron.daily/
/etc/cron.hourly/
#!/bin/bash
# A sample shell script to clean cached file from lighttpd web server
CROOT="/tmp/cachelighttpd/"
# Clean files every $DAYS
DAYS=10
# Web server username and group name
LUSER="lighttpd"
LGROUP="lighttpd"
# Okay, let us start cleaning as per $DAYS
/usr/bin/find ${CROOT} -type f -mtime +${DAYS} | xargs -r /bin/rm
# Failsafe
# if directory deleted by some other script just get it back
if [ ! -d $CROOT ]
then
/bin/mkdir -p $CROOT
/bin/chown ${LUSER}:${LGROUP} ${CROOT}
fi
# chmod +x /etc/cron.daily/clean.cache
See man pages for more information cron(8), crontab(1), crontab(5), run-parts(8)
20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
Reply
10 srini August 25, 2014 at 8:31 am
I believe i should be like,
15,30,45,00 * * * * /path/to/script.php
Reply
11 Catweazle February 5, 2015 at 12:35 pm
No like they said above it should be */15 * * * * /path/to/php_script the 15,30,45,00
makes a mess of your crontab.
Reply
12 David W. Jensen December 27, 2006 at 2:45 am
Using Puppy Linux at the moment. How does one check to see if the cron daemon is
running.?
I have a file that works from the command line.
/home/dwj/CRONY/cronf.01 which simply makes a statement on the monitor screen. I
want cron to be able to put a variety of messages on the monitor screen at various times
through the day & week. [ A separate file for each message of course.]
But so far nothing I had tried works. In /var/spool/cron/crontabs/dwj [ my crontab file
which was created using Puppys GUI gcrontab within their control panel, bottom
selection.].
The items in the fields look correct to me vis:
01-59/6 * * * * /home/dwj/CRON/cronf.01
Which is supposed to mean from minute 01-59 each
6 second interval = do the file in field #-6.
What else am I missing or do not understand.?
TIA for any & all help rendered.
Dwj 73 w 0 r m v LONG LIVE LINUX
Reply
13 chiks November 8, 2011 at 4:01 pm
david u know cron job wakes up each and every minute.so u cant
write a cron script which is supposed to run each and every second.
for that u have to write a script and another one u can schedule a particular job
like 7:30:45.
for dis u have to write a script at 7:30 first.give this script name to a.sh.then.
in unix there s a concept called wrapper script in which u will include the sleep
command
write another script called b.sh
in there write
sleep 44 a.sh
then execute it. it will run at 7:30:45
Reply
14 nixCraft December 27, 2006 at 8:46 am
David,
Crontab is designed to work with minutes and upwards it cannot wake up and run task
every second or every 6 second later. cron is not really
designed for such frequent runs.
You need to start your script in background
/home/dwj/CRON/cronf.01 &
in script put logic as follows
while [ true ]; do
sleep 6
# add rest of commands
Done
Reply
15 JDS January 5, 2007 at 4:00 pm
The response to how to run every 15 minutes is wrong. The answer given:
15 * * * * /path/to/script.sh
will run the thing every hour, at the 15 minute mark. (9:15, 10:15, etc)
The proper answer is:
0,15,30 * * * * script.sh
or
0-59/15 * * * * script.sh
(depends on your version of cron)
Reply
16 Manoj October 5, 2010 at 5:10 am
we can run cron job every 15 min using following expression.
*/15 * * * * script.sh
Reply
17 Chitra July 24, 2013 at 9:52 am
Thanks for this post.
Reply
18 Ian Mc March 10, 2011 at 11:42 am
Surely 0,15,30,45 * * * * script.sh
???
Reply
19 zane matthew January 26, 2007 at 4:00 pm
thanks for the help, im at working installing mrtg and setting up my crontab files for the
first time
Reply
20 ashish February 20, 2007 at 7:09 pm
why doesnt crontab work for me .
the crond is running bbut what i want is not happening
/var/spool/cron is unreadable
also crontab -l correctly lists what I want
35 * * * * /usr/bin/gedit
Reply
21 rahul January 30, 2013 at 8:22 am
here u want to write */35 * * * * /usr/bin/gedit
Reply
Reply
28 Jeremy Hannah March 23, 2007 at 8:29 pm
Does the cron job have to reside in /var/spool/cron/crontabs, or can the cronjob reside
anywhere?
Reply
29 nixCraft March 24, 2007 at 4:55 am
Jeremy,
Yup it is the default location under /var file system. You can change this location by
recompiling software.
Reply
30 Aravind Miryala April 7, 2007 at 3:32 pm
I want to schedule cron jobs for First Saturday of Every MOnth. Your help is appreciated
Reply
31 nixCraft April 7, 2007 at 9:53 pm
Aravind,
You need to write a smart script that will detect First Saturday of Every Month as you can
not write such cron job. You can also try following trick:
00 01 1-7 1-12 * if [ "$(date +%a) = "Sat" ]; then /path/to/script.sh;
fi
Reply
33 lucky February 28, 2012 at 4:22 pm
Hi,
pankaj can u tell me how to schedule second saturday of every month and explain how
job run on every first saturday above cronjob.
Reply
34 Valli April 19, 2007 at 2:42 pm
What does 00 14 29 12 4
mean?
Reply
35 John T. April 19, 2007 at 7:28 pm
Vali,
# Use the hash sign to prefix a comment
# +- minute (0 59)
# | +- hour (0 23)
# | | +- day of month (1 31)
# | | | +- month (1 12)
# | | | | +- day of week (0 7) (Sunday=0 or 7)
# | | | | | +- command to be executed
#||||||
# * * * * * command
0 14 29 12 4 /path/to/command
command will be run at 2pm Dec 29th in addition to every Thursday in December I
believe.
Reply
36 Sahithi February 23, 2014 at 8:33 am
In addition to every thursday? or will it run only if Dec29th is thursday
Reply
37 Lakshmi Shastry April 26, 2007 at 7:44 am
I need to write a cron expression which fires every 5 hours from the given start time. Ex:If 8.30 am is my start time then the cron expression will be something like 30 8,0-23/5 *
* *. But this fires in the time sequence like at 8.30, 10.30, 15.30, 20.30, 00.30, 10.30
etc
But what i need the time sequence is 8.30, 13.30, 18.30, 1.30, 6.30, 11.30, 16.30, 21.30,
2.30 which means that fire should occur for the specified start time and every 5 hours
after that. Can anyone help me with the cron expression to represent the same. Thanks a
lot in advance.
Reply
38 rahul November 15, 2010 at 1:09 pm
hey lakshmi ..
firstly you check this command crontab -l Display your crontab file. that show you
presentally crontab.After that see your chron scrip ki chang or not .there is some two
hours interval . You want run this scrip in all day of week. Then in this case you use this
script.. 30 8:30,13:30,18:30,1:30,6:30,11:30,16:30,21:30,2:30 * * # give your
destinestion path#
and other wire u check the chmod permision if this script solve your problem .so plz
reply
Reply
39 rahul November 15, 2010 at 1:11 pm
Then in this case you use this script.. 30 8,13,18,1,6,11,16,21,2 * * # give your
destinestion path#
sorry for that check this script
Reply
40 vinod April 27, 2007 at 3:24 pm
i hope
30 1-23/5 * * * /aaa.sh
will work
Reply
41 GC Hutson May 26, 2007 at 9:18 pm
Since CRON cannot be used to schedule tasks by the second, what can be
used/written/done to perform tasks as such?
Reply
42 Ap_1 May 30, 2007 at 5:35 am
Hi,
I added 1 enrty in crintab using crontab -e,i added below line in that file
0 23 * * 1-5 root echo I will run at 11
but after 11:00 clock also its not running.
y any idea ???
I checked,Cron shell is runningthen y that command didnt run..
Plz help regarding this
Reply
43 Johan August 15, 2007 at 6:06 pm
Hello,
When i try to run crontab i get the following error message failed user root parsing.
And the cron is not executing anything.
The command crontab -l indicates that everything is fine and that i have scheduled a
command correctly.
Also checked that the service is running crond
cant get cron to work please help!
I am using Puppy linux 2.16
Thanks for help, my email is: Johan@mediavisiongroup.se
Reply
44 Ivan Versluis December 19, 2007 at 10:22 am
Thank you. I needed some help on scheduling my ntpdate in a virtual linux machine.
Reply
45 vasanthan January 17, 2008 at 2:53 pm
problem with setting cronjob..
Reply
54 thegetpr March 20, 2008 at 10:34 pm
my crown job is working fine ***** script
but its execution time is very slow, how should i make it fast to work
Reply
55 Nilesh March 21, 2008 at 1:34 am
Use fcron; which doesnt wake up every minute to see whether there is a job to be
executed. It sees the next time when to wake up and wakes up at the particular time only
unless a user edited his fcrontab to wake it up before. It saves resources. The syntax is
quite similar but there is some difference which can be learnt by using.
http://fcron.free.fr
it is available in fedoras repos.
Reply
56 pravin March 31, 2008 at 11:16 am
how do i append new task or crontab job using scprite in existing task
Reply
57 Rajitha May 13, 2008 at 6:52 am
submitting the job in crontab is a bit confusing for the beginners.
in a text file(eg., file.txt) give all the cron jobs you want to schedule
eg., 15 14 * * * /root/dir/script.sh
and submit the file using crontab
crontab file.txt
in order to do this user need to have permisson, which can be seen using cron.allow file
if the crontab file is already existing use crontab -e to add ur job to the crontab.
if it is already existing crontab -l displays the existing jobs
one imp thing to remember is you need to provide all absolute paths in the script which u
want to schedule, otherwise u will end up in thinking why my cron job is not running
though it is added properly.
Reply
58 Diego March 9, 2011 at 5:25 pm
wow, u r the first one in giving basics steps in how to do that. Thaaaaaank uuuu, not all
people are geniuses here!!!
Reply
59 pushp August 23, 2013 at 8:29 am
nice really helpful.i got it.thanks
Reply
60 Hans May 15, 2008 at 9:28 pm
Nice tutorial,
To be complete it would be nice to mention:
/etc/cron.daily
/etc/cron.hourly
/etc/cron.deny
/etc/cron.monthly
/etc/cron.weekly
/etc/cron.d
As these are preferred afair
Reply
61 nixCraft May 16, 2008 at 1:05 pm
Hans,
The faq has been updated.
Reply
62 lalit June 20, 2008 at 6:41 am
Hi
Im new in solaris.I want to create a cron job to delete a temp file in a directory and it run
on every saturday of the week.
Is the eight special string suitable use for all type/version of linux operating system?
(eg.Red-hat, Ubuntu)
Example:
Special string Meaning
@reboot Run once, at startup.
@yearly Run once a year, 0 0 1 1 *.
@annually (same as @yearly)
@monthly Run once a month, 0 0 1 * *.
@weekly Run once a week, 0 0 * * 0.
@daily Run once a day, 0 0 * * *.
@midnight (same as @daily)
@hourly Run once an hour, 0 * * * *.
Reply
69 nixCraft November 25, 2008 at 6:38 am
Ben
Yes, they works with Linux / UNIX as long as your are using Paul Vixies crond.
Reply
70 Ben November 25, 2008 at 9:43 am
Thank you a lot. it is help me a lot.
Reply
71 Subeesh December 9, 2008 at 8:12 am
Hi,
I want to run a script everyday 12:00 am 01:00 pm every 5 minutes,
Please help me
Thanks,
Subeesh
Reply
72 vawani December 8, 2011 at 9:33 pm
*/5 00-13 * * *
Reply
Reply
82 maaly March 26, 2009 at 9:15 pm
write echo command that print hello message on o
every day at a 2 am at the morning for the first week of the month
Reply
83 Subeesh April 2, 2009 at 6:27 am
Hi all,
I want to write cron to run a script from 12 noon to 11:30 pm, every 5 minutes
I have written like this, which I guess, it works from 12 noon to 11 PM only,
0-55/5 12-23 * * * /path/to/command
but how should I re-write it to run the script from 12 noon to 11:30 pm, every 5 minutes ?
Thanks in advance,
Subeesh
Reply
84 Haid Avila April 22, 2009 at 2:28 am
Hi, Ive just made my script and put it into crontab
I want my script to run this command ( opensipsctl fifo lb_resize 1 pstn 0) if ping fails.
It looks like this
#!/bin/bash
# add ip / hostname separated by while space
HOSTS="192.168.0.11"
# no ping request
COUNT=1
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print
$2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
opensipsctl fifo lb_resize 1 pstn 0
fi
done
If I run the script from the command line it works nice and smooth, but if it runs from the
CRON it doesnt work
I have this on my crontab so it will run every minute
0-59 0-23 * * * /etc/opensips/monitor_server1.sh
Reply
99 Rituparna June 23, 2009 at 9:15 am
just a bit of modification to the above
it is 15 14 6 * * //df -h
Reply
100 Rituparna June 23, 2009 at 9:17 am
just a bit of modification to it
15 14 6 * * //df -h
Reply
101 Narendra June 29, 2009 at 5:52 am
Hi,
How can we call php page from CRONTAB in every 5 seconds. I had used this by using
sleep funtion with some logic. Script executes for a time and sleeps for 5 seconds for 10
times within 1 minute interval. But the problem occurred is sever gets too busy when I
called crontab file like this.
So I would like to know how can file be executed in every 5 seconds without any
problem?
Reply
102 nami June 30, 2009 at 5:27 am
does all the files in /etc/cron.daily folder on a daily basis.
Actually i have copied a sh file in this folder yesterday but it did not get executed .
As if this file is executed one of my tables in the database gets updated.
I am not sure whats going wrong
Reply
103 nami June 30, 2009 at 7:21 am
According to this link the files under /etc/cron.daily should get executed.
But in my case its not getting executed
i used putty to copy the file from one of the directories in the system to the /etc/cron.daily
directory.
Would some permissions be causing it to not execute it.
http://www.debian-administration.org/articles/56
Reply
104 nam June 30, 2009 at 8:16 am
This link specifies all the files under this directory will be executed daily
http://www.debian-administration.org/articles/56
But in my case it is not executing is it some permission issue
my crontab file looks like below :
//////crontab////////////////
SHELL=/bin/bash
PATH=/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.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
//////crontab////////////////
There is no cron.allow file.The cron.deny file does not contain anything.
Reply
105 Ben July 30, 2009 at 2:00 am
hi,
if i put both cronjob in crontab which one will run first?
eg:
@yearly Run once a year. 0 0 1 1 * /path/to/command
and
@monthly Run once a month. 0 0 1 * * /path/to/command
Reply
106 Aditya September 14, 2009 at 1:12 pm
Hi i have to run a Command in eyery minute Command is hwclock hctosys , how i can
make entry in Crontab ,m is a new for Crontab ,Please Help me .mine mail id is
Reply
Reply
111 srinivashan November 10, 2009 at 12:32 pm
hai gays
i want to run this cammand daily ( cp /root/desktop/123.flk /root/srinivas/imp files/ )
using corn jobs or is there any other way to run this command daily automaticaly
plz hlp me anyone
thanks srinivas
Reply
112 Jade November 14, 2009 at 2:33 am
Wonderful article. Thanks!
Reply
113 map007 November 20, 2009 at 7:06 am
Hi,
I want to run cron job in every 20 second, so i have created following script.
#!/bin/bash
while true
do
/usr/bin/php -q /home/abc/public_html/Cron.php &
pid=$!
sleep 20
kill -SIGKILL $pid
done
But its not working. Please guide me if i m wrong.
Thank you.
Reply
114 Ducky November 25, 2009 at 10:06 pm
I am new to CRON command. What I want is to have a CRON job execute myWeb
Service which takes two parameters. Maybe I should use a .sh file instead of the whole
URL with parameters in the command line. Can someone give me a simple sample, thank
you.
Reply
115 Ani November 27, 2009 at 4:44 am
Hai,
How to send a request to a webserver all times when i power on my system(fedora)
automatically to indicate im online?
Reply
116 Ramakrishnan December 3, 2009 at 6:31 am
Hi,
how to create cron job for running klinkstatus link checker for daily that must send html
format output from klinkstatus to a emailaddress.
How to create it?
Thanks
Ramakrishnan t
Reply
117 anil December 4, 2009 at 9:45 pm
HI,
I am using cron jobs.It is working fine.It fetches some links and stores in database. But
the problem is when i first run the cron it has fetched 5,000 links per hour.After that it is
very slow.Now not even fetching 100 links per hour.What can i od to improve?
Reply
118 Russty December 23, 2009 at 4:12 pm
I need to know how to make a script run every 20 minutes.
Reply
119 Raj January 2, 2010 at 8:32 am
Guys,
I want the following to run every 1 hour. Can you please tell me what to do?
Reply
124 sss April 28, 2010 at 1:50 pm
how to display which are modified time(mtime) between 5 t0 10 days in unix?
Reply
125 Naseer May 19, 2010 at 6:29 am
how to turn on system automatically while system is in turn off state
Reply
126 johnny June 8, 2010 at 8:58 am
helllo
i have problem about my server elastix
i configure crondtab for automatic reboot
but my mechine cannot reboot time i set.
how to solve..
help me.
thanks
Reply
127 Anonymous June 11, 2010 at 11:14 am
Hi,
Can anyone tell me how to set jobs in cron tab
Reply
128 Anonymous June 11, 2010 at 11:15 am
Kishore,
Can anyone tell me how to run pl/sql jobs in unix.
Reply
129 Santiago June 14, 2010 at 3:57 am
below script is not running on linux, the /bin/sh has been defined in the $PATH. Kindly
advise ?
=======================================
#!/bin/sh
export INFORMIXDIR=/opt/informix/11.50.FC6
export INFORMIXSERVER=czchols1790_1_soc
export ONCONFIG=onconfig_1
export PATH=$INFORMIXDIR/bin:$PATH
export TERMCAP=$INFORMIXDIR/etc/termcap
dbaccess gcdb < bash
Reply
130 Arps June 17, 2010 at 6:22 am
Hi,
i want to create a cron job to check the no of filehandler every hour in my application.
can anyone help me
Reply
131 nany June 21, 2010 at 5:58 am
I set my command at
45 01 * * * /PullMissingFiles/GeneralScripts/GenericPullFilesScript.sh
the script is running for yesterday
MONTH=`TZ=CST+24 date +%m`
DAY=`TZ=CST+24 date +%d`
YEAR=`TZ=CST+24 date +20%y`
if [ ${#DAY} -eq 1 ]
then
DAY=0$DAY
fi
yesterday=$YEAR$MONTH$DAY
but the result is pulling for 2days ago (e.g. if today is 21 we will got the result of 19th)
?????please help me
Reply
132 MSK July 27, 2010 at 11:10 am
I want to schedule a job which will execute only once in life time. Is it possible to
schedule it using cronjob.
Please suggest.
Reply
133 Brian July 28, 2010 at 7:51 am
it could be nice if you could write HOW you append in this so-called-editor that crontab
is using.
Reply
134 vamsi krishna August 18, 2010 at 3:20 pm
hey .,i have few questions
1)how can i append to the existing crontab file of root with automation?
like when i give as root > crontab /var/shell.sh.everythin previously present is getting
vanished.?help me
2)In the end i need to remove this entry at the time of uninstallation of my system?
Thx in advance :)
Reply
135 gaurab August 20, 2010 at 7:20 am
How to set the cron job that runs every week on sunday 10 am.
10 * * * 1/path/to/command
Is the above one correct.Please guide me.
Reply
136 gese74 October 5, 2010 at 5:04 pm
Hello Gaurab,
From your command
10 = tenth minute
* = every hour
* = every day
* = Every month
1 = Monday
So since you have Monday it automatically nullifies the every day.
Reply
141 g September 9, 2010 at 7:10 am
is my SH file is having mistake?
take alook
[quote]
#!/bin/sh
tarikh=$(date +%F_%R);
nama=crm_;
fileHasil=$nama$tarikh.tar.bz;
targetLoc=/usr/share/serverware/backup/;
targetWeb=/var/www/crm/;
echo Processing Backup for $tarikh;
echo Backing up in progress;
tar cvjf $targetLoc$fileHasil $targetWeb;
echo Backed up Success! Saved on $targetLoc$fileHasil;
[/quote]
I could execute it manually,but once I use it at CRONTAB
it never executed why eh?
anyone have experienced about this before?
Reply
142 Reddy September 16, 2010 at 1:38 pm
Hi,
i need to set up a corn job from Linux server to HP server,
Is it possible to set up the corn job from one server to another server without script.
Please advise
Reply
143 Nicole January 7, 2011 at 3:58 am
Hi, could you please help me create a cron job (in php) that will check disk space every
day and will send me email if its 75% full, and will not send me an email if its not.
Thank you so much! im a new bie.
Reply
144 Anbu January 14, 2011 at 8:46 am
I want to kill the jboss server and restart the jboss server in linux machine.
Please provide the solution
Reply
145 a12345 February 21, 2011 at 9:16 am
Hi all,
I want to run a particular script say a.sh daily at some particular time
Is it fine if I place the script which i have to run(a.sh) in cron.daily directory???
or
Do I have to edit crontab???
Please help me out!!!
Thanks in advance!
Reply
146 nixCraft February 21, 2011 at 10:16 am
Yes, place your script in /etc/cron.daily/ so that it will get run once a day. If you need to
run the script, say at particular time (6 pm everyday), than add it to user crontab.
Reply
147 ramaraj ponnan March 3, 2011 at 8:10 am
Hi,
I need a cron job .
if the username and password is wrong while entering into any application, it should
generate a mail to some mail ids, every after 20 sec of logging (error logging)
Reply
148 Shuja Ali March 7, 2011 at 5:56 pm
Hi,
I have a cronjob that runs as follows:
PATH=/usr/bin:/bin:/usr/local/mysql/bin:/opt/TKLCixp/prod/db/utils/sql
22 17 * * * /home/cfguser/housekeeping/Daily_Scripts/Sessions.sh >/dev/null 2>&1
When the script runs it runs a .sql file located in directory
/opt/TKLCixp/prod/db/utils/sql and the error message from mail is shown below:
I have this message coming up any time I want to run crontab,No crontab for root. This
is despite the fact that all my cron commands and files are owned by root. I am using
RHEL 5.5 X 86_64 version of linux. Any help. please?
Reply
156 MrCompTech July 4, 2011 at 6:02 pm
i have a script awstats-mrcomptech.com in the /etc/cron.hourly with the permissions
744, it is owned by root/root but it is not running, It did run at one time, so I must have
inadvertently changed something, but I cant see what I did to cause this hourly cron jobs
to not run!
how are the hourly cron jobs in /etc/cron.hourly triggered to run?
I can manually run the script with /etc/cron.hourly/awstats-mrcomptech.com and it
executes just fine.
This is causing a problem that if I am not available to manually run the script at least
once per day then the awstats for that day show 0 visits even though the apache log file
show over a hundred visits.
Reply
157 MrCompTech July 4, 2011 at 6:10 pm
I found another post on the web that says a blank line is needed at the end of the script
awstats-mrcomptech.com, I added the blank line and will now wait 52 minutes to see if
it runs. i did edit that file so hopefully this will fix the problem!
Reply
158 MrCompTech July 4, 2011 at 7:14 pm
Yes, that did the trick, have to have a blank line for the last line of my cron file!
Reply
159 Lexyz August 4, 2011 at 10:40 am
Can someone explain to me what this script will do?
PATH-TO-PHP -q FULL-LOCAL-PATH-TO-DOMAIN/cron.php
Reply
The instructions you received for using the script are generic. They have to be because
the programmer cannot know on what server OS (Windows/Linux) or what version of the
OS you will be putting the script on.
Are you using purchased web hosting services for your website? If so then depending on
your hosting provider you maybe able to use your cPanel to add the cron job. Most
hosting providers also include How-To video tutorials for their customers. These are
usually located near the top of the cPanel.
If the video tutorials are not sufficient then most likely you will have to contact your web
hosting provider.
If you host your own server or have purchased a VPS (Virtual Private Server) then I may
be able to help you more. For example PHP is usually installed in /usr/bin/php. On your
own server or VPS you must have root access to setup this cron job. But if its not your
server then you most likely do not have root access and that is why you would need to
get instructions from your hosting provider on how they have configured their servers
and whether or not they allow you to add a cron job.
If I were adding this to one of my hosted web sites I would try to use the Cron Jobs
module in the cPanel to add the command to the list of commands as:
php -q /publichtml/cron.php
This may or may not work. My hosting provider does not provide a video on How-To
setup a cron job so if this didnt work I would have to contact my hosting provider for
instructions.
On my own server for my website http;//mrcomptech.com and assuming the file cron.php
were in the root of my website and assuming I wanted this command to run once every
hour..
In the directory /etc/cron.hourly/
I would create the file named mysite.com.cron.php (the name is arbitrary)
and this file would contain these 3 lines:
#!/bin/bash
/usr/bin/php /var/www/clients/client1/web1/web/cron.php > /dev/null
exit 0
Note there is a space after /usr/bin/php.
The file permission would need to be 744 so that the system can execute it.
To test that it worked, at the command prompt, I would run the command
/usr/bin/php /var/www/clients/client1/web1/web/cron.php
and then check to see that what it was supposed to do, it did. The script cron.php is not a
standard script, it is not something that is part of every website. So I cant tell you
specifically what your script is supposed to do without the script and any other scripts to
which it it refers.
Have A Nice Day! (HAND!)
Reply
163 Lexyz August 5, 2011 at 4:42 pm
Thanks for the help.
I will check this out.
Great!
Reply
164 MrCompTech August 5, 2011 at 4:47 pm
You welcome and if you or anyone has any computer/Internet/technology question I
would be happy to answer them at http://mrcomptech.com/index.php/ask-a-technologyquestion
Reply
165 Ashish September 7, 2011 at 8:17 am
Hi,
I would like to schedule a crontab entry for a SAP script which should run quarterly, after
every three month on Saturday (any weekend) but just one Saturday of the month.
I thought of below entry to be added:
0 22 * 3,6,9,12 6
I doubt bcoz of *, this will run on every Saturday of third month, where as I want to run it
just one Saturday of the third month.
Could you please help me to create an entry which fulfil above criteria.
Thanks
Reply
166 MrCompTech September 8, 2011 at 4:03 pm
@ Ashish
I havent tested this but I think this is what you want:
0 22 1-7 3,6,9,12 6
This should run at 22:00 (0 22) but only if it one of the first seven (1-7) days of months
Mar, Jun, Sept, Dec (3,6,9,12) and then only if it is a Saturday (6).
Reply
167 Anup September 15, 2011 at 5:34 pm
Hi,
Im using VPS with cpx control panel in FREEBSD platform and have root access also
thru UNIX command. I need to create a Cron Job schedule for user x to clear his inbox
and Junk mail box every day by 3.00 am. How to do it. Also want to create a job for
SENDMAIL to restart everyday by 3.15 am. Pls help
Anup
Reply
168 Pete September 27, 2011 at 10:26 pm
Awesome article. Love your site, I always get excited to see this.
I *think* there might be a typo for sending emails to a custom address:
MAILTO=vivek@nixcraft.in
0 3 * * * /root/backup.sh >/dev/null 2>&1 (2>&1 seems to disable email).
Im not 100% sure on that, but I couldnt get emails delivered until I removed 2>&1.
Reply
169 Paul Smith October 23, 2011 at 3:09 am
Finally a blog with some insight into cron jobs. I have a question about the email issues. I
have a dedicated server (just learning how to manage) for my websites and host a few of
my friends sites on it also. One of them has a cron job set using cPanel and it reads:
curl -A Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115
Firefox/3.6 -s http://www.hissite.com/billing/coin_cron/invoices.php
However the emails get sent to my server address and not his domain address. I went into
/etc/crontabs but if I change it to his address then all future cronjobs that I wanted to
create would go there also, correct? Not what I want. How do I change it so he and any
future clients emails will be sent to their domain? Sorry if this is confusing as I am just
Hi every on, I newbie too i want to get a buckup of a folder the file is saved in that folder,
I want to know how i can compress that folder like tar and then that compresssed tar file
stored on a sperate location by crontab and should done in a 1 day of the week.
Your comments will be appriciated.
Reply
175 avinash January 22, 2012 at 2:30 am
how to create a folder daily using cron job
Reply
176 kamesh March 29, 2012 at 1:23 pm
Will you create the same folder name every time and in which ath you have to create?
Reply
177 avishay January 22, 2012 at 8:34 am
I added a cron job but it doesnt work. crontab -l shows my script * * * * *
/tmp/some_script
pgrep cron shows 1471.
thanks
Reply
178 sandeep February 13, 2012 at 12:22 pm
may i know how to give cron for 20 seconds
Reply
179 Amit G October 23, 2012 at 10:55 am
smallest resolution is 1min. Look at alternatives : Quartz scheduler
Reply
180 kiran March 27, 2012 at 6:13 am
Hi,
Can any one help me.
i need a cron job to sync data from linux pc/folder to other linux pc folder.
how to add password of other pc in script file.
can any one help me?
Reply
181 vedagiri April 9, 2012 at 9:49 am
how i check whether the cron job running or not?pl any one help me
Reply
182 Mario April 24, 2012 at 3:53 pm
how do I Add a cron job to send a timestamp to a file in their home directory every
minute.
is it
crontab -e
then
* * * * 1 /timestamp/home/user/Documents.
Im dont think this is right. can anyone help
Reply
183 rj2029x October 5, 2012 at 5:46 am
1 * * * * /timestamp/home/user/Documents
1st place = Minutes
2nd place= Hours
3rd place= Days
4th place= Months
5th place = Day of the Week
Reply
184 anonymous October 15, 2012 at 11:27 am
It should be: */1 * * * * /timestamp/home/user/Documents
as if you only do: 1 * * * * /timestamp/home/user/Documents it will do it the first minute
of everyhour and not everyminute of the hour
Reply
185 Jamshed Ahmed Qambrani June 9, 2012 at 8:14 am
Ive configured RMAN backups on daily basis like sundaay, monday, tuesday. these
backup are place on PROD server. now i want a script which copy my daily rman backup
to another server as , from source server A /u01/RMAN/backup/sunday to target server
B /u02/RMAN/backup/09-June-2012 in current date format in which date backup was
take place.
Reply
186 Arjay Almanzor July 16, 2012 at 7:17 am
Can you please send me the example of Crontab script that will backup one folder or that
can automatically generate report on internet.
also the steps how to do it.
thanks.
Reply
187 Reddy March 4, 2013 at 2:02 am
Hi friends
One job scheduled to run on dally on the basis of receiving data from the upstream
environment. My Issue is data had delay one day wat ll do?
waiting for reply
Reddy
Reply
188 Prabhakar Shelke April 4, 2013 at 6:01 am
Hi,
I have total 4 cron job, and these are just send reminder mail to customer, these are given
below,
First Cron every four month Second Cron every four month and 7 days Third Cron
every four month and 14 days Fourth Cron every four month and 21 days
Suggest me How can i set up these cron jobs,
Thanks Inadvance.
Regards,
Prabhakar Shelke.
Reply
189 Pavan May 15, 2013 at 6:24 am
Hi All,
I need to run the cronjob for every 15 days. the script should be executed on saturday and
sunday at evening 8o clock..
Please let me know
Reply
190 Pankaj June 4, 2013 at 6:12 am
Hi..
how to use special staring plz tell me any one.
Reply
191 Debrup Bhattacharjee July 18, 2013 at 9:00 am
I want to run a cron job at 4 AM every morning to clear the /tmp folder on the server.
How can I write this job?
Reply
192 Debrup Bhattacharjee July 18, 2013 at 9:50 am
I want a add a cron job which would run at 3 AM every morning and delete all content in
the /tmp folder. Can someone help me with that?
Reply
193 Erik August 10, 2013 at 3:55 am
I was unable to run this command:
You also need to enable crond service via sys v / BSD init style system. Under RHEL /
CentOS / Fedora, you need to use chkconfig (ntsysv) command to enable crond on boot:
# chekconfg crond on
I see you had a typo there, as well. Im using Lubuntu and it sees no candidate for
chkconfig
Reply
I am not too sure about cron jobs, but there are number of Freeware tools out there (such
as NagiOS), which you can configure to do the monitoring of the hosts and send out alert
notifications based on required conditions.
Reply
200 Jaison April 22, 2014 at 7:09 am
I wish to run this following command on my Linux prompt every hour:
/etc/init.d/symphoniad restart WebClient
I have a text file with this command and saved into the /etc/cron.hourly folder with name
restartwebclient. Will this command get executed every hour? If yes, how do i verify it
and if no, how do i get to execute this command line every one hour.
Kindly advise.
Jaison.
Reply
201 Nix Craft April 22, 2014 at 7:12 am
Check crond log in your /var/log/ directory. On a CentOS/RHEL/Fedora Linux log file
name /var/log/cron.
Reply
202 cyprriot May 19, 2014 at 10:26 am
Hi,
I have a vps system and I have working some job under webmin panel. I need to some
script to check application while its stoped or not. if its stopeed script should be restart
application again. and timely periond check.
thank you
Reply
203 Abhilasha June 10, 2014 at 11:56 am
Hi,
I want to run a cronjob at 10:30 pm and 5:30 am everyday. Can you tell me how to go
about it?
Thanks :).
Reply
204 sasi July 6, 2014 at 2:35 pm
try this below expression
30 5, 22 * * * /path/to/script.sh
Reply
205 Nayelii August 9, 2014 at 10:42 am
Just got bit by this myself. My oipinon is that its not suitable for production systems to
automatically do this. At least put a question to the user if they want this turned on.My
main database runs on an Areca hardware card that autoscrubs a 16 disk RAID-10 but
doesnt get in the way. I have several replicant slaves that have just a pair of 1TB
7200RPM SATA drives because they are read only and dont need massive performance
on IO. They work just fine. Until the first sunday of the month. I dont care about bit rot,
the data is all reproduceable from the master anytime I need it. I can monitor the drives
with smart and replace them as needed easily and cheaply.However, a batch job that takes
6 hours ran for 12 hours last night and every customer I had was bitching about how slow
the system was. In general theres a lot of smart stuff done with mdadm. This is NOT one
of them. Scott Marlowe
Reply
206 Tamirat August 20, 2014 at 5:47 pm
Thanks a lot for sharing this resource by putting shell=/bin/bash I solved error
generated by crone job for not knowing some of the command I used in the bash script
many thanks
Reply
207 Prashanta August 26, 2014 at 3:13 pm
I hava a file media.sh which I intend to run daily. On running ./media.sh , an excel file
test.xlsx is generated. I need to mail the test.xlsx file daily. How can I achieve this using
cron ?
Reply
208 Theo September 22, 2014 at 7:13 pm
Hi al. Most interesting. I have 3 inkjet printers with CISS. And I have Mepis Linux
(KDE). As Im going away for a month I would like to print a file called test-page on
each printer once a week to keep the print heads nice. Is it possible to start my computer
with a script and perform this? (I would have to set wake up permissions in the BIOS I
think) . What would the script look like . I am total newbie to bash and cron etc. Many
thanks in advance for any help/script/instructions you email me.
Reply
209 avinash October 10, 2014 at 2:45 pm
hello,
nice tutorial..very helpfull,
i have a question..
how to schedule a cronjob on 3rd saturday of every mount?
please help me on this..
thankyou
Reply
210 Nagoji November 19, 2014 at 11:24 am
I want to run the cronjob for 2-3 days, can you please help me???
Reply
211 adam January 22, 2015 at 2:55 pm
i should automate several scripts and set a cron job all the scripts are to be done one after
the otherand stop if there is any error andget an email is there a way to do that
thanks,
Reply
212 shufil February 20, 2015 at 3:24 pm
Hi,
i created a bash scrip ,
if (( $(lsof -i:3007 | wc -l) > 0 ))
then
echo $service is running!!!
else
nohup node test_app.js &
fi
Subscribe to nixCraft
Learn something new about Linux/Unix by email
Enter your email address: