Comment/uncomment a cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comment/uncomment a cron
# 1  
Old 05-25-2009
Comment/uncomment a cron

Hi,

My requirement is to comment/uncomment a cron job through a script.

1. Redirected the output of crontab -l to a text file.
crontab -l >cronoutput.txt
2. grep to find the script running and sed to place the comment (#) as
the first char

grep -i 'weblogicmonitor.sh' cronoutput.txt | sed 's/^/#/'

3. I could see the output on the screen,

However my requirement is to keep the "cronoutput.txt" file as it is and place a comment where the 'weblogicmonitor.sh' is located.

Can someone suggest how to comment/uncomment the cron job.
# 2  
Old 05-25-2009
If your version of sed supports it, use -i (inline editing). Otherwise, create a temporary copy of the file, grep & sed that and pipe the result to cronoutput.txt.
# 3  
Old 05-25-2009
Hi Pludi,

thnx for your reply, my unix version doesn't support -i, I am able to grep the script and do a sed on it but my result is a single line, I wan all my old entires in cronoutput.txt too.. any further suggestions !!
# 4  
Old 05-25-2009
Maybe Perl is an option:
Code:
perl -i -pe 's/^/#/ if /weblogicmonitor.sh/i;' cronoutput.txt

# 5  
Old 05-25-2009
Maybe this:
Code:
grep -i 'weblogicmonitor.sh' cronoutput.txt | sed 's/^/#/' > _c  &&  mv -f _c cronoutput.txt

Oops. That was hasty. Maybe this:
Code:
sed  '/weblogicmonitor.sh/s/^/#/' cronoutput.txt > _c  &&  mv -f _c cronoutput.txt


Last edited by KenJackson; 05-25-2009 at 11:24 AM.. Reason: Better solution
# 6  
Old 05-25-2009
An important point here is that after the crontab file is modified, it should be deployed to take the effect.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl uncomment line

Hi guys I am making a bash script, need to un-comment a line remove the"#" Want to accomplish this with a Perl command. Line is like this: #readclients = yes Need it like this: readclients = yes Any help would be really appreciated. (3 Replies)
Discussion started by: Tox
3 Replies

2. Shell Programming and Scripting

To comment/uncomment in config file

hi! I want to comment and uncomment 2 lines in my config files that goes like: CONTACT_LIST="abc@xyz.com;" #CONTACT_LIST="def@xyz.com;" I want to sawp the commnets in above lines and desired output should be: #CONTACT_LIST="abc@xyz.com;" CONTACT_LIST="def@xyz.com;" Please suggest. (1 Reply)
Discussion started by: scriptNovice
1 Replies

3. UNIX for Dummies Questions & Answers

Easiest way to comment/uncomment a shell script?

cd path line1 line2 line3 line4 line5 Lets say thats the sample script...So say if i have to comment the above script, which would be the better way so that whenever i want, i cud comment or uncomment the same. Thanks (1 Reply)
Discussion started by: saggiboy10
1 Replies

4. Shell Programming and Scripting

Uncomment XML block using sed

Hi All, I need to umcomment an XML block (if it's not already uncommented) in a shell script. There are several commented blocks in the file that need to remain commented out. The challenging part for me is that I need to match a comment on one line and an XML tag on the following line. Also,... (0 Replies)
Discussion started by: raiderfan1
0 Replies

5. Shell Programming and Scripting

comment/uncomment grep output

Hi I need help to comment/uncomment the output from grep command output within a file from command line using shell script. # grep -i -p testfs filesystem.out /TestFs: dev = /dev/TestFslv vfs = jfs2 log = /dev/hd8 mount ... (2 Replies)
Discussion started by: mbak
2 Replies

6. Shell Programming and Scripting

uncomment or comment one specific line in a config file

Hello. I want comment or uncomment a ligne in a config file. The file name : /etc/samba/smb.conf Normaly the ligne is uncomment :so the line begin with a tab character followed by passdb backend =\tpassdb backend = In that case I should comment this line ... (2 Replies)
Discussion started by: jcdole
2 Replies

7. Shell Programming and Scripting

comment and uncomment a line with Shell Script

Requirement is: 1. comment and uncomment the line with Shell Script: /opt/admin/fastpg/bin/fastpg.exe -c -=NET (using fastpg.exe as a search option) 2. display = "Commented" (when its commented) and display = "Uncommented" (when its uncommented) Its urgent, please let me asap!!! Thanks in... (2 Replies)
Discussion started by: anthonyraj75
2 Replies

8. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: 22blaze
4 Replies

9. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies

10. AIX

comment jobs in cron for multiple accounts

Hi, We have several jobs scheduled in cron in AIX. Before every release we need to comment those jobs and uncomment those after the release is over. There are several accounts whose cron entries need to be commented. Can anyone provide me with a script which can put a '#' before each line in... (3 Replies)
Discussion started by: shibajighosh
3 Replies
Login or Register to Ask a Question