Prev: Installed libraries
Next: parens in sed
From: Joe Smith on 30 Oct 2009 10:09 Hello and thanks in advance for any assistance. I have a small bash script that connects to the db using sqlplus and runs a sql script. The script runs perfect if I run it on command line, however when running it on crontab the script does not seem to be able to see on.csv and so goes into the else routine. #!/bin/bash sqlplus login/login @audit.sql sleep 60 #Not sure if needed, but give db time to write on.csv if [ -e on.csv ]; then uuencode on.csv on.csv | mail -s "My Report" myemail(a)myemail.net rm on.csv exit 0 else echo "daily report not run" > badrun.txt mail -s "Report not run" myemail(a)myemail.net < badrun.txt exit 1 fi I figured that maybe cron was looking in the wrong place for on.csv so I changed the code slightly to explicitly show where the file lives (and also cd to the correct directory) so my script becomes: #!/bin/bash cd /usr/mydir sqlplus login/login @audit.sql sleep 60 if [ -e "/usr/mydir/on.csv" ]; then uuencode /usr/mydir/on.csv /usr/mydir/on.csv | mail -s "my report" myemail(a)myemail.net rm /usr/mydir/on.csv exit 0 else echo "report not run" > badrun.txt mail -s "report not run" myemail(a)myemail.net < badrun.txt exit 1 fi This runs from command line, but still cannot see on.csv when run via crontab and script goes into the else routine. (am not getting badrun.txt either, but not concerned about that right now as I am sure this is the same issue) Just to make sure the the sql script wasnt writing to another directory I have this in in .sql script: spool /usr/mydir/on.csv (was originally simply spool on.csv ) Any idea what the difference is when I run this script from cron vs command line? lazydog(a)sdf.lonestar.org SDF Public Access UNIX System - http://sdf.lonestar.org
From: Bit Twister on 30 Oct 2009 11:01 On Fri, 30 Oct 2009 14:09:13 +0000, Joe Smith wrote: > Hello and thanks in advance for any assistance. > I have a small bash script that connects to the db using sqlplus and runs > a sql script. The script runs perfect if I run it on command line, Anytime script runs on command line and fails in cron, is because a PATH or environment is missing. Just for fun, create a cron job put a echo "PATH=$PATH" > /tmp/cron.dump echo " " >> /tmp/cron.dump env | sort >> /tmp/cron.dump which sqlplus >> /tmp/cron.dump 2>&1 which uuencode >> /tmp/cron.dump 2>&1 which mail >> /tmp/cron.dump 2>&1 and check /tmp/cron.dump when it completes.
From: Joe Smith on 30 Oct 2009 11:18 Great idea! Thank you. This should give me enough to go on. On Fri, 30 Oct 2009, Bit Twister wrote: > Date: Fri, 30 Oct 2009 15:01:02 +0000 (UTC) > From: Bit Twister <BitTwister(a)mouse-potato.com> > Newsgroups: comp.unix.shell > Subject: Re: bash script crontab issue > > On Fri, 30 Oct 2009 14:09:13 +0000, Joe Smith wrote: >> Hello and thanks in advance for any assistance. >> I have a small bash script that connects to the db using sqlplus and runs >> a sql script. The script runs perfect if I run it on command line, > > Anytime script runs on command line and fails in cron, is because > a PATH or environment is missing. > > Just for fun, create a cron job put a > echo "PATH=$PATH" > /tmp/cron.dump > echo " " >> /tmp/cron.dump > env | sort >> /tmp/cron.dump > > which sqlplus >> /tmp/cron.dump 2>&1 > which uuencode >> /tmp/cron.dump 2>&1 > which mail >> /tmp/cron.dump 2>&1 > and check /tmp/cron.dump when it completes. > > lazydog(a)sdf.lonestar.org SDF Public Access UNIX System - http://sdf.lonestar.org
From: Seebs on 30 Oct 2009 11:36 On 2009-10-30, Joe Smith <lazydog(a)sdf.lonestar.org> wrote: > I figured that maybe cron was looking in the wrong place for on.csv so I > changed the code slightly to explicitly show where the file lives (and > also cd to the correct directory) so my script becomes: Hmm. I guess the first thing I'd do would be to cheat horribly. Start with exec 3>/tmp/script.log echo >&3 "Script started." pwd >&3 Also, fix the indentation: > #!/bin/bash > cd /usr/mydir > sqlplus login/login @audit.sql > sleep 60 This sleep command (which you probably don't need?) is not contingent on the previous command, so don't indent it. > if [ -e "/usr/mydir/on.csv" ]; then This probably shouldn't be indented either. One obvious question: When you're running in cron, is "sqlplus" in $PATH? echo "PATH: $PATH" >&3 which sqlplus >&3 -s -- Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Joe Smith on 30 Oct 2009 11:53 Found the issue. Thanks all. running which sqlplus on cron: which: no sqlplus in (/usr/bin:/bin) running which sqlplus on command line: oracle/product/10.2.0/CLIENT/bin/sqlplus Thanks everyone for your help!
|
Pages: 1 Prev: Installed libraries Next: parens in sed |