Problem with crontab

Hi,

I have one script which takes data from table and spools it into a file.
When i am running manually all is fine but while trying same script thru crontab the spooled file is not getting generated..... :confused:

The mail part is working fine....only prob is the spooled file.

Please help....!

One point to start from: use absolute paths (e.g. /bin/grep instead of grep), thus making sure cron knows what you want :wink:

As always - check out the FAQs first.

I am using complete path.....the script is even executing but only the spool part is not happening......!

---------- Post updated at 11:46 AM ---------- Previous update was at 11:44 AM ----------

sorry....but u asked me to check FAQ for wat?

Post your script. And Under which user you are running it?..

Did you specify the full path name for the spooled file? If not you may find the file in the root directory.

I only placed file on server and also did entry in crontab..!

The script is running fine if i manually run at that location but everything remaining same when it runs from crontab entry the spooled_file is not getting created.....!

I am using full paths everywhere....!

Let's get some base facts.

Which Operating System?
Which Shell?
Which database engine?
What is in the script?
What is in the crontab line?
Which user did you use test from the command line?
Which user owns the crontab?
Any error messages in unix mail for the user?

I wud be posting all details, just let me know how to check who owns crontab?

---------- Post updated at 08:41 PM ---------- Previous update was at 07:41 PM ----------

1) Sun Solaris
2) Ksh shell
3) sqlplus (Oracle)
4) Code

#!/bin/ksh
LOG=/log/AT.log
MESSAGE=/log/MESSAGE_AT.txt
mail_list=/AT_MAIL_LIST.txt
data=/log/spooled_AT.log
SIGNATURE=/log/AT_Signature.txt
echo "`date` Starting execution for ATCOUNT" > $LOG
 
RESULT=`$ORACLE_HOME/bin/sqlplus -s schema/pwd@abc << EOF
        set echo off;
        set heading off;
        set feedback off;
        set trimspool on;
        @/log/AT.sql
`
echo $RESULT >> $LOG
 
echo " `date` End of step generation of AT COUNT has completed" >> $LOG
 
touch temp_file
touch temp1
echo "AT count is "> temp_file
cat $data >> temp_file
cat temp_file $SIGNATURE > temp1
mv temp1 $MESSAGE
rm temp_file
 
mailx -r"abc@aaa.com" -s " ATT PMT NIKU Count `date` "  `cat $mail_list`<$MESSAGE
echo "mail has been sent" >> $LOG

Code for sql file:

spool /log/spooled_AT.log
select count(*) from AT;
spool off;
exit;
 

5) Crontab Line

 
25 12 * * * /scripts/AT_COUNT.ksh
 

6 & 7 ) same user is used for both crontab and manual run
8) No error.

I am creating multiple files, all working fine, then y only spooled one is having error...... Pls Help.......!

  1. don't assume crontab knows about $ORACLE_HOME
  2. temp_file and temp1 have no 'absolute' path definition

Once again - I'd strongly encourage looking into the FAQs.

Nice to see the shebang line at the top of the script.

Agreed. As a minimum for the Oracle environment we'll need:

ORACLE_HOME="/wherever_oracle_home_is"   ;  export ORACLE_HOME
ORACLE_SID="sidname"  ; export ORACLE_SID
PATH="${PATH}:${ORACLE_HOME}/bin"  ; export PATH

There still may be a question about which user? When issuing the "crontab" command the default user is "root" unless you specify a different user. If we assume that this is a root cron it may be inappropriate to run an Oracle program if Oracle is using the unix username for authentication.
For example when I use root cron to run a script as user "oracle" I use something like this:

15 20 * * * su oracle -c "/home/oracle/scripts/scriptname"

Tip about cron. Write a one line script and run it once from cron to see the cron environment. Then compare with the the output from "env" in the user environment.

env >/tmp/cron_env.lst

Footnote:
I can't explain why there were not error messages in mail for the user. If this is a root cron, the errors should be in root mail.

1 Like

Please check the right access to the user from which you are trying to spool the data.

  1. User must have right access to the directory/mount your are trying to spool into
  2. Try to write the error in a log file.

30 18 * * * /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log

Hi all,

sory i was unable to look into solutions....!
Will work on that...
just for info a mail got generated in which said

/home/fid/AT.ksh[18]  /bin/sqlplus:  not found

will get back to you soon.!
Thanks for replies.

Thanks alll........!!!!

my script is now running on server...... :slight_smile:

I didnt understand this.......!!!

Also in crontab how to get data in log file, i mean this one

/a/b/file.ksh > fileLog.log

wen i am doin this, no data is comin in fileLog.log, i am givin full path for log file...!

"Tip about cron" was to write a very simple script to find out what the environment looks like in cron. It will tell you that is a skeleton environment which is nothing like the environment for an interactive user and may not even be using the same shell.

Try the simple "env" cron for practice. It will also show you that redirect to a log works. It of course only works if there is any output. Ideally in your Live script you will have already redirected any output to log files in which case there is nothing left to capture on the crontab line itself. I say ideally because all unredirected output turns up in mail for the user of the cron which is just about the least useful place!

Thanks Methyl....!!!

People like you is making my unix script learning very interesting and boosting my confidence that a novimce like me can also do it.....!!!!

Thanks a lot and will keep bugging you.... :stuck_out_tongue:

Moderators : Please close this thread, my issue is resolved. :slight_smile: