LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-09-2006, 05:27 PM   #1
dehuszar
Member
 
Registered: Aug 2003
Posts: 41

Rep: Reputation: 15
problems using "ping" in a variable


I'm trying to write a script to DL AV updates, and I'm trying to ensure that the script can verify an internet connection before beginning (long story, but not relevant to this discussion).

I've gotten the script to otherwise do what I want, I just don't want it to bother to execute if it won't be able to DL stuff anyway.

When testing, the following lines of script:
Code:
interPing='ping www.google.com | grep time'
$interPing
I get the following error:
Code:
ping: unknown host |
I'm getting my syntax from the bash man pages and various tutorials online. I've also tried to use double quotes, leave the "| grep time" portion outside of the ''s. All with the same result.

I've also tried doing it this way:
Code:
interPing=$(ping www.google.com | grep time)
...but the cursor just hangs and I have to Ctrl-C the command.

I'm fairly competant in the Linux world, but don't do a whole lot of heavy scripting. If anyone can illuminate me, I'd greatly appreciate it.

Thanks in advance,
Samuel deHuszar Allen
 
Old 08-09-2006, 06:02 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Since I'm not sure what the end result of what you're doing is, I just tried to send the output of the command to the variable name:
Code:
$ interping=`ping -c 1 www.google.com | grep time`
$ echo $interping
1 packets transmitted, 0 received, 100% packet loss, time 0ms
It may have been the multi-line output or the wrong quotes (I have to go to a meeting and can't check) - but is that what you wanted it to do?
 
Old 08-09-2006, 08:03 PM   #3
tgo
Member
 
Registered: Dec 2004
Posts: 125

Rep: Reputation: 15
in c you could popen ping and fread the the input then sprintf %d and check the return value
 
Old 08-16-2006, 12:32 PM   #4
dehuszar
Member
 
Registered: Aug 2003
Posts: 41

Original Poster
Rep: Reputation: 15
Much thanks. Stupid '! I needed the ` single quote instead.

Sam
 
  


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
ping outputs TX to "loopback" instead of "eth1" Jojo1 Linux - Networking 0 04-12-2006 05:10 AM
Common problems explained: "kernel panic - not syncing", "unable to mount..." sundialsvcs Linux - Newbie 2 03-01-2006 12:17 PM
why iam getting problems like "...too many files opened" or "segmentation fault" naren_0101bits Linux - Newbie 2 07-19-2004 12:20 PM
My clients "can browse" outside but "can't ping" outside mrnoe Linux - Networking 1 09-05-2003 02:55 PM
"host" ok, but "ping" can't find ip address hardigunawan Linux - Networking 2 05-16-2002 05:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:38 PM.

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