1833875 Members
1877 Online
110063 Solutions
New Discussion

More script help please

 
SOLVED
Go to solution
Nick D'Angelo
Super Advisor

More script help please

I have a ping /usr/bin/ksh script that doesn't exit for some reason.

Any ideas? Do I need the done on the end?

here it is:
#!/usr/bin/ksh
received'
ping istatprd -n 5 >> /home1/nickd/pingresult.txt
ping gbclinux -n 5 >> /home1/nickd/pingresult.txt
ping usaiss -n 5 >> /home1/nickd/pingresult.txt
#done
Always learning
15 REPLIES 15
Nick D'Angelo
Super Advisor

Re: More script help please

Sorry, the received line should not be in there.
Always learning
Mel Burslan
Honored Contributor

Re: More script help please

is one of the ping's hung and it is not exiting or it is finishing but not exiting. If the situation is latter, try appending an

exit

command after the ping statements.
________________________________
UNIX because I majored in cryptology...
Sridhar Bhaskarla
Honored Contributor

Re: More script help please

Hi,

If one of the systems is down, then it can take quite long to come out of ping. Be patient and it will eventually come out.

I use -n 2 to only wait for 2 packets.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Nick D'Angelo
Super Advisor

Re: More script help please

it is finishing,and all ip/hosts are being found, but it is still not exiting after I included an exit command on the end of the script.
Always learning
Jeroen Peereboom
Honored Contributor

Re: More script help please

Nick,

no 'done' is needed.
'exit' also is not needed, but it may be nice to end the script with an 'exit 0' such that the script always returns 'OK' as result.

I too believe you just have to wait for the pings to finish.

JP.
Mel Burslan
Honored Contributor

Re: More script help please

are you by any chance running this script remotely via remsh/rexec/ssh ? Or this is happening when you run it locally ?
________________________________
UNIX because I majored in cryptology...
Sridhar Bhaskarla
Honored Contributor

Re: More script help please

If this script simply has these three lines, then I don't see any reason why it wouldn't exit.

Put 'set -x' at the start of the script. It will print the debug information that may help you find the issue.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Nick D'Angelo
Super Advisor

Re: More script help please

I am running it localling by running ./ping.sh

I also tried to put in cron to see if it behaves any differently and NO - it is the same.

I tried to put the exit 0 on the end and still the same. here is my updated script:

#!/usr/bin/sh
ping istatprd -n 5 >> /home1/nickd/pingresult.txt
ping gbclinux -n 5 >> /home1/nickd/pingresult.txt
ping usaiss -n 5 >> /home1/nickd/pingresult.txt
exit 0

Always learning
Nick D'Angelo
Super Advisor

Re: More script help please

Sridhar,

I put a set -x in the script and it looks all good - this is the output.

+ ping istatprd -n 5
+ 1>> /home1/nickd/pingresult.txt
+ ping gbclinux -n 5
+ 1>> /home1/nickd/pingresult.txt
+ ping usaiss -n 5
+ 1>> /home1/nickd/pingresult.txt
Always learning
Mel Burslan
Honored Contributor
Solution

Re: More script help please

while doing this, are you watching the pingresults.txt file on a different terminal session using tail -f command ? If so, do you see usaiss pinging 5 times successfully ? It seems like your script is not returning from the last ping command to usaiss
________________________________
UNIX because I majored in cryptology...
RAC_1
Honored Contributor

Re: More script help please

Aprt from putting sh -vx to check it, I would also use -m option of ping command. The -m option is for timeout period in seconds.

Check man page.

ping host -n 5 -m 10

Anil
There is no substitute to HARDWORK
Nick D'Angelo
Super Advisor

Re: More script help please

I am such a dolt sometimes. The IP address for the last machine was wrong. (there were more in my script but I didn't want to bore you with the list)

Thanks to all.

If you want more points, please reply with a thank you and I will assign 10 each for being such a dolt.
Always learning
Sridhar Bhaskarla
Honored Contributor

Re: More script help please

OK. Some more debugging and it is frustating me. All it has is three lines and it won't exit.

Put some lines before and after each pings.

echo "ping start on istatprd"
ping istatprd -n 5 >> /home1/nickd/pingresult.txt
echo "istatprd completed"

Repeat the above all the servers and see what you get.

YOu should get "usaiss completed" at the end.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Michael Schulte zur Sur
Honored Contributor

Re: More script help please

Hi,

doesn't that point to some dns resolution problem? Is the ping also stuck, when you use it manually with a wrong hostname?

greetings,

Michael
Nick D'Angelo
Super Advisor

Re: More script help please

It is using local /etc/hosts for name reslution and I had a bad ip address.

Always learning