Results 1 to 5 of 5

Thread: Track cron performance

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    4

    Default Track cron performance

    Hi

    I am working under LAMP environment.
    I have various php scripts running in cron scheduler.
    Sometimes it so happens that some of the php scripts or some mysql query fails to run and in such case i am not aware about it.

    I tried doing
    00 07 * * 2 /var/www/html/filename.php | mail -s "XYZ executed" xyz@example.com

    but even if script fails I still get the mail and I remain under impression that cron has run properly.

    Is there any way to find out or track that cron has not run or some script has failed?

  2. #2
    Junior Member
    Join Date
    Jun 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Use this script

    You could do that with a script.

    First write you script to run the php code
    it will look something like this

    I did NOT check for syntax errors so you may want to double check it

    Code:
    !#/bin/bash
    
    #Declarations
    errorLog=error.log
    #Mail
    who2mail="root@localhost"     # The address of who we will inform of the problem
    mailSubject="There was a problem!"     # Set the subject for the mail
    mailmsg="mailmsg.txt"                           # Holds the mail content
    
    # This executes php then pass to echo, you can put several functions 
    # delimited by ";" in between the {} 
    
    { php myFile.php }&& { sayLoud "Execution...succesful"; } || { sayLoud "Execution...Failed!";leaveAndMail; } 
    
        #
        # use this function to output to console and save the output to the log file
        #
        function sayLoud()
        {
            echo $1
            echo $1 >>$errorLog
        }
    
    function leaveAndMail()
        {
            ## Append human friendly message
            echo  > $mailmsg
            echo "There was a problem with the execution of script " $0 " in the " $hostname " server. The error log is attached. ">> $mailmsg
            echo  >> $mailmsg
            echo "===================  START ERROR LOG  ===================" >> $mailmsg
            cat $errorLog >> $mailmsg
            echo "===================   END ERROR LOG   ===================" >> $mailmsg
            echo  >> $mailmsg
            
            ## Appends done, send the mail
            /bin/mail -s "$mailSubject" $who2mail < $mailmsg
            
            # Message content no longer relevant delete
            rm $mailmsg
            
            #Ready to quit
            exit
        
        }

    That script will create a error.log file and a mailmsg.txt file, you will be notified ONYL! if something went wrong, if everything ran ok during execution, you will see the output in the cron mail that you should receive daily.

  3. #3
    Member
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    4

    Default

    Thank you so much for reply.
    But is this script capable of returning error in mysql query or php script?

  4. #4
    Junior Member
    Join Date
    Jun 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Not so sure

    Im not sure, the problem is that we are dealing with bash not php or mysql, if php quits with an error signal then bash will treat it like so, however if it only outputs the error but doesn't quits then the script will continue like nothing happened.

    The script will check only that whatever you ran, exit with a clean exit signal, if it didn't then it will pass to the execution error part of the script.

    You could give it a try, but to be honest I haven't use scripts for such a task, maybe a more complete php script will do it instead of bash.

  5. #5
    Member
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    4

    Default

    Hi

    thanx for the reply...but my php script depends upon fetching data from database which inturn client uploads...so fate of some php files running via cron depends on the data in DB.

    So I want to get alerted if at all cron fails due to errors in Mysql or php..

    Anyways thanx for the bash script,i will try it out.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Track internet access
    By sem007 in forum Linux software
    Replies: 3
    Last Post: 26th February 2011, 11:07 AM
  2. Replies: 6
    Last Post: 26th August 2010, 10:37 AM
  3. Replies: 2
    Last Post: 24th November 2009, 04:01 AM
  4. Script to track the changes made to a file
    By hariharan.nb in forum Shell scripting
    Replies: 1
    Last Post: 11th June 2009, 03:30 PM
  5. track changing in docs file
    By zafar466 in forum Windows Xp/2000/2003 server administration
    Replies: 0
    Last Post: 12th March 2007, 09:53 PM

Posting Permissions

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