Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems running script via cron

Status
Not open for further replies.

loqtis

Technical User
May 29, 2003
4
US
Im running a shell script from crontab on a solaris machine that runs a tar backup of certain files on the machine. the script runs great when ran manually ...but when ever i try to run it from cron it creates a emtpy tar file and or doesnt run at all ...anyone have any thougths ???

thank you
Bmyster
 
1. check whether you're explicitly specifying a script interpreter to run the script through [#!/bin/whateverShell]

2. make sure your PATH is setup correctly for ALL the tools/utilities used by the script

3. remember: the environment in which every cron is ran is NOT the same as the interactive shell's environment.

4. man cron

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
this is the script im running a very simple script as you can see.


#!/bin/sh
# Tar backups written by Brent
#

cd /
echo &quot;Tarring up usr/local/apache&quot;
/usr/sbin/tar -zpcvf /var/coreosbkup/apache.`date +%Y.%m.%d.at.%H.%M.%S`.tgz /usr/local/apache

echo &quot;Tarring up usr/local/mysql&quot;
/usr/sbin/tar -zpcvf /var/coreosbkup/mysql.`date +%Y.%m.%d.at.%H.%M.%S`.tgz /usr/local/mysql

echo &quot;Tarring up var/log&quot;
/usr/sbin/tar -zpcvf /var/coreosbkup/varlog.`date +%Y.%m.%d.at.%H.%M.%S`.tgz /var/log

echo &quot;Tarring up db/coreos&quot;
/usr/sbin/tar -zpcvf /var/coreosbkup/db.`date +%Y.%m.%d.at.%H.%M.%S`.tgz /db/coreos

echo &quot;Tarring up etc/init.d&quot;
/usr/sbin/tar -zpcvf /var/coreosbkup/etc-initd.`date +%Y.%m.%d.at.%H.%M.%S`.tgz /etc/init.d

cd /var/coreosbkup
echo &quot;Erasing the tape&quot;
/usr/bin/mt -f /dev/rmt/0 erase
echo &quot;Rewinding the tape&quot;
/usr/bin/mt -f /dev/rmt/0 rewind
echo &quot;Moving the tar files to tape&quot;
/usr/sbin/tar cvf /dev/rmt/0n /var/coreosbkup/*.tgz
mt -f /dev/rmt/0 offline
echo &quot;Removing tar files from system&quot;

rm *.tgz

echo &quot;Backup of /usr/local/apache - /usr/local/mysql - /var/log - /etc/init.d done&quot;

Now ive tried explicit paths as you ..and i get the same result ..either it doesnt even work ...or it creates a emtpy tar file.
Now someone else had recommended that i add the following to my script..for troublshooting:

set -x

exec 1> mylog 2>&1

i did ..hopeing it would give me a clue in the &quot;mylog&quot; file ...the only thing that is in the &quot;mylog&quot; file after the sript runs in cron is
+exec <-- whats that mean ???


thanx for all and any help :)

Brent
 
Brent,
if you let cron do your job you'll always get a mail if your script has produced output. Because of the &quot;echo&quot;-statements it will at least echo something provided your crontab entry doesn't end with a &quot;>/dev/null 2>&1&quot;
If you don't get a mail, maybe your mail service isn't up. For further investigations try &quot;at&quot;. It works similar to &quot;cron&quot; but is not driven through a schedule (i.e. crontab).

Michael.
 
I think vgersh99 hit the nail on the head with his comment about the $PATH variable. You need to explicitly define this within your script so that cron knows what variables etc are to be used. If you need help with this, post back. Regards.
 
no problem.

In the scope of things - it ain't so bad! ;)

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top