LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-26-2009, 03:53 AM   #1
junust
Member
 
Registered: Jul 2008
Location: Israel Ramat Gan
Distribution: CentOs 5.3, SuSe 11.1, Solaris 9, Slackware 13
Posts: 78

Rep: Reputation: 15
cron job did not redirect output from bash script


Hello,
I got simple bash script which is running through crontab as user 'root'
#!/bin/bash
#echo $CacheIP
CurreIP=$(wget http://freedns.afraid.org/xxxxxx-something to catche my current ip adderess
if [ "$CurreIP" = "$CacheIP" ]
then
echo Both IP are equal
echo "Update not required..."
else
wget http://freedns.afraid.org/dynamic/update.php something to update my current ip adderess

#Here is the problem
echo "$(date) Updating log with IP $CurreIP " >> dnsactual.log

fi
rm -f /etc/freedns/dnsactual.conf
echo $CurreIP > /etc/freedns/dnsactual.conf


when I am running this script manually it is work perfect(meening I got dnsactual.log start filling), but doing it through crontab it is do the job concerning update my ip address like it is suppouse to do, but I do not have dnsactual.log file updated

Last edited by junust; 07-26-2009 at 04:48 AM.
 
Old 07-26-2009, 03:56 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
Well, maybe you don't have it in the place you expect it to be. A cron job run from the user home directory by default, so that every relative path inside the script is relative to $HOME. Check if $HOME/dnsactual.log has been created. As a general rule, it's safer to use absolute paths for both the commands and the files inside the cron job.
 
Old 07-26-2009, 04:30 AM   #3
junust
Member
 
Registered: Jul 2008
Location: Israel Ramat Gan
Distribution: CentOs 5.3, SuSe 11.1, Solaris 9, Slackware 13
Posts: 78

Original Poster
Rep: Reputation: 15
colucix
Excellent, working like a charm, I did not know about ($HOME by crontab)
Actually all my logs after running this script by cron, were in my /root/dnsactual.log directory
Thank a lot for the hint
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH script for a MySQL cron job - Need help Carlo1973 Linux - Newbie 1 05-20-2009 01:56 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
HELP - bash script - cron job - not out putting in 132 boyd98 Programming 12 05-01-2007 06:14 PM
How to set up cron job to execute bash script lgmqy2000 Linux - General 4 11-22-2006 04:29 AM
Bash script and cron job rust8y Linux - General 2 07-08-2006 07:45 AM


All times are GMT -5. The time now is 02:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration