Home Man
Search
Today's Posts
Register

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

Tags
aix, crontab, pattern, sed

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 10-09-2013
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

# 2  
Old 10-09-2013
I'd say it doesn't like the / chars in PATTERN. Try to escape them; execute with set -vx
# 3  
Old 10-09-2013
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 10-09-2013
You could also use either "|" or "\\" as a sed limiter,
actualy "," would be possible too - but not in this case.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Crontab command rimob AIX 6 07-19-2016 05:15 AM
Crontab command help thinkingeye UNIX for Dummies Questions & Answers 6 07-09-2015 11:24 AM
How to automate a command to run in crontab? ablakios UNIX for Dummies Questions & Answers 4 03-19-2013 03:55 PM
rcp command is not working in crontab BPANDEY HP-UX 5 09-28-2012 05:44 AM
sed adding/removing comment in crontab BeefStu Shell Programming and Scripting 4 11-08-2010 10:58 AM
crontab doesn't allow `command` ?? tiger2000 Shell Programming and Scripting 1 09-21-2009 04:43 AM
command faster in crontab.. silverlocket Shell Programming and Scripting 2 07-01-2009 04:10 AM
crontab + exec command naushad Shell Programming and Scripting 4 03-27-2008 03:23 AM
getting the date in crontab command pranavagarwal UNIX for Dummies Questions & Answers 7 12-12-2007 12:09 PM
crontab command not working digant UNIX for Advanced & Expert Users 8 01-04-2004 08:46 PM


All times are GMT -4. The time now is 06:11 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password