LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   removing # from crontab (bash script) (https://www.linuxquestions.org/questions/programming-9/removing-from-crontab-bash-script-676078/)

inderpunj 10-13-2008 12:49 PM

removing # from crontab (bash script)
 
Hi All,

I am new to scripting. i am creating a script by which it will check all the enteries in crontab and will remove # if any entry will be commented. Please help me to resolve out.
For exp :-
$crontab -l
#*/10 * * * * ./aa.sh
* * * * * ./bb.sh
# * * * * * ./cc.sh

I want to remove # so that the crontab -l should like this :-

*/10 * * * * ./aa.sh
* * * * * ./bb.sh
* * * * * ./cc.sh

Please help me.
Thanks in advance
Inder

TB0ne 10-13-2008 01:07 PM

Quote:

Originally Posted by inderpunj (Post 3308856)
Hi All,

I am new to scripting. i am creating a script by which it will check all the enteries in crontab and will remove # if any entry will be commented. Please help me to resolve out.
For exp :-
$crontab -l
#*/10 * * * * ./aa.sh
* * * * * ./bb.sh
# * * * * * ./cc.sh

I want to remove # so that the crontab -l should like this :-

*/10 * * * * ./aa.sh
* * * * * ./bb.sh
* * * * * ./cc.sh

Please help me.
Thanks in advance
Inder

Check the sed command. Run the file through sed, and remove the "#", such as "sed 's/\#//g'"

PTrenholme 10-13-2008 01:18 PM

Read man sed, and add something like sed s/^[[:space:]]*#// where you want to un-comment a line.

Note that sed normally takes a file as input, so something like sed s/^[[:space:]]*#// /etc/crontab > /etc/crontab.new might work.

You might also think about removing empty lines and trailing comments.

inderpunj 10-13-2008 01:20 PM

Quote:

Originally Posted by TB0ne (Post 3308879)
Check the sed command. Run the file through sed, and remove the "#", such as "sed 's/\#//g'"

Many Thanks for your help

How can i run this command through a script so that it will reflect all the enteries in crontab ?
Thanks
Inder

TB0ne 10-13-2008 02:34 PM

Quote:

Originally Posted by inderpunj (Post 3308899)
Many Thanks for your help

How can i run this command through a script so that it will reflect all the enteries in crontab ?
Thanks
Inder

If you read the man page on SED, or look at any of the Google hits you'd get, you'd see the 'g' at the end of the statement, means to replace all occurrences.


All times are GMT -5. The time now is 02:13 AM.