HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
cancel
Showing results for 
Search instead for 
Did you mean: 

Cron Job Issue

 
SOLVED
Go to solution
shameemsoft
Frequent Advisor

Cron Job Issue

Dear,

We have created one script to collect recent files(when this script executed, it will check less than one hour time stamp files) and zip that files and transfer to other server.

When i run the script manually, it is working properly.

I tried with cron job. But it is not taking any files & zip file is created with 0 bytes and transferred to other server.

I am confusing why it is not executing with correct output only in cron job.

Kindly clarify on this.

Thanks in Advance
Shameem
24 REPLIES
Johnson Punniyalingam
Honored Contributor
Solution

Re: Cron Job Issue

>>I am confusing why it is not executing with correct output only in cron job. <<

check on the "cron logs" to send some light on your problem

/var/adm/cron/log ? and also it could better if you can post "entry of your crontab" and location of the script which you are calling
Problems are common to all, but attitude makes the difference
Horia Chirculescu
Honored Contributor

Re: Cron Job Issue

Hello,

Try to set up in your srcipt the shell you are using and set the PATH variable (copy the value from profile)

Horia.
Best regards from Romania,
Horia.
shameemsoft
Frequent Advisor

Re: Cron Job Issue

Thanks a lot your quick response.

Find cron entry. i changed the time now for testing.

50 14 * * * /home/eppadm/scripts/epp-sync-j2ee-daily.sh

Log file information below.

> root 6826 c Tue Feb 23 14:50:00 WAT 2010
> CMD: /home/eppadm/scripts/epp-sync-j2ee-daily.sh
> root 6827 c Tue Feb 23 14:50:00 WAT 2010
< root 6825 c Tue Feb 23 14:50:00 WAT 2010
< root 6826 c Tue Feb 23 14:50:01 WAT 2010
< root 6827 c Tue Feb 23 14:51:18 WAT 2010

#!/bin/sh shell information updated in the script.

Which PATH variable need to set?

Kindly check and provide your feedback.

Thanks in Advance
Shameem
johnsonpk
Honored Contributor

Re: Cron Job Issue

Hi Shameem,

Looks like environment and PATH for the commands in your script is not defined.

Define it PATH variable in your script or replace each command with its absolute path.

Regards!
Johnson
Horia Chirculescu
Honored Contributor

Re: Cron Job Issue

Edit your script

/home/eppadm/scripts/epp-sync-j2ee-daily.sh

And define the PATH in there (get it from profile)

Horia.
Best regards from Romania,
Horia.
Sachin Kumbla
Frequent Advisor

Re: Cron Job Issue

As johnson said check the cronlogs whether is script is executing or not.

Also check for the absolute path of the script in your crontab.

Check for the permission of the script/file & the directory structure.should have execute permission for the script file for the owner of the sript/file.

Rgds.,
Sachin Kumbla.
johnsonpk
Honored Contributor

Re: Cron Job Issue

can you post the script /home/eppadm/scripts/epp-sync-j2ee-daily.sh
Horia Chirculescu
Honored Contributor

Re: Cron Job Issue

#!/bin/sh
#

PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:.....

Copy the value from your user's profile.

Horia
Best regards from Romania,
Horia.
shameemsoft
Frequent Advisor

Re: Cron Job Issue

Thanks for your response.

I updated PATH. i have taken path details from /etc/profile.

Still it is not working... Again i am telling this script is working properly when i execute manually :).

I have attached script in the attachment.


Horia Chirculescu
Honored Contributor

Re: Cron Job Issue

PATH=/usr/sbin:$PATH:/sbin:/home/root:/usr/local/bin:$JAVA_HOME


Not good enough...


As the user you are running "manually" the script and it is working, do

set

and copy PATH line


Then open your script and past the line there (delete this line)

I believe the only problem is with gzip but just to be sure, add the correct PATH variable as above.

Horia.
Best regards from Romania,
Horia.
Horia Chirculescu
Honored Contributor

Re: Cron Job Issue

"ipaddress "

I assume it is an IP address, not some variable?

Horia.
Best regards from Romania,
Horia.
Jupinder Bedi
Respected Contributor

Re: Cron Job Issue

you can set the path by using set command as follows


set pathname

and than try

Good luck
All things excellent are as difficult as they are rare
Johnson Punniyalingam
Honored Contributor

Re: Cron Job Issue

also it would be better if you can / direct the output for your script by crontab to "some logs" like >> /tmp/daily.log -> it can capture of the execution and we narrow down the problem

>>IP address<< as per IP attachment have exculded, becoz its confidential ..?
Problems are common to all, but attitude makes the difference
shameemsoft
Frequent Advisor

Re: Cron Job Issue

Thanks for your response.

I removed IP & server name from the script and uploaded to ITRC :)

If I set a path using set command, will it update the existing path configuration? It is production host. Thats why i would like to reconfirm with you guys.

Thanks in Advance
Shameem



Johnson Punniyalingam
Honored Contributor

Re: Cron Job Issue

if you run manually the script run as per your earlier post,

can we redirect to a log file to capture the output of your script while execution in crontab.
so that we will all know what causing the actual problem. Guess we are all shooting in the dark room.
Problems are common to all, but attitude makes the difference
shameemsoft
Frequent Advisor

Re: Cron Job Issue

Thanks Johnson.

I tried with that option...find the log output

#cat /tmp/log.out
Waiting until tar is complete ...
Tar completed successfully
Waiting until gzip is complete ...
Gzip completed successfully

tar & zip is completed with 0 bytes.. if i run manually at same time, some files exists in zip.

Kindly clarify on this

Thanks in Advance
Shameem
Yallappa
Occasional Advisor

Re: Cron Job Issue

Create to different script one for data collection and another for zip and transfer. And add two different entry in cron with sufficient time between them.
Horia Chirculescu
Honored Contributor

Re: Cron Job Issue

Have you set the PATH variable like this:

>As the user you are running "manually" the script and it is working, do

set

and copy PATH line into your SCRIPT.

Please re-attach the modified script here.

Horia
Best regards from Romania,
Horia.
Johnson Punniyalingam
Honored Contributor

Re: Cron Job Issue

>>>#cat /tmp/log.out
Waiting until tar is complete ...
Tar completed successfully
Waiting until gzip is complete ...
Gzip completed successfully<<<

as long as i see from above. time taken "tar" is too short. and between you can "use " sleep command optins

man sleep

"sleep - suspend execution for an interval"
Problems are common to all, but attitude makes the difference
Horia Chirculescu
Honored Contributor

Re: Cron Job Issue

>I tried with that option...find the log output

Would be better to implement logging like this:

(Put in front of this script your declarations)
------------------------------------
LOGF=/tmp/my_script.log

echo "\n\n\nStart Script at `date`" >> $LOGF

echo " Waiting until tar is complete ..."
touch readme $REPO/readme.txt

tar -cvf $REPO/$TAR $REPO/readme.txt >> $LOGF

find $J2EE -type f -mtime -1| xargs tar -rvf $REPO/$TAR >> $LOGF

echo " After first find/tar " >> $LOGF
ll $REPO/$TAR >> $LOGF

find $J2EE -type l -mtime -1| xargs tar -rvf $REPO/$TAR >> $LOGF

echo " Tar completed successfully " >> $LOGF
echo " After the second find/tar " >> $LOGF
ll $REPO/$TAR >> $LOGF

echo " Waiting until gzip is complete ..."
gzip -c -9 $REPO/$TAR > $REPO/$FILE
echo " Gzip completed successfully "
rm $REPO/$TAR

# Once done, SCP to the DR system
su - $USER -c "scp -i $KEY $REPO/$FILE $USER@$DEST:$REPO"
echo "File EPP-J2EE-FS.tar.gz transferred on `date`" >> $LOG

# Delete the created file; else next job will fail
rm -rf $REPO/$FILE

--------------------------------------------

Run the script through cron and paste here the content of the /tmp/my_script.log

Paste also the modified script (including the PATH and the rest of the declarations - remove any values you consider necessary to protect your privacy)


Horia.
Best regards from Romania,
Horia.
shameemsoft
Frequent Advisor

Re: Cron Job Issue

Hello Johnson,

Thanks for your response.

I found below information during script execution.

tar file creation take 8min & it is created successfully. gz file created with 0 bytes.

Then I put sleep 300 after below command

find $J2EE -type f -mtime -1| xargs tar -rvf $REPO/$TAR
find $J2EE -type l -mtime -1| xargs tar -rvf $REPO/$TAR

again gz file created with 0 bytes.

Again i put sleep after below command

gzip -c -9 $REPO/$TAR > $REPO/$FILE

Still gz file created with 0 bytes. Now problem with gz file only not with tar file.

Hello Horia,

Thanks for your response.

I found problem is in gz file. do you need to get the log information from each line from the script as per your previous update?

For PATH configuration, If I set a path using set command, will it update the existing path configuration? It is production host. Thats why i would like to reconfirm with you guys.

Shameem
Horia Chirculescu
Honored Contributor

Re: Cron Job Issue

>For PATH configuration, If I set a path using set command, will it update the existing path configuration? It is production host.

You should not use

set

command in your script file (at least not in this file!)

I just said that you should use the set command in order to find out the original environm. for the user that you claimed that the script worked as expected. (like this you would get the PATH value that you would copy into your script file, at the beginning)

Horia.
Best regards from Romania,
Horia.
Arturo Galbiati
Esteemed Contributor

Re: Cron Job Issue

hello,

put in your script:
#===========================================
# Load environment
#===========================================
. ~/.profile 1>/dev/null

this will assure you to have the same environment in crontab as you execute teh script manually.

HTH,
Art
shameemsoft
Frequent Advisor

Re: Cron Job Issue

Thanks a lot for your response.

Issue is resolved. Issue with PATH details.

Configured /usr/contrib/bin/gzip instead of gzip.

As per your opinion, If I configure PATH information in the script also resolve this issue.

Thanks
Shameem