|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
comment out a cron job as part of a script
Greetings,
I am creating a ksh script to automate the installation of a utility on many servers. As part of this install, I want to check for a job in root's crontab. If the job exists, I need to comment it out. I know I will need to copy off the crontab then read it back in, but I am struggling on commenting the job out while maintaining the integrity of the crontab. The job will have the same path, so this is a constant to check for. The crontab entry might not reside on the same line for each server. Any tips would be appreciated. Thanks |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
You can copy off the crontab, grep for the job name, if found, put a hash at the beginning of the line (you can use sed) and write it back.
Show us the code you have tried so far. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
I am aware of all those steps. It is the syntax of the sed command that I am struggling with. If I just grep for the command and issue the Code:
sed 's/^/#/' #0 10 * * 5 /my/cron/job I only get that single line in my new file. I am not strong with sed and need some help with the [address]. I have tried these and get the same error, Code:
$ crontab -l | sed [/my/cron/job]s/^/#/ Unrecognized command: [/my/cron/job]s/^/#/ $ crontab -l | sed '[/my/cron/job]s/^/#/' Unrecognized command: [/my/cron/job]s/^/#/ |
|
#4
|
||||
|
||||
|
Thats why you should start with posting code to save everyone's time. Here goes: Code:
$ cat cron.sample 0 10 * * 5 /my/cron/job 0 10 * * 5 /other/cron/job $ cat cron.sample |sed '/\/my\/cron\/job/s!^!#!' #0 10 * * 5 /my/cron/job 0 10 * * 5 /other/cron/job |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Understood on the code posting. I will keep this in mind for future posts.
This works great. Thanks for the quick response, much appreciated. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pls comment on my script. | sparcguy | Shell Programming and Scripting | 3 | 11-21-2008 03:18 AM |
| help needed for multiline comment deleting script | aster007 | Shell Programming and Scripting | 1 | 10-10-2008 04:40 AM |
| comment jobs in cron for multiple accounts | shibajighosh | AIX | 3 | 04-08-2008 10:52 AM |
| Block Comment in Shell script | skyineyes | Shell Programming and Scripting | 3 | 07-02-2007 07:15 AM |
| Snapshot of part of the cron | rooh | UNIX for Dummies Questions & Answers | 5 | 07-07-2001 05:30 AM |
|
|