Find the answer to your Linux question:
Results 1 to 2 of 2
Hi All, I am new to scripting. i am creating a script by which it will check all the entries in crontab and print all the enteries start with # ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    20

    removing # in crontab (bash script)

    Hi All,

    I am new to scripting. i am creating a script by which it will check all the entries in crontab and print all the enteries start with # and after that it 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 first it print "ok" if # is present at the beginning of the line and then
    I want to remove #
    And please let me know how can i remove # in crontab through a script. so that the crontab -l should like this :-

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

    Please help me.
    Thanks in advance
    Inder

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I'm afraid I don't entirely understand.

    If we imagine that crontab -l looks like:
    Code:
    #*/10 * * * * ./aa.sh
    * * * * * ./bb.sh
    # * * * * * ./cc.sh
    You want the output to be:
    Code:
    ok
    */10 * * * * ./aa.sh
    * * * * * ./bb.sh
    ok
    * * * * * ./cc.sh
    ?

    In any case, checking if a line starts with a '#' can be easily accomplished with sed if you want to use it, or grep if you want to just check within the script. The regular expression is "^#", where '^' indicates the beginning of the string, and the '#' is a literal '#'.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...