Unix/Linux Go Back    


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

Comment out crontab using sed command

AIX


Tags
crontab, pattern, sed

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-09-2013   -   Original Discussion by SKhan
SKhan's Unix or Linux Image
SKhan SKhan is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 9 October 2013, 6:31 AM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Comment out crontab using sed command

I am trying to comment out the crontab entries using sed.
I want to comment it out for a particular environment say '/mypath/scripts/'.

Using the full path as pattern, it is working. but using variable it is not working. i have tried double quotes too. but no luck!



Code:
$ crontab -l

0,20,40 * * * * /mypath/scripts/script1.sh
15,35,55 * * * * /mypath/scripts/script2.sh
5,15,25,35,45,55 * * * * /somepath/somedirectory/script3.sh

$ PATTERN=/mypath/scripts

$ crontab -l > cron.backup
$ sed "/${PATTERN}/s!^!#!" cron.backup > newCron.sample

$ crontab newCron.sample

I have also tried to escape the '$' and the braces also.



Code:
$ sed "/\${PATTERN}/s!^!#!" cron.backup > newCron.sample

$ sed "/\$\{PATTERN\}/s!^!#!" cron.backup > newCron.sample

None of the above is working. but if I use the following code, its working absolutely fine



Code:
$ sed "/\/mypath\/scripts/s!^!#!" cron.backup > newCron.sample

Sponsored Links
    #2  
Old Unix and Linux 10-09-2013   -   Original Discussion by SKhan
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 23 May 2018, 12:42 PM EDT
Location: Aachen, Germany
Posts: 12,740
Thanks: 413
Thanked 3,913 Times in 3,599 Posts
I'd say it doesn't like the / chars in PATTERN. Try to escape them; execute with set -vx
Sponsored Links
    #3  
Old Unix and Linux 10-09-2013   -   Original Discussion by SKhan
SKhan's Unix or Linux Image
SKhan SKhan is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 9 October 2013, 6:31 AM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks RudiC !
I am not familiar with the use of 'set' and could not find any suitable example too. Could you please elaborate on the same?
    #4  
Old Unix and Linux 10-09-2013   -   Original Discussion by SKhan
sea's Unix or Linux Image
sea sea is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 14 October 2016, 2:49 PM EDT
Location: Swissh
Posts: 1,286
Thanks: 256
Thanked 226 Times in 209 Posts
You could also use either "|" or "\\" as a sed limiter,
actualy "," would be possible too - but not in this case.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed adding/removing comment in crontab BeefStu Shell Programming and Scripting 4 11-08-2010 10:58 AM
Comment a line with SED gubbu Shell Programming and Scripting 1 05-26-2010 04:57 PM
Using sed to comment out line in /etc/vfstab deaconf19 Shell Programming and Scripting 9 07-14-2009 02:44 AM
Help using SED to comment XML elements J-Hon Shell Programming and Scripting 4 06-03-2009 01:42 PM
get rid of xml comment by grep or sed RonLii Shell Programming and Scripting 3 05-21-2009 11:10 PM



All times are GMT -4. The time now is 12:47 PM.