The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
commenting xml file lines scorpio Shell Programming and Scripting 6 04-28-2009 09:29 PM
commenting simmijaswal Shell Programming and Scripting 2 09-25-2008 11:52 AM
Commenting dreams5617 Shell Programming and Scripting 6 04-16-2007 03:59 PM
Commenting lines rolex.mp UNIX for Dummies Questions & Answers 2 02-21-2007 04:54 AM
commenting more then 1 line ajayyadavmca Shell Programming and Scripting 3 12-14-2006 08:27 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-01-2009
avishek007 avishek007 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 6
Commenting contab from a script

Dear All,
I have many cron entries and want to comment a particular cron entry from a script.
Ex- Suppose I have the below cron entries:

Code:
# DO NOT EDIT THIS FILE - edit the master and reinstall.
#Cron entries for Jboss server 1
0 23 * * * /usr/bin/echo
0 23 * * * /usr/bin/asdg_count.sh
0 23 * * * /usr/bin/true
0 23 * * * /usr/bin/true

I want to comment the entry for asdg_count.sh from my script
I am using the below command:

Code:
(echo ^[:g/watchdog/s/^/#/^[:wq!^M)|crontab -e >> temp.txt

But the command is not working
and I am getting the console message as :

Code:
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
crontab: "vi" exited with status 1

and the message in temp.txt is :

Code:
-- Ip/crontab.XXXXOKeTQL" 7L, 305C
Vim: Error reading input, exiting...
Vim: preserving files...
Vim: Finished.

Please help on commenting the cron from the script.


Thanks
AK

Last edited by Franklin52; 10-02-2009 at 04:33 AM.. Reason: Please use code tags!
  #2 (permalink)  
Old 10-01-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 464
One way which may help you.,

1. Backup the crontab as

crontab -l >> tmpfile.txt

2. Use sed with -i option to substitute.

3. and then remove all crontab.

crontab -r

4. install the new file as

crontab tmpfile.txt

It will work best for you.... instead of trying to do the edition with vim.
Also, note that, if some body else edits that crontab at the same time then you will end up in mess..
  #3 (permalink)  
Old 10-01-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,380
Quote:
Originally Posted by avishek007 View Post
Dear All,
I have many cron entries and want to comment a particular cron entry from a script.
Ex- Suppose I have the below cron entries:
# DO NOT EDIT THIS FILE - edit the master and reinstall.
#Cron entries for Jboss server 1
0 23 * * * /usr/bin/echo
0 23 * * * /usr/bin/asdg_count.sh
0 23 * * * /usr/bin/true
0 23 * * * /usr/bin/true
I want to comment the entry for asdg_count.sh from my script


Code:
crontab -l | sed '/asdg_count.sh/ s/^/#/' | crontab -


Last edited by cfajohnson; 10-02-2009 at 01:44 PM.. Reason: Missing apostrophe added (thanks methyl)
  #4 (permalink)  
Old 10-02-2009
avishek007 avishek007 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 6
crontab -e | sed '/watchdog/ s/^/#/ | crontab -

I guess its not complete ...


please help
  #5 (permalink)  
Old 10-02-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,134
crontab -e, complete or not, is wrong!

crontab -l was mentioned, though.

I would be cautious of automating anything with the crontab file without taking a backup first.


Code:

crontab -l | tee crontab.bak | sed '/asdg_count.sh/ s/^/#/' | crontab -


Last edited by scottn; 10-02-2009 at 04:03 PM.. Reason: good spot, methyl.... added closing apostrophe
  #6 (permalink)  
Old 10-02-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
avishek007 the example you post is looking for a line in crontab containing the word "watchdog" not "asdg_count.sh".

There is a minor typo in cfajohnson's post (missing quote) which has been carried forward into the next two posts. Perhaps that is the problem?


Code:
crontab -l | sed '/asdg_count.sh/ s/^/#/' | crontab -

I would always advise copying crontab to a safe area before editing the file. The rest really depends on local rules.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0