|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Bash Script Problem
I'm new to scripting, bashing or otherwise
But I'm usually a fast learner.I came across a script which I'm trying to modify for my own environment - the ping command gives a different output than the original script I discovered. Here's the script: ************************************* #!/bin/bash # Report on network ping responses to determine health of devices on network. # Ping Gateway ping=`ping -c3 XXX.XXX.XXX.X | tail -2` loss=`echo $ping |cut -d"," -f3 | cut -d"," -f1` delay=`echo $ping | cut -d"=" -f2 | cut -d"/" -f1` if [ "$loss" = "100% packet loss" ] ; then echo router - XXX.XXX.XXX.X is not responding at all elif [ "$loss" != "0% packet loss" ] ; then echo router - XXX.XXX.XXX.X is responding with packet loss else if [ "$delay" -lt 100 ]; then echo router - XXX.XXX.XXX.X is responding normally else echo router - XXX.XXX.XXX.X is responding slowly fi fi ************************************* Details: XXX.XXX.XXX.X is an IP address of my router. When I run this script, the output is: "echo router - XXX.XXX.XXX.X is responding with packet loss" But this should not be. The output in reality is 0% packet loss. And, during my experiments, I've even added an echo statement: echo $loss Which always come back as "0% packet loss" So, I'm a bit stumped at this behaviour. Pulling my hair out trying to figure what could be wrong. Other details: RH 9 Script created in Kate Bash version: 2.05b.0(1)-release (i386-redhat-linux-gnu) Thanks guys.. any help would be appreciated. Laura Last edited by WeeImp : November 1st, 2003 at 11:48 PM. |
|
#2
|
||||
|
||||
|
Are you running this as a cron job? I wrote a bash script a while back and had some odd behaviour as well. I later found out that environment variables were causing different output on the same command. When I ran the script via telnet it was fine. When it ran automatically, it was completely wrong. Look in that direction if that helps.
__________________
- Redtailed |
|
#3
|
|||
|
|||
|
Thanks for the reply, Redtailed, but no, I am not running this as a cronjob. I'm running it from the command line.
I still haven't figured it out ![]() Laura |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Bash Script Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|