AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
Expand all | Collapse all

Cron job giving Error while reading txt file

  • 1.  Cron job giving Error while reading txt file

    Posted Sat November 29, 2014 01:27 AM

    Originally posted by: DhirajHaritwal


    Hi,

    I have a bash script which search two files in a path, cat msg.txt to create email body, attached these two files with uuencode & send it to a group defined locally. Now when this cron executed, i am getting email but without attachment & without email body. if i manually run the same script, i am getting email with attachment & email text (body). while checking cron logs, getting below output.

    I have given 777 permissions on the script file & msg.txt. these files having ownership of a custom user & group staff through which these files are getting generated. i have tried to shceule this script on both root user & the custom user cron but same results at both.

    Kindly how wht's wrong here & how to resolve it.

    Your "cron" job executed on Server1 on Sat Nov 29 11:20:00 IST 2014
    sh /DailyJobs/sendemail.sh                                                                                                                                                                                                                               produced the following output:

    cat: 0652-050 Cannot open msg.txt.
    Detail_Err*: A file or directory in the path name does not exist.
    Data_Err*: A file or directory in the path name does not exist.
    Null message body; hope that's ok

    Dhiraj


    #AIX-Forum


  • 2.  Re: Cron job giving Error while reading txt file

    Posted Tue December 02, 2014 09:08 AM

    Originally posted by: Wouter Liefting


    You'd have to post the script itself for me to be certain, but from your output it looks like the script is run when there is no Detail_Err* or Data_Err* file. The shell itself therefore cannot expand those wildcards, and the original name, with the wildcard, is passed to another program, possibly the e-mail program itself. That program does not do wildcard expansion but tries to attach the original name (with the wildcards in it), and that file does not exist. Hence the error.

    In other words, you have not written your script correctly, to handle the fact that the file you're looking for is not there.

    One possible related cause: When executing from cron, the context (mostly your environment variables) is not setup in the same way as an interactive login session. You can't necessarily rely on your active working directory to be the same, $PATH to be the same, and a few other things. If you rely on $PATH, $LANG or any other shell variables, or if you rely on the script being executed in a particular directory, make sure you set these variables and environmental factors yourself.

    BTW the 777 permissions means that anyone on the system can alter your script. It's pretty likely that that's not the intention. 755 or 700 would probably be more appropriate.


    #AIX-Forum


  • 3.  Re: Cron job giving Error while reading txt file

    Posted Thu December 04, 2014 09:29 AM

    Originally posted by: DhirajHaritwal


    Hi,

    Thanks for your response.

    I have double check the files & both are there while the cron is running. infact as i said when i am running the script manually it's working fine. reading the msg.txt file content --> adding it in email body --> searching both files & attaching them in email & sending the email. i am getting the email with all required deatils. the only problem is while running it through Cron. The Crone is scheduled under root user whereas these files (mg.txt / Detail_Err* & Data_Err*) are having onwership of another user. as i mentioned for testing purpose i have given 777 permission so shouldn't be a permission issue.

    Is there any debug logging we can enable to get more detailed logs to check wht's going wrong when this cron is running.

    Dhiraj


    #AIX-Forum


  • 4.  Re: Cron job giving Error while reading txt file

    Posted Wed December 10, 2014 05:13 AM

    Originally posted by: Wouter Liefting


    That debugging would typically be done in your script. Something along the lines of

    if [[ ! -f /tmp/somefile ]]

    then

      echo "File /tmp/somefile does not exist!"

      exit 1

    fi

    cat /tmp/somefile | mail -s "Here is the file" me@me.com

     

    If cron runs a script, any output that is not redirected (via > /dev/null or 2> /dev/null for instance) will be mailed to the owner of the job, so that's where your debug output ends up. Of course, you can also use logger to log to syslog, or setup your own logging file/system.

    For advanced shell script debugging, you may want to turn xtrace on. Man ksh for details.


    #AIX-Forum