LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-18-2003, 08:54 AM   #1
jjfate
LQ Newbie
 
Registered: Jun 2003
Posts: 18

Rep: Reputation: 0
ping problem


Hi all,

I am trying to get this to work in a script:

result= `ping -c 1 172.16.0.6 | grep -e 100\%`

this works fine with bash-2.05b-12mdk, but craps out with bash-2.05-16mdk. Is this a known issue? has anyone else encountered the same? Any thoughts or tips would be appreciated.

TIA

JJ
 
Old 09-18-2003, 10:48 AM   #2
jjfate
LQ Newbie
 
Registered: Jun 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Sorry, forgot to mention that the part it seems to have problems with is the -c 1. This is where I get the error when running from my script.
It works fine from the command line but not when called from the scipt.
 
Old 09-18-2003, 01:06 PM   #3
jjfate
LQ Newbie
 
Registered: Jun 2003
Posts: 18

Original Poster
Rep: Reputation: 0
a little more information:

The command runs from the command line in that shell, on that computer, but not from the script. both are using the same kernel (2.4.21), one is mandrake 9.1(it works on this one) the other is mandrake 8.2 (doesnt work on this one).

The error:

./set_time : 1: command not found

The script:

#ping to see if connection to server exists. Looks for 100% packet loss.
result= `ping -c 1 172.16.0.6 | grep -e 100\%`

#if result is blank ping was good (there is a connection to the server)
if [ test $result != '' ]
then
#syncs time with relication server in yellowknife and then syncs the system and hardware clocks
/usr/bin/rdate -s replication.arcticco-op.com
/sbin/clock -w
echo `date` time sync successful. >> set_time.log
else
#if there is no connection to the server, this appends a line to the log with time and date.
echo `date` time sync was unsuccessful, no connection to server >> set_time.log
exit;
fi
 
Old 09-18-2003, 05:38 PM   #4
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
Don't use a space between -c and 1, i.e:

result=`ping -c1 172.16.0.6 | grep -e 100\%`

hw
 
Old 09-18-2003, 08:24 PM   #5
footfrisbee
Member
 
Registered: Apr 2003
Distribution: Debian Sarge
Posts: 259

Rep: Reputation: 30
You might want to check out fping. It's easier to use in scripts than ping.
 
Old 09-19-2003, 11:03 AM   #6
jjfate
LQ Newbie
 
Registered: Jun 2003
Posts: 18

Original Poster
Rep: Reputation: 0
HW,

Perfect, that got me past the ping problem, but now I am getting an error with my test that says I have too many arguments.

Here is the error:

./set_time: [: too many arguments

I think it all looks okay. I cant seem to get this going.


JJ
 
Old 09-19-2003, 12:20 PM   #7
jjfate
LQ Newbie
 
Registered: Jun 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks for the help with this problem, I made a couple changes, and it now works just fine.

I changed the grep -e to grep -c and added double quotes to the test as follows

if ( test "result" != "1" )

this script is now working and I appreciate your time!


JJ
 
Old 09-19-2003, 05:25 PM   #8
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
Glad you got it working!

hw
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Ping Issue - Can't ping localhost but can ping others on LAN code_slinger Linux - Networking 15 03-30-2015 02:39 PM
FC4 won't ping 127.0.0.1 or the internet, but will ping local computers jalsk Linux - Networking 4 11-22-2005 05:59 PM
Any idea why this time I can not ping my LAN pc but can PING for ex. www.yahoo.com vakia Debian 5 09-28-2005 06:42 PM
PPP establish can ping the gateway router but unable to ping the host deepalalla Linux - Networking 0 11-18-2004 09:10 AM
windows 98 m/c ping to ip address of red hat server but fails to ping hostname ravilohot Linux - Networking 2 09-07-2004 04:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration