Commenting out a cron entry through a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Commenting out a cron entry through a shell script
# 1  
Old 03-27-2013
Commenting out a cron entry through a shell script

In my cron thare is a line like

24 11 * * * /usr/batch/bin/abc.sh > /usr/batch/log/abc.log 2>&1

along with other entries. I want to comment out this line through a shell script. My local variable 'line'ontains the full entry (i.e. 24 11 * * * /usr/batch/bin/abc.sh > /usr/batch/log/abc.log 2>&1
)

Any suggestion?
# 2  
Old 03-27-2013
List it, comment out that line, store it and feed it back in:
Code:
ct2=$( crontab -l | sed 's/^24 11 . . . .*abc.sh /# &/' )
echo "$ct2" | crontab

It might work as one pipeline, but I think " ... | crontab " clears the crontab before you can list it. You can give it a try, once you have a copy of the crontab in a file!
# 3  
Old 03-27-2013
Thanks. But my variable contains value 24 11 * * * /usr/batch/bin/abc.sh > /usr/batch/log/abc.log 2>&1

i.e. line="24 11 * * * /usr/batch/bin/abc.sh > /usr/batch/log/abc.log 2>&1"

And I have to use line in the command.
# 4  
Old 03-27-2013
Well, sometimes regex is a pain.
  • You can do the substitution in a 'while read line2 ; do case "$line2" in ("$line")' loop, as case's file glob meta are more friendly (but dangerously loose). Maybe skip case in favor of: if [ "$line" = "$line2" ]
  • You can 'fgrep -vx "$line2"" and move it to the end as an append: echo "# $line"
  • You can fgrep each line individually (many fork/exec but no cron file is that long), detectiing a blank output with not blank input.
# 5  
Old 03-28-2013
Thanks. Instead of one line command, I created a loop.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cron entry to pass the value to script

0 I have a script(main.sh) which calls another script(Get_Files.sh) and gets a value in a variable like the below: File_to_Refresh="$(sh /Aug/work/Get_Files.sh /Aug/Work/Universal_File.txt)" Now I have to schedule the script main.sh for 3 different files i.e. the Universal_File.txt with 3... (2 Replies)
Discussion started by: bhartiya007
2 Replies

2. Shell Programming and Scripting

Shell script to find if any new entry in directory

I require a shell script to find if any new entry of dump files present in a particular directory and to send an email if any new entry exists.I had a crontab to run the script for every 5 min. Below are the file names.dump.20150327.152407.12058630.0002.phd.gz... (9 Replies)
Discussion started by: bhas85
9 Replies

3. AIX

Commands to call script work from command line but not from Cron entry

My first post evidently did not materialize so I posted it again: Runnning a cron job every 5 mins to send data files to a state facility. My original cron entry at worked fine: 01,06,11,16,21,26,31,36,41,46,51,56 * * * * /home/sftpuser/stateinoc-from-appname.ksh Somewhere I have a... (1 Reply)
Discussion started by: Skyybugg
1 Replies

4. Shell Programming and Scripting

Commenting Multiple lines using Shell Script

I have an xml file which has following code : <abc-ref> <abc-name>abc.efg.hij.klm</abc-name> </abc-ref> I want to comment this whole section out and I have written the following script : (where "hij" is unique string in the file) TEMPFILE=replaceYY.tmp file=hello.xml sed -n... (6 Replies)
Discussion started by: Dish
6 Replies

5. Shell Programming and Scripting

How to update an entry of another file in a Shell script?

Hi all, Say I have a shell script called update_password.sh - in this script I want to perform a task to update a specified entry of another file (e.g. users.passpords) update_password.sh #!/bin/bash -e PW_FILE_DIR="${A_DIR}/.../..." PW_FILE="users.passwords" I want to update the... (2 Replies)
Discussion started by: isaacniu
2 Replies

6. Shell Programming and Scripting

Commenting lines in Shell script

Hi All, I know we can comment by using "#" .... I want to know... is there any way to comment a whole big script easily.... In a file i need to comment more than 15 lines ........ and check the script and un comment back. I am learning VI now so its taking lot of time to comment and un... (4 Replies)
Discussion started by: firestar
4 Replies

7. Solaris

User entry in both cron.allow and cron.deny

Hello All, Anybody please help me to know ,what happens when a user having entry in both cron.allow and cron.deny files.Wheather the user will be able to access the crontab??? Thanks in advance Vaisakh (5 Replies)
Discussion started by: ksvaisakh
5 Replies

8. Shell Programming and Scripting

shell script to edit file and delete entry

Can anyone provide me a shell script to edit a xml file and delete one entry. To do manually i can edit(vi editor) the file and 'dd' will delete the file.But I wiluld to know if I can do with a script. Thanks in advance Tannu (6 Replies)
Discussion started by: tannu
6 Replies

9. UNIX for Dummies Questions & Answers

capture shell output in cron entry

Hey all, I'm running scripts from cron and I want to capture the output from the 1 file handle. Ex. * * * * * /test.sh 1>test.log. I also want to append a formatted date to the file. * * * * /test.sh 1>test.log_date +%m%d%y but I keep keep getting the output as if I had just added the date... (5 Replies)
Discussion started by: steve72
5 Replies

10. Shell Programming and Scripting

crontab entry modification using shell script

hi Friends, iam trying to write a script which will grep the particular entry in crontab of root and enable/disable it .iam a novice in scripting. your suggestions are most welcome..please help Cheers!! (4 Replies)
Discussion started by: munishdh
4 Replies
Login or Register to Ask a Question