Find the answer to your Linux question:
Results 1 to 9 of 9
CRON JOB COMPLETETION 1) How to know whether cronjob has been completed as scheduled. 2) Cronjob often tries to send message to my mail id but i would like to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2011
    Location
    Chennai, Tamilnadu
    Posts
    13

    Smile Cron job completetion


    CRON JOB COMPLETETION
    1) How to know whether cronjob has been completed as scheduled.
    2) Cronjob often tries to send message to my mail id but i would like to find the output in the terminal window ,similar kind of "WALL".
    3) even i tried to output the file to tmp file but i didn't find the file is executing.

    Here is my code
    #!/bin/bash
    MAILTO="xxx"
    01 **** /home/demo1.sh /tmp/cronjob.log

    I don't want the o/p to be sent to my email id rather i would like to show up the output either in a X window as popup or in the terminal window.

    Your valuable assistance and feedback is highly appreciated.

  2. #2
    Just Joined!
    Join Date
    Jul 2011
    Location
    Chennai, Tamilnadu
    Posts
    13
    Please give me with step by step instruction to create a cronjob and find the o/p of it. I am new to linux

  3. #3
    Just Joined!
    Join Date
    Jun 2011
    Location
    Belgium
    Posts
    84
    Start cron with the option -s in your daemon (/etc/init.d/crond or /lib/systemd/system/crond.service) and restart the cron daemon.
    This will direct all outputs to the syslog.

    If you want it for one or more jobs (but not all) there is a workaround:
    start your scheduled job in a script and redirect all outputs (also the errors)
    Example:
    #!/bin/sh
    myCronJob > /tmp/myCronJob.log 2> /tmp/myCronJob.err

  4. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by Ramkumarselvam View Post
    CRON JOB COMPLETETION
    1) How to know whether cronjob has been completed as scheduled.
    2) Cronjob often tries to send message to my mail id but i would like to find the output in the terminal window ,similar kind of "WALL".
    3) even i tried to output the file to tmp file but i didn't find the file is executing.

    Here is my code
    #!/bin/bash
    MAILTO="xxx"
    01 **** /home/demo1.sh /tmp/cronjob.log

    I don't want the o/p to be sent to my email id rather i would like to show up the output either in a X window as popup or in the terminal window.

    Your valuable assistance and feedback is highly appreciated.
    Where did you save that code you've posted? If it is a cronjob, you do not need the #!/bin/bash at the top.

    To create a cronjob, run:
    Code:
    crontab -e
    Now insert the appropriate stuff for the cronjob, e.g.:
    Code:
    MAILTO="xxx"
    1 * * * * /home/demo1.sh /tmp/cronjob.log 2>&1
    Then save and quit the file. Note that /home/demo1.sh must be executable.

    To list your installed cronjobs:
    Code:
    crontab -l
    If the cron daemon is already running, you don't need to restart it - the new job will get picked up.

    Look in the cron log (usually /var/log/cron) for errors, etc. Your log file (/tmp/cronjob.log) should contain the output (STDERR/STDOUT) of your script.

  5. #5
    Just Joined!
    Join Date
    Jul 2011
    Location
    Chennai, Tamilnadu
    Posts
    13
    Hi atreya and Kdg, Thank you so much for your valuable making me understanding this topic, I got the output as u said, but when I changed the output in demo1.sh file and look under the folder /tmp/cronjob.log i am finding the old output as i find before could you please tell me

  6. #6
    Just Joined!
    Join Date
    Jun 2011
    Location
    Belgium
    Posts
    84
    Do you have the logs in /var/log/cron?
    You're sure the sheduled job has run?
    Do you have output(s) when you run demo1.sh directly from a shell process?
    Can you post demo1.sh?

  7. #7
    Just Joined!
    Join Date
    Jul 2011
    Location
    Chennai, Tamilnadu
    Posts
    13
    here is the demo1.sh file
    Clear
    echo "this is testing"
    echo "See the todays date"
    date -u

    When i compile the demo file i am able to get the output but when i put it in cron job i am getting only the first echo window as o/p "This is testing" in /tmp/cronjob

  8. #8
    Just Joined!
    Join Date
    Jun 2011
    Location
    Belgium
    Posts
    84
    I can simulate your error.
    Here's my code for demo1.sh
    Code:
    $> cat demo1.sh
    #!/bin/bash
    clear
    echo "this is testing"
    echo "See the todays date"
    date -u
    You should have a simular line in /etc/crontab (just an example, it will run every 3 minutes):
    0-59/3 * * * * root run-parts /etc/cron.test4Forum
    .
    If your troubles persists, can you also post the configuration files:
    • /etc/crontab
    • /etc/init.d. or /lib/systemd/system/crond.service
    ?

    Don't forget to restart the cron-daemon each time you change one of the these files.
    Code:
    $> service crond restart

  9. #9
    Just Joined!
    Join Date
    Jun 2011
    Location
    Belgium
    Posts
    84
    Do you have a line in /etc/rsyslog.conf like this:
    cron.* /var/log/cron?
    This line means that all cron logs are written in the file /var/log/cron.
    .
    BTW: if you change this file, you should restart the rsyslog-daemon:
    Code:
    $> service rsyslog restart

Posting Permissions

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