LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-12-2010, 11:55 AM   #1
joesto
LQ Newbie
 
Registered: Jun 2010
Location: liverpool GB
Distribution: ubuntu 10.4
Posts: 18

Rep: Reputation: 0
Question cronjob doing it twice why?


hi all
i have a cronjob that runs every 5 mins and it does what is should but it is going into a log twice so does that mean there is more than one cronjob running is how do i find out?
if i list cronjobs with crontab -e
the script is in the list only once this is the scripts
*/5 * * * * /var/script/Check.sh

and this is the script
process=`ps auxwww | grep CCcam.x86 | grep -v grep | awk '{print $1}'`
if [ -z "$process" ]; then
echo "Couldn't find CCcam.x86 running Restarting CCcam Server "`date` >>/var/cccamlog/cccam.check
/usr/local/bin/CCcam.x86 -d >>/var/cccamlog/CCcamDebug.log
else echo " is still OK! "`date` >>/var/cccamlog/cccam.check
fi

and when i look inn the log i get this
is still OK! Fri Nov 12 16:20:01 GMT 2010
is still OK! Fri Nov 12 16:25:01 GMT 2010
is still OK! Fri Nov 12 16:25:01 GMT 2010
is still OK! Fri Nov 12 16:30:01 GMT 2010
is still OK! Fri Nov 12 16:30:01 GMT 2010
is still OK! Fri Nov 12 16:35:01 GMT 2010
is still OK! Fri Nov 12 16:35:01 GMT 2010
is still OK! Fri Nov 12 16:40:01 GMT 2010
is still OK! Fri Nov 12 16:40:01 GMT 2010
is still OK! Fri Nov 12 16:45:01 GMT 2010
is still OK! Fri Nov 12 16:45:01 GMT 2010
is still OK! Fri Nov 12 16:50:01 GMT 2010
is still OK! Fri Nov 12 16:50:01 GMT 2010

so can some tell me why it is doing it twice?
thanks
joe
 
Old 11-12-2010, 01:07 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,628
Blog Entries: 14

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
What user does the script run as? Which crontab is it in? Is it possible you have it in two different crontabs (e.g. root and the user that normally runs the scrpt)? Check to see what files exist in /var/spool/cron - and verify only one of them contains your check.

Also did you check to see if maybe the check script is already running (e.g. from when you started it from command line during testing maybe with a while loop)?

Also did you try to put it in the /etc/cron/ files for hourly, monthly etc... in addition to standard crontab? If so it may be those other crons that are doing it though they typically don't run every 5 minutes.
 
1 members found this post helpful.
Old 11-13-2010, 01:49 PM   #3
joesto
LQ Newbie
 
Registered: Jun 2010
Location: liverpool GB
Distribution: ubuntu 10.4
Posts: 18

Original Poster
Rep: Reputation: 0
Thumbs up

thanks for the reply and yes there is a crontab file called root which has the same cronjods as the one i set up with crontab -e but there is a
warning is the file that says

DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.P8N5RT/crontab installed on Thu Nov 11 17:12:37 2010)

the file i edit is in /tmp/crontab.JjmZvH/crontab

so how do i stop one of these from running or how do i edit it and reinstall
sorry if this is an obviouse question but i no little about linux
thanks
joe
 
Old 11-13-2010, 03:12 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
The crontab files have not to be modified by hand, so that the cron daemon can be aware of the changes. This is valid for each user's crontab. If you want to modify/remove the root's cron job, just do
Code:
sudo -i
to switch to root, enter your user's password (this assumes you have privileges for system administration) then edit the crontab using
Code:
crontab -e
again. If you want completely remove the crontab use option -r, but first take a look (with option -l) if there are other jobs you want to preserve, just in case!
 
1 members found this post helpful.
Old 11-17-2010, 03:36 PM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,628
Blog Entries: 14

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
As noted in the warning and above post it is best not to edit those files by hand. I was just saying you can look there to see them.

Note that the files are created by crontab -e when run by the given user. That is to say /var/spool/cron/root is created when you run "crontab -e" logged in as root or when you use sudo to run crontab -e. If you ran crontab -e as user, billybob, then there would be a file called /var/spool/cron/billybob. You can have separate crontabs for each user. The crontab for a user runs under that user's id.

I was suggesting that possibly you had more than one crontab file that had the command. If however, you were running crontab -e as root and also saw /var/spool/cron/root you're seeing the same file not two different ones. If however you saw there was /var/spool/cron/root and a /var/spool/cron/billybob that both had the same entries it could explain why it is running twice. You'd then want to eliminate one of them.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
cronjob help LinuxNeo Linux - Newbie 6 10-13-2010 11:54 PM
cronjob janihemang Linux - General 1 05-10-2010 05:43 PM
Cronjob..... milindpk Linux - Newbie 6 05-06-2010 07:52 PM
cronjob dnaqvi Linux - General 5 04-26-2010 05:05 AM
Su in a cronjob michedlp Programming 3 11-06-2003 09:30 AM


All times are GMT -5. The time now is 03:33 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration