LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-15-2009, 01:17 AM   #1
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,627

Rep: Reputation: Disabled
Script not running properly in cron though runs well if run manually.


Hello,

I have got a script that I run to download a small file and check the internet speed while download is going on. The internet statistics are written to a log file. The script is called as test_script.
I want to run it through cron but have got some problems while it runs through cron.
Here is the script.

Code:
#!/bin/bash

####Set todays date####
set `date +%F%H%M`

####Create a file for todays date and time###
touch /ifstat/log.$1

####Write todays date in the file####
date +%F >> /ifstat/log.$1
date +%T >> /ifstat/log.$1
echo "==============================================================" >> /ifstat/log.$1

####Change the directory where the downloaded file is to be saved###
cd /downloads

####Remove all the files if there are any####
rm -rf *.*

####Start the download####
####Set the wget and ifstat processes####
set `ifstat -T >> /ifstat/log.$1 &`
set `wget http://xxxxxxxx.com/xx.exe`

####Keep loopig to find out if the download is complete and keep ifstat running ####till download is complete
while [ $3 ]

do $2
done
##echo "Download complete"

####Kill all the running ifstat processes####
pidof ifstat | xargs kill

####Write the end time of download to the file####

echo "==============================================================" >> /ifstat/log.$1
date +%F >> /ifstat/log.$1
date +%T >> /ifstat/log.$1

####Delete log files older than 7 days####
find /ifstat -mtime +7 -exec rm -rf {} \;

####Exit the script####
exit 0
This if run manually runs fine and gives proper output and kills the ifstat process. But if run in cron it fails to kill ifstat. Also ifstat keeps writing into file even after download is complete.
Any suggestions why this happens?

Edit:
Forgot to tell that I run it on RHEL4.

Last edited by linuxlover.chaitanya; 01-15-2009 at 01:20 AM.
 
Old 01-15-2009, 01:29 AM   #2
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 38
On my machine, pidof is /sbin. Can you try giving the full path in your script? Or you could add /sbin to $PATH in the beginning of your script, whatever.
 
Old 01-15-2009, 02:47 AM   #3
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,627

Original Poster
Rep: Reputation: Disabled
I am running the cron job as root user. Still do I need to edit pidof to /sbin/pidof?
 
Old 01-15-2009, 02:52 AM   #4
arckane
Member
 
Registered: Sep 2005
Location: UK
Distribution: Gentoo/Debian/Ubuntu
Posts: 306

Rep: Reputation: 38
If scripting, always use full paths or make sure that the search paths are set correctly.

Also, you could use just outright use kill rather than pidof.
 
Old 01-15-2009, 03:31 AM   #5
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,627

Original Poster
Rep: Reputation: Disabled
Thanks both of you. It worked.
 
  


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
Script runs fine from command line, but not when attempted from Cron hwest Linux - Newbie 8 12-11-2008 06:48 PM
Cron Job only runs when it is manually started sinister1 Linux - General 4 02-25-2008 08:35 AM
Script works when run manually but not in cron job Harlin Linux - Software 7 10-16-2007 06:36 PM
script doesn't run in cron (runs from shell just fine) Timur Sakayev Linux - Software 6 02-26-2007 12:56 PM
script runs fine from a command line, but doesn't work from cron? kleptophobiac Linux - Software 5 05-03-2004 04:14 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration