13 Replies Latest reply: Jun 25, 2014 7:34 AM by EdStevens RSS

    How to verify cronjob successfull

    ChuongNguyen

      Dear all,


      After set a cron job i check in /var/log/cron and can see the job ran:


           May 19 15:35:01 urac01 crond[6637]: (oracle) CMD (/home/oracle/database_script/lstandby_job/pro_ins_ms_alltransbyday.sh)


      But when i check by run it, the job can not run because i still not compile the procedure:


      /home/oracle/database_script/lstandby_job/pro_ins_ms_alltransbyday.sh

      REPORT_ADMIN.PRO_INS_MS_ALLTRANSBYDAY();

                   *

      ERROR at line 2:

      ORA-06550: line 2, column 14:

      PLS-00905: object REPORT_ADMIN.PRO_INS_MS_ALLTRANSBYDAY is invalid

      ORA-06550: line 2, column 1:

      PL/SQL: Statement ignored


      So, my cron job wont completed successfull, right. Can i know my cron job completed success or not ??


      like AIX it have like this : tail -100 /var/adm/cron/log

      Cron Job with pid: 18743514 Successful
      root      : CMD ( /usr/sbin/dumpctrl -k >/dev/null 2>/dev/null ) : PID ( 3932662 ) : Mon May 19 15:55:00 2014
      Cron Job with pid: 3932662 Successful


      So Thanks


        • 1. Re: How to verify cronjob successfull
          Ratnesh Kumar Roy

          Hi,

           

          To check the cronjob,

           

          first check in /etc/init.d

           

          service crond status

           

          ps -ef| grep cron

           

          check these and posts

          • 2. Re: How to verify cronjob successfull
            ChuongNguyen

            Hi,

             

            i think you not totally get my point

            The crontab is runing, service, process ...

            I just want to know my job completed successfull or not. Mean, i only know my cron job completed sucessful or not when i do select on my database.

             

            Thanks

            • 3. Re: How to verify cronjob successfull
              Frak!!!

              I addition to checking crontab logs,

              you can forward logs generated by the script to a log file.

              • 4. Re: How to verify cronjob successfull
                Dude!

                Assuming you are using Oracle Linux, the log file for cron is /var/log/cron. You can verify it by checking /etc/*syslog.conf.

                 

                For instance:

                 

                crontab -e

                 

                * * * * * ls -l

                 

                # tail /var/log/cron

                May  8 01:10:01 vm213 CROND[2135]: (root) CMD (/usr/lib64/sa/sa1 1 1)

                May 19 12:01:46 vm213 crond[1538]: (CRON) STARTUP (1.4.4)

                May 19 12:01:46 vm213 crond[1538]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 44% if used.)

                May 19 12:01:48 vm213 crond[1538]: (CRON) INFO (running with inotify support)

                May 19 12:09:14 vm213 crontab[1640]: (root) BEGIN EDIT (root)

                May 19 12:09:28 vm213 crontab[1640]: (root) REPLACE (root)

                May 19 12:09:28 vm213 crontab[1640]: (root) END EDIT (root)

                May 19 12:10:01 vm213 CROND[1661]: (root) CMD (ls -l)

                May 19 12:10:01 vm213 CROND[1662]: (root) CMD (/usr/lib64/sa/sa1 1 1)

                May 19 12:11:01 vm213 CROND[1681]: (root) CMD (ls -l)

                 

                In addition, cron will also mail a status report:

                 

                # mail

                Heirloom Mail version 12.4 7/29/08.  Type ? for help.

                "/var/spool/mail/root": 3 messages 1 new

                    1 Cron Daemon           Mon May 19 12:10  26/903   "Cron <root@vm213> ls -l"

                    2 Cron Daemon           Mon May 19 12:11  26/903   "Cron <root@vm213> ls -l"

                >N  3 Cron Daemon           Mon May 19 12:12  25/892   "Cron <root@vm213> ls -l"

                 

                If the job runs as the user Oracle, check the oracle account.

                • 5. Re: How to verify cronjob successfull
                  ChuongNguyen

                  Yes Dude , /var/log/cron show the time cron job begin to start, but not tell us whether cron job completed or not.

                  • 6. Re: How to verify cronjob successfull
                    Dude!

                    The log file shows you what and when something is executed. For instance, you might be running or submitting a command or procedure. From what I understand, an email is sent when the crontask has completed, which also shows the result, such as the termianl output or error, if any.

                    • 7. Re: How to verify cronjob successfull
                      ANURAGDBA INDIA

                      u check cron log

                      as well as  run manually and check on terminal using ./file.sh  with complete execution process.

                       

                      if any changes then restart cron job

                      service /etc/init.d/cron start | stop

                      • 8. Re: How to verify cronjob successfull
                        Anirban Mondal

                        Hi

                            You can use standard output and standard error variables in this case to get the necessary details appended in a log file. Find below the example:

                         

                             0,10,20,30,40,50 * * * * Script name; date >> log file name  2>&1

                         

                             It will append the standard output as well as error with date time in the log file. Hope it helps. Triggering the job from cron entry is the utility of cronjob. It is advisable to check the details of jobs from the log file.

                         

                        Thanks and regards,

                        Anirban Mondal.

                        • 9. Re: How to verify cronjob successfull
                          EdStevens

                          ChuongNguyen wrote:

                           

                          Hi,

                           

                          i think you not totally get my point

                          The crontab is runing, service, process ...

                          I just want to know my job completed successfull or not. Mean, i only know my cron job completed sucessful or not when i do select on my database.

                           

                          Thanks

                          cron is just a job scheduler.  It's not his responsibility to check or log the success or failure of any particular operation within your job.  That's why you need to write your job in such a way as to do its own logging and interpreting of errors.

                          • 10. Re: How to verify cronjob successfull
                            Robert Chase

                            Possibly the simplest thing you could do is add a line to the script that either does logging or can e-mail you when the job completes. 

                            • 11. Re: How to verify cronjob successfull
                              ChuongNguyen

                              Cron Job with pid: 16121882 Successful

                              root      : CMD ( /usr/bin/sh /home/oracle/DB_Warning/monitor_db.sh ) : PID ( 12058668 ) : Wed Jun 25 11:34:00 2014

                              Cron Job with pid: 12058668 Successful

                              oracle    : CMD ( /usr/bin/sh /database/lstandby/scripts/pro_ins_ms_alltransbyday.sh ) : PID ( 15728862 ) : Wed Jun 25 11:35:00 2014

                              root      : CMD ( /usr/sbin/dumpctrl -k >/dev/null 2>/dev/null ) : PID ( 13697152 ) : Wed Jun 25 11:35:00 2014

                              Cron Job with pid: 13697152 Successful

                              Cron Job with pid: 15728862 Successful

                               

                              So  thanks

                              • 12. Re: How to verify cronjob successfull
                                Dude!

                                The cron log simply tells whether or not a particular cron process executed. What does "successful" in such output really tell you? Does it mean that the process was executed successfully as it indicates, or does it mean the task was executed successfully? From what I understand, the cron process may have run successfully, but it does not necessarily mean the task was successful too.

                                 

                                Under Linux, the cron log (/var/log/cron) shows what cron jobs got executed, including data and time, owner and command, but it does not explicitly report "failed" or "successful". You have to check the cron output to see if your cron task was successful. By default, all output is send to the mail facility, or you can use your own mechanism (2>&1) and redirect standard output including standard error output to a log file as previously explained.

                                • 13. Re: How to verify cronjob successfull
                                  EdStevens

                                  ChuongNguyen wrote:

                                   

                                  Doesn't have anything to do with any "magic" you think is being peformed by AIX's cron vs. anyone else's.

                                   

                                  As we've been trying to explain, cron is just a scheduler.  It schedules tasks and submits those tasks for execution at the scheduled time.  It has now knowledge of what those tasks are expected to do and it certainly has no knowledge of whether or not those tasks actually accomplished their tasks in a manner that you or anyone else might consider "successful".  The only thing cron would consider a failure is if some process returned an exit code greater than zero. 

                                   

                                  You send me an email requesting that I do something.

                                  The system reports back that it successfully delivered the email.

                                  The system has no way of knowing or reporting if I did what you asked me to do in the email.

                                   

                                  scheduling tasks in cron is no different.

                                   

                                  If I start a sqlplus session and issue a sql statement that fails, sqlplus will report that with a message, but sqlplus itself still exits with a zero (success) return code.

                                   

                                  It is up to you to determine what constitutes success or failure in a given job.  It is up to you to figure out how to make that determination within the job.  It is up to you to determine how to notify someone of success or failure, within the job. 

                                   

                                  Have you looked at what cron does with any 'uncaptured' output .. output that is written to stdout or stderr?  On my system (Oracle Linux) cron will capture that and send an email to a configured distribution list.  But even at that, it is not a determination of failure or success, it is simply cron saying "hey, your job wrote these messages, here they are"