Unix Shell - Why won't this line hunt?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2006 > Why won't this line hunt?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Why won't this line hunt?
larryalk

2006-11-24, 1:22 pm

Why does the line below (sorry about the wrap) work at a shell prompt
but fail in a script and hangs the script?

echo -n `ping somewhere.dyndns.org |grep icmp |cut -d '(' -f 2 |cut
-d ')' -f 1` >/var/tmp/myip

Same thing with the line without the echo -n and the `script_line`

The normal result should be my IP address xx.xx.xx.xx
and the purpose of the double cut is to get rid of opening and closing
parenthesis surrounding the IP address from the ping command.

Larry
--
My real sig is much better.
Glenn Jackman

2006-11-24, 7:19 pm

At 2006-11-24 02:10PM, "larryalk" wrote:
> Why does the line below (sorry about the wrap) work at a shell prompt
> but fail in a script and hangs the script?


What are the differences in the environment between your shell and
wherever you're running your script? e.g. what's the PATH?

--
Glenn Jackman
Ulterior Designer
larryalk

2006-11-24, 7:19 pm

On 24 Nov 2006 19:46:52 GMT, Glenn Jackman <glennj@ncf.ca> wrote:

>At 2006-11-24 02:10PM, "larryalk" wrote:
>
>What are the differences in the environment between your shell and
>wherever you're running your script? e.g. what's the PATH?


Hello Glenn.

The paths are identical.
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11

Maybe something about too many redirections?

Larry

--
My real sig is much better.
larryalk

2006-11-24, 7:19 pm

On 24 Nov 2006 19:46:52 GMT, Glenn Jackman <glennj@ncf.ca> wrote:

>At 2006-11-24 02:10PM, "larryalk" wrote:
>
>What are the differences in the environment between your shell and
>wherever you're running your script? e.g. what's the PATH?


Problem solved Glenn.

I forgot my shell ping is an alias
alias ping='ping -c1'
which of course doesn't work the same in a script.

When I put the ping line in a script it outputted the way it should
and redirected the IP addr to a file.

Sorry to bother the list on something dumb like this.™

Larry

--
My real sig is much better.
Chris F.A. Johnson

2006-11-24, 7:19 pm

On 2006-11-24, larryalk wrote:
> On 24 Nov 2006 19:46:52 GMT, Glenn Jackman <glennj@ncf.ca> wrote:
>
>
> Problem solved Glenn.
>
> I forgot my shell ping is an alias
> alias ping='ping -c1'
> which of course doesn't work the same in a script.


That's a good demonstration of why creating aliases with the same
name as a standard command is not a good idea. For command-line
use, use something like 'ping1' as the alias.

> When I put the ping line in a script it outputted the way it should
> and redirected the IP addr to a file.



--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Bill Marcum

2006-11-25, 7:21 pm

On Fri, 24 Nov 2006 19:10:21 GMT, larryalk
<nobody@nowhere.com> wrote:
> Why does the line below (sorry about the wrap) work at a shell prompt
> but fail in a script and hangs the script?
>
> echo -n `ping somewhere.dyndns.org |grep icmp |cut -d '(' -f 2 |cut
> -d ')' -f 1` >/var/tmp/myip
>
> Same thing with the line without the echo -n and the `script_line`
>

ping never ends. Try ping -c 1.


--
Blessed are they that have nothing to say, and who cannot be persuaded
to say it.
-- James Russell Lowell
Chris Mattern

2006-12-05, 1:20 pm

In article <m9vk34-i5j.ln1@don.localnet>, Bill Marcum wrote:
>ping never ends. Try ping -c 1.
>

That depends on your system. In Solaris, ping by default pings once
and exits.

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com