LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

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: 40
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: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

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: 308

Rep: Reputation: 39
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: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:02 AM.

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
Open Source Consulting | Domain Registration