Saturday, 22 June 2013

CRONTAB

#crontab -l                  --> lists crontab job
#crontab -e                 --> edits crontab

Q: How to edit crontab for a specific user ?
=> #su - user
        #crontab -e
          OR
       #crontab -e -u user

Q: How to block a user from using crontab ?
=>  #vim /etc/cron.deny
         <username>
      Save & Quit

Format of crontab: 

    *             *             *             *             *          <command>
 min            hr          Date      Month    Day
(0-59)     (0-23)       (1-31)    (1-12)     (0-7)
                                                           0->Sunday
                                                           7->Sunday

Q: Write a crontab, Message="HappyBday", should be displayed on the home directory of user Natasha in a file bdya.txt, every year 12:00 AM , 23rd March.
=> #crontab -e
    0 0 23 3 * echo "HappyBday" >> /home/natasha/bday.txt

Note: '>' means Overrite and '>>" means Append.

Note: Append to a file when question explicitly mentions that.

Ensure you are root if you are running System Commands. eg. system-config-date

No comments:

Post a Comment