Networking Forums

Networking Forums > Computer Networking > Linux Networking > tcpdump + IFS = no sense?

Reply
Thread Tools Display Modes

tcpdump + IFS = no sense?

 
 
tony.andreoli@gmail.com
Guest
Posts: n/a

 
      08-29-2006, 03:49 PM
Ok, perhaps one of the experts here can help. I'm just trying to write
a small script that will start a tcpdump. The dump will be started
with a variable for tcpdump's parameters. This works fine:

cmd="-i eth0"
tcpdump $cmd

BUT, if I then add an IFS command before it (to eventually allow me to
read the parameters from a config file) it doesn't work. This fails:

IFS="
"
cmd="-i eth0"
tcpdump $cmd

with a "tcpdump: ioctl: No such device"

I've tried it with Redhat EL3 and FC5 with the same results. Can
someone explain what the heck's going on?

Thanks!
Tony

 
Reply With Quote
 
 
 
 
Dale Dellutri
Guest
Posts: n/a

 
      08-29-2006, 04:00 PM
On 29 Aug 2006 08:49:46 -0700, (E-Mail Removed) wrote:
> Ok, perhaps one of the experts here can help. I'm just trying to write
> a small script that will start a tcpdump. The dump will be started
> with a variable for tcpdump's parameters. This works fine:


> cmd="-i eth0"
> tcpdump $cmd


> BUT, if I then add an IFS command before it (to eventually allow me to
> read the parameters from a config file) it doesn't work. This fails:


> IFS="
> "
> cmd="-i eth0"
> tcpdump $cmd


> with a "tcpdump: ioctl: No such device"
> I've tried it with Redhat EL3 and FC5 with the same results. Can
> someone explain what the heck's going on?


bash can't parse the command string properly because you changed the
field separator. What are you setting IFS to?

$IFS
internal field separator
This variable determines how Bash recognizes fields, or word
boundaries when it interprets character strings.
$IFS defaults to whitespace (space, tab, and newline), but may be
changed, for example, to parse a comma-separated data file. Note that
$* uses the first character held in $IFS. See Example 5-1.

--
Dale Dellutri <(E-Mail Removed)> (lose the Q's)
 
Reply With Quote
 
tony.andreoli@gmail.com
Guest
Posts: n/a

 
      08-29-2006, 05:09 PM
I'm setting it to a carriage return:

IFS="
"

As I've done a million times before. The result is the ability to read
a text file one line at a time rather than one word at a time. That
functionality still works fine, it's just that tcpdump is choking.

Dale Dellutri wrote:
> On 29 Aug 2006 08:49:46 -0700, (E-Mail Removed) wrote:
> > Ok, perhaps one of the experts here can help. I'm just trying to write
> > a small script that will start a tcpdump. The dump will be started
> > with a variable for tcpdump's parameters. This works fine:

>
> > cmd="-i eth0"
> > tcpdump $cmd

>
> > BUT, if I then add an IFS command before it (to eventually allow me to
> > read the parameters from a config file) it doesn't work. This fails:

>
> > IFS="
> > "
> > cmd="-i eth0"
> > tcpdump $cmd

>
> > with a "tcpdump: ioctl: No such device"
> > I've tried it with Redhat EL3 and FC5 with the same results. Can
> > someone explain what the heck's going on?

>
> bash can't parse the command string properly because you changed the
> field separator. What are you setting IFS to?
>
> $IFS
> internal field separator
> This variable determines how Bash recognizes fields, or word
> boundaries when it interprets character strings.
> $IFS defaults to whitespace (space, tab, and newline), but may be
> changed, for example, to parse a comma-separated data file. Note that
> $* uses the first character held in $IFS. See Example 5-1.
>
> --
> Dale Dellutri <(E-Mail Removed)> (lose the Q's)


 
Reply With Quote
 
David Schwartz
Guest
Posts: n/a

 
      08-30-2006, 03:55 AM

(E-Mail Removed) wrote:

> I'm setting it to a carriage return:
>
> IFS="
> "
>
> As I've done a million times before. The result is the ability to read
> a text file one line at a time rather than one word at a time. That
> functionality still works fine, it's just that tcpdump is choking.


With IFS set to just a newline, bash interprets "tcpdump -i eth0" as
"tcpdump" "-i eth0" instead of "tcpdump" "-i" "eth0", which is what it
expects and requires.

DS

 
Reply With Quote
 
tony.andreoli@gmail.com
Guest
Posts: n/a

 
      08-30-2006, 02:27 PM
Wierd, I've never experienced this, but putting "eval" in front solved
it.

Thanks!
David Schwartz wrote:
> (E-Mail Removed) wrote:
>
> > I'm setting it to a carriage return:
> >
> > IFS="
> > "
> >
> > As I've done a million times before. The result is the ability to read
> > a text file one line at a time rather than one word at a time. That
> > functionality still works fine, it's just that tcpdump is choking.

>
> With IFS set to just a newline, bash interprets "tcpdump -i eth0" as
> "tcpdump" "-i eth0" instead of "tcpdump" "-i" "eth0", which is what it
> expects and requires.
>
> DS


 
Reply With Quote
 
tony.andreoli@gmail.com
Guest
Posts: n/a

 
      08-30-2006, 02:28 PM
Wierd, I've never experienced this, but putting "eval" in front solved
it.

Thanks.

David Schwartz wrote:
> (E-Mail Removed) wrote:
>
> > I'm setting it to a carriage return:
> >
> > IFS="
> > "
> >
> > As I've done a million times before. The result is the ability to read
> > a text file one line at a time rather than one word at a time. That
> > functionality still works fine, it's just that tcpdump is choking.

>
> With IFS set to just a newline, bash interprets "tcpdump -i eth0" as
> "tcpdump" "-i eth0" instead of "tcpdump" "-i" "eth0", which is what it
> expects and requires.
>
> DS


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Sense Moretti Windows Networking 0 04-12-2007 12:40 AM
Does this make sense? Frank Parmelee Broadband Hardware 3 01-08-2007 01:16 AM
Please help! Can anyone make any sense of this? Lee Broadband 4 02-12-2005 08:23 PM
Making sense of DNS and Dynamic DNS? Tony Home Networking 4 02-05-2005 10:34 PM
Crazy business sense. Steven Campbell Broadband 4 02-23-2004 12:32 PM



1 2 3 4 5 6 7 8 9 10 11