BSD Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsBSD Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 29th, 2006, 12:44 PM
namotco namotco is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Madison
Posts: 419 namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 1 h 43 m 23 sec
Reputation Power: 35
Send a message via AIM to namotco
Shell script doesn't work as cron job

This code works correctly when executed from the command line, but when I have this entry in my crontab file the output is an empty bz2 file.

cron tab:
Code:
@daily /usr/home/wha/scripts/rperry_wha_bkup.sh



shell script:
Code:
#!/bin/sh
# Script name : auto_mysql_dump.sh
# Backup the dbname database
dir=`date +%Y-%m-%d`
dbname='rperry_wha'
if [ -d /home/wha/backup ]; then
mkdir /home/wha/backup/$dir
mysqldump -B --user=rperryFile --password=somepassword --host=127.0.0.1 $dbname | bzip2 -c > /home/wha/backup/$dir/$dbname.sql.bz2
fi
# End of script auto_mysql_dump.sh
__________________
MadisonIP

Reply With Quote
  #2  
Old June 29th, 2006, 03:18 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 189
Use absolute path names.

Cron has got a different environment setup than your shell. The problem is most likely the PATH variable.

M.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old June 29th, 2006, 03:29 PM
tj_nt tj_nt is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2004
Posts: 2,102 tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level)tj_nt User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 12 h 25 m 58 sec
Reputation Power: 1766
this may not apply...so FWIW...

If you used a 'Windows' (or other non-nix) system to compose the shell script and then uploaded it to the server there is a possibility that there are hidden characters that get ignored when the script is run from bash but cron see it as a corrupted file...

Reply With Quote
  #4  
Old June 29th, 2006, 03:36 PM
namotco namotco is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Madison
Posts: 419 namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 1 h 43 m 23 sec
Reputation Power: 35
Send a message via AIM to namotco
Hmm, I tried to be careful with the path names, but maybe mysqldump is the issue. I'll use a full path on it and see what happens.

Thanks.

Reply With Quote
  #5  
Old June 29th, 2006, 04:13 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 189
Yes, that's what I meant.
The "PATH" variable is the search path for binaries.
It does not include /usr/local/bin by default. You can change this, but I prefer to use absolute paths still.

M.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsBSD Help > Shell script doesn't work as cron job

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap