Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 1st, 2003, 11:30 PM
WeeImp WeeImp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 WeeImp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old November 20th, 2003, 06:45 PM
Redtailed's Avatar
Redtailed Redtailed is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Utah, USA
Posts: 83 Redtailed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 31 sec
Reputation Power: 6
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

Reply With Quote
  #3  
Old November 20th, 2003, 07:03 PM
WeeImp WeeImp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 WeeImp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Bash Script Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT