Visit Our UNIX and Linux User Community


ping from cron


 
Thread Tools Search this Thread
Top Forums Programming ping from cron
# 1  
Old 02-28-2002
ping from cron

Hello

I wrote a shell script to poll network. It works fine from command line, but doesn't want to work from cron.
To clarify the problem, I wrote simple test file (test.ksh):
ping -c1 -q 172.27.38.2 > /path/res.log

when I do:
>ksh test.ksh

it works fine, and res.log populated with ping info.
but when I'm calling it from cron:
29 15 * * * ksh /path/test.ksh

it creates res.log with 0 size and that's it.
Why doesn't it work from cron?

Thanks,
Vlad
# 2  
Old 02-28-2002
You may want to add...

>/tmp/test.ksh.err 2>&1

...to the end of your cron job line.
This may give you some hint as to why
the shell script is not working.

Sometimes, you need to specify the full path
name to commands when running under cron as
they may not get a full environment set when
the execute.

In your shell try...

!#/bin/ksh
/bin/ping -c1 -q 172.27.38.2 > /path/res.log
# assuming ping is in /bin

Your cron like...
29 15 * * * ksh /path/test.ksh >/tmp/test.ksh.err 2>&1
# 3  
Old 03-01-2002
This is how we ping other boxes to ensure their up and running.
Nb: This is run on a SCO Unix box.

Script:
Code:
# more /usr/users/operator/check_rcmd
if [ `rcmd $1 hostname | grep someweb.com` ]
then
  echo OK
else
  mailx -s "Unable to access SomeWeb server $1" ops@somedomain.com <<END
`hostname` cannot perform remote commands on $1
This may effect the ability to do bookings on $1
Follow TVL escalation procedure to resolve
END
fi
#

From Cron:
Code:
# Check rcmd is availble.  Test for situation where corruption of the
# authorisation database was preventing remote access 
10,40 * * * * /usr/users/operator/check_rcmd 168.153.251.80 > /dev/null 2>&1

Hope that helps some. Smilie
# 4  
Old 03-01-2002
Thanks

You were right! it was path to ping should be /sbin/ping instead of just ping! how stupid of me!

Thanks guys

Previous Thread | Next Thread
Test Your Knowledge in Computers #145
Difficulty: Easy
Unix popularized the hierarchical file system with arbitrarily nested subdirectories, originally introduced by Multics.
True or False?

10 More Discussions You Might Find Interesting

1. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

2. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

3. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

4. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

5. Shell Programming and Scripting

How to get reason for ping failure using perls Net::Ping->new("icmp");?

Hi I am using perl to ping a list of nodes - with script below : $p = Net::Ping->new("icmp"); if ($p->ping($host,1)){ print "$host is alive.\n"; } else { print "$host is unreacheable.\n"; } $p->close();... (4 Replies)
Discussion started by: tavanagh
4 Replies

6. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

7. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

8. Solaris

User entry in both cron.allow and cron.deny

Hello All, Anybody please help me to know ,what happens when a user having entry in both cron.allow and cron.deny files.Wheather the user will be able to access the crontab??? Thanks in advance Vaisakh (5 Replies)
Discussion started by: ksvaisakh
5 Replies

9. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

10. AIX

AIX and cron logs filtering ?: /etc/cronlog.conf, /var/adm/cron/log

Hi, I can use 'crontabs –e' and do all the scheduling I like. However I would like to auto send myself just the cronjobs logs that fail. That is to say the PIDs that fail and the related lines with those PID’s only. (Not the full set of logs) Has anyone done this work? Or does an AIX 5.3 tool... (0 Replies)
Discussion started by: Keith Johnson
0 Replies

Featured Tech Videos