1824977 Members
3996 Online
109678 Solutions
New Discussion юеВ

Re: Comments in Crontab

 
SOLVED
Go to solution
Kim Doty
Advisor

Comments in Crontab

I have some cron jobs that we sometimes need to stop running for a few days. I can't find any docs on whether using a # will comment out the line or not, so I've been deleting the line altogether and then replacing it when we want the job again. Does a # in crontab comment out the line like in other unix scripts?
20 REPLIES 20
hpuxrox
Respected Contributor
Solution

Re: Comments in Crontab

One word,

YES

MANOJ SRIVASTAVA
Honored Contributor

Re: Comments in Crontab

Hi Kim

# will comment the command . It will read it as a comment line and not a command line.


Manoj Srivastava
John Carr_2
Honored Contributor

Re: Comments in Crontab

Hi

HP do not support comments in the crontab file.

make a copy of the file then edit the original to remove the non required entries.

John.
John Carr_2
Honored Contributor

Re: Comments in Crontab

Hi

and when you want to put the lines back simply copy the backed up file over the crontab file being used.

John.
Kim Doty
Advisor

Re: Comments in Crontab

Ok, now I'm confused, 2 yeses and a no. I am running HP-UX 11.0 if that makes a difference.
Victor_5
Trusted Contributor

Re: Comments in Crontab

Yes, for sure.
hpuxrox
Respected Contributor

Re: Comments in Crontab

Kim,

YES!

I have been doing it for years.

Darrell Allen
Honored Contributor

Re: Comments in Crontab

Hi Kim,

man crontab says:

<>
Blank lines and those whose first non-blank character is # will be ignored.
<>

It works fine to use comments in your crontab. Blank lines also.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
MANOJ SRIVASTAVA
Honored Contributor

Re: Comments in Crontab

Hi Kim

Please donot be confused , all of us run this stuff . and it works , it is a standard ASCII file and if you see a template which looks like this

#ident "@(#)root 1.14 97/03/31 SMI" /* SVr4.0 1.1.3.1 */
#
# The root crontab should be used to perform accounting data collection.
#
# The rtc command is run to adjust the real time clock if and when
# daylight savings time changes.
#
10 3 * * 0,4 /etc/cron.d/logchecker
10 3 * * 0 /usr/lib/newsyslog
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1
01 0 * * 4 /root/backups/arbdat01_backup.sh
20 4 * * * . /etc/env.BDDM; /opt/BDDM/bin/traceCleanup > /dev/null 2>&1 #BDDM
05 3 * * * . /etc/env.BDDM; /opt/BDDM/bin/DMbackup > /dev/null 2>&1 #BDDM
35 0,12 * * * . /etc/env.BDDM; /opt/BDDM/bin/logchecker > /dev/null 2>&1 #BDDM


at the start you will see lines which are commented , that doesnot mena that the same are ecuted.


All the best.


Manoj Srivastava
John Carr_2
Honored Contributor

Re: Comments in Crontab

Hi Kim sorry to have confused you

I should have said YES because it does work but I have been led to believe by HP that the supported method to do as you wish is using several crontab files rather than comments to stop jobs running.

so YES it does work and its not supported

cheers
John
Jeff Schussele
Honored Contributor

Re: Comments in Crontab

Hi Kim,

One thing to keep in mind is that the crontab file(s) are only read when cron starts up.

So you should edit with the crontab -e command, crontab ~/your_cron_file OR edit the file manually and kill -HUP the cron PID. All methods will "force" a reread of the crontab files.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
hpuxrox
Respected Contributor

Re: Comments in Crontab

Jeff Schussele,

SIGHUP cron? I have never had to do that in the past.

just crontab -e

Works for me everytime.

-Yates
Jeff Schussele
Honored Contributor

Re: Comments in Crontab

Hi Yates,

If one *manually* edits w/o using crontab -e , for example using vi, then one would have to kill -HUP the cron PID.
I agree that crontab -e is the easiest....but you also run the risk of saving a corrupt/typo'd file inadvertently.
The recommended method is to create the file in one's home dir & use the crontab ~/my_cron_file command to let it place it & restart the cron daemon. This also gives one the opportunity to have *several* cron files - precisely what this user is looking for.
But I also use crontab -e frequently.......

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
hpuxrox
Respected Contributor

Re: Comments in Crontab

Jeff Schussele,

You are correct, for the method you stated.

I hope I didn't sound to defensive.

Peace,
Jeff Schussele
Honored Contributor

Re: Comments in Crontab

Hi Yates,

No...not at all.
No offense taken, nor proffered

Have a great day,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Richard Darling
Trusted Contributor

Re: Comments in Crontab

Hi Kim,
Don't know if you are convinced yet, but everytime that we have a holiday I suspend my backups using crontab -e and comment out the backup command with a # sign. I then remove the # sign with crontab -e when I want the backup to be reactivated.
I have never had a problem.
RD
Emanuel Sardenberg
Occasional Advisor

Re: Comments in Crontab


Hi!


Cronfile Example

####
0 8 * * 1,2,4,5 /lnULOGGLOBO.sh 2>&1
0 10 * * 0,3,6 /lnULOGGLOBO.sh 2>&1
#15 * * * * /moncpu.sh > /moncpu.log 2>&1
####

Emanuel Sardenberg
Jack Werner
Frequent Advisor

Re: Comments in Crontab

Hi there,
Here's a little something an
admin should kep in mind, esp if you are changing crontabs for users other than root. If you edit the crontab directly, vi /usr/spool/cron/crontabs/<> then you must recycle the cron daemon for it to "see" the modified crontab. Most systems /etc/inittab launch cron with the "respawn" option, so it is OK to kill the cron pid.
i'm retired
Bill Hassell
Honored Contributor

Re: Comments in Crontab

Just to clarify: HP supports the behavior described in the man page, that is, a comment is defined is a blank line or where the first non-blank character is #, just like a shell. Sorry that someone from HP said it wasn't 'supported'. Perhaps they meant 'recommended', but even then, I would disagree.

cron simply doesn't care what you put in your crontab file as comments. As far as managing crontab files, there are as many methids as there are sysadmins. My method is to always keep root's 'official' crontab file in root's $HOME, specifically in the .cronfiles directory. That way, if a newbie sysadmin blows away the crontab entry, it can easily be restored. You make the changes to the $HOME/.cronfiles/crontab.root file, then simply replace the current crontab entry with:

crontab $HOME/.cronfiles/crontab.root

No restart of cron, no crontab -e, etc. I find that with multiple root admins, this works the best. And the .cronfiles directory keeps the crontab reference a bit hidden.


Bill Hassell, sysadmin
John Carr_2
Honored Contributor

Re: Comments in Crontab

Hi everyone

OK I have messed up real bad but its been interesting to see all the feed back i was told recommended not unsupported. I shall endevour to improve my english grammer, as well as my memory.

John.