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!

cron job not displaying output

Status
Not open for further replies.

SeSe

Programmer
Jun 8, 2001
32
GB
Hi,
I'm trying to run cron job that are running scripts that are launching commands like fping to check if some hosts are alive or queries against databases, etc...
The output of a fping command is appended to a file and the output is mailed to an address. If a run the script manually, it works fine. From cron, there is no output mailed whatsoever...
Any ideas why cron behaves in this way?
TIA.
SeSe


 
Hi,



Are you sure the cron job actually runs at all ? Or are you saying it creates the file but doesn't do the email part ?



Regards
 
Cron job runs Ok. Email works fine. Just the output of the fping command does not append correctly. I can provide you with the script if you'd willing to have a look at it...
 
Please post both the script and the cron entry so that we can see where the problem lies :)

Thanks ---
John Hoke<br>
 
When something runs at the command line but not in cron, it is always because cron's environment is not the same as what you have when logged in- PATH is different, other variables aren't set or are set differently, you aren't connected to a tty, etc.

See for more on that and simple ways to fix it.

Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
Hi all,
This is the script:

#!/bin/bash
rm -f *.htm? *.htm*.*
export TOP_DIR=/root/Scripts
touch tosend.html

# /usr/local/bin/wget -q -nd /usr/local/bin/wget -q -nd -P $TOP_DIR
# Write the Ip info from index.html
echo &quot;Ip Address&quot; >> $TOP_DIR/tosend.html
cat $TOP_DIR/index.html* | grep &quot;Your [iI]P&quot; >> $TOP_DIR/tosend.html

# Get the alive hosts using fping...
echo &quot;The following hosts are alive:&quot; >> $TOP_DIR/tosend.html

# Write the alive hosts in the tosend file....
/usr/local/sbin/fping -a -f iplist >> $TOP_DIR/tosend.html

# Get the info from the router...
/usr/local/bin/wget -q -nd -P $TOP_DIR 192.168.2.1/status.htm
# /usr/local/bin/wget -q -nd 192.168.2.1/status.htm

cat $TOP_DIR/status.htm >> $TOP_DIR/tosend.htm

cat $TOP_DIR/tosend.html | mail -s &quot;MSv Ip Info at `date`&quot; mymail@myisp.com
rm -f $TOP_DIR/*.htm* $TOP_DIR/*.htm*.*


This is the output (from the email) when this is run from the command line:

Ip Address
<h1>Your IP is 24.157.124.254<br></h1>
The following hosts are alive:
192.168.2.1
192.168.2.4
192.168.2.40
192.168.2.50


And this is the output when the script is run from cron:
Ip Address
<h1>Your IP is 24.157.124.254<br></h1>
The following hosts are alive:


As you see the output of fping does not come when cront is running the script.
Thanks for your help, much appreciate it...
SeSe
 
Sorry, the cron entry:
3 0,4,8,12,16,20 * * * /root/Scripts/ipinfo.sh 2>/dev/null
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top