Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

/proc/kallsyms format, sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas

Links

XODOX
Impressum

#1: Reading from a file

Posted on 2008-04-22 15:09:26 by invincible

I am trying to read from a file for the list of servers and then
instruct the script to login on these servers and run a command to
check one text file.

So far its done the below way...

cat server-list | \
while read line
do
echo "------------------------------------------------" >>test.out
echo " HOST : $line" >>test.out
echo "________________________________________________" >>test.out
rsh $line cat /home/basks.tbl|awk '{ print $1 }' >>test.out
done

The problem seems to be that script does not work !!! :-)

Any ideas around using cat wiht the while loop in a better way ?

Report this message

#2: Re: Reading from a file

Posted on 2008-04-22 15:33:51 by Florian Kaufmann

> rsh $line cat /home/basks.tbl|awk '{ print $1 }' >>test.out

Maybee you have to write

rsh "$line" cat ...

because $line might contain blanks.

Report this message

#3: Re: Reading from a file

Posted on 2008-04-22 15:49:06 by Ed Morton

On 4/22/2008 8:09 AM, invincible wrote:
> I am trying to read from a file for the list of servers and then
> instruct the script to login on these servers and run a command to
> check one text file.
>
> So far its done the below way...
>
> cat server-list | \
> while read line
> do
> echo "------------------------------------------------" >>test.out
> echo " HOST : $line" >>test.out
> echo "________________________________________________" >>test.out
> rsh $line cat /home/basks.tbl|awk '{ print $1 }' >>test.out
> done
>
> The problem seems to be that script does not work !!! :-)
>
> Any ideas around using cat wiht the while loop in a better way ?

Yes, don't use it. Instead of this:

cat file |
while read line
do
whatever
done

do this:

while IFS= read -r line
do
whatever
done < file

and instead of this:

cat file | awk '...'

do this:

awk '...' file

So, do that and then post a followup if your script still doesn't work.

Ed.

Report this message

#4: Re: Reading from a file

Posted on 2008-04-22 15:50:53 by Bill Marcum

On 2008-04-22, invincible <imanuk2007@googlemail.com> wrote:
>
>
> I am trying to read from a file for the list of servers and then
> instruct the script to login on these servers and run a command to
> check one text file.
>
> So far its done the below way...
>
> cat server-list | \
> while read line
> do
> echo "------------------------------------------------" >>test.out
> echo " HOST : $line" >>test.out
> echo "________________________________________________" >>test.out
> rsh $line cat /home/basks.tbl|awk '{ print $1 }' >>test.out
> done
>
> The problem seems to be that script does not work !!! :-)

How does it not work? What errors do you get? Are you sure rsh on your
system is "remote shell" and not "restricted shell"?
Another possible problem is that rsh is in a loop with a pipe as
standard input. You might need to redirect the rsh command's input to
/dev/null.

>
> Any ideas around using cat wiht the while loop in a better way ?

Report this message

#5: Re: Reading from a file

Posted on 2008-04-22 16:54:13 by invincible

On Apr 22, 2:49 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 4/22/2008 8:09 AM, invincible wrote:
>
>
>
> > I am trying to read from a file for the list of servers and then
> > instruct the script to login on these servers and run a command to
> > check one text file.
>
> > So far its done the below way...
>
> > cat server-list | \
> > while read line
> > do
> > echo "------------------------------------------------" >>test.out
> > echo " HOST : $line" >>test.out
> > echo "________________________________________________" >>test.out
> > rsh $line cat /home/basks.tbl|awk '{ print $1 }' >>test.out
> > done
>
> > The problem seems to be that script does not work !!! :-)
>
> > Any ideas around using cat wiht the while loop in a better way ?
>
> Yes, don't use it. Instead of this:
>
> cat file |
> while read line
> do
> whatever
> done
>
> do this:
>
> while IFS= read -r line
> do
> whatever
> done < file
>
> and instead of this:
>
> cat file | awk '...'
>
> do this:
>
> awk '...' file
>
> So, do that and then post a followup if your script still doesn't work.
>
> Ed.

Ed,

It seems Im now stuck on below error

rsh dubba awk '{ print $1 }' /home/basks.tbl
syntax error The source line is 1.
The error context is
>>> { <<<
awk: The statement cannot be correctly parsed.
The source line is 1.

Thankyou

Report this message

#6: Re: Reading from a file

Posted on 2008-04-22 17:21:21 by wayne

invincible wrote:
> On Apr 22, 2:49 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>> On 4/22/2008 8:09 AM, invincible wrote:
>>
>>
>>
>>> I am trying to read from a file for the list of servers and then
>>> instruct the script to login on these servers and run a command to
>>> check one text file.
>>> So far its done the below way...
>>> cat server-list | \
>>> while read line
>>> do
>>> echo "------------------------------------------------" >>test.out
>>> echo " HOST : $line" >>test.out
>>> echo "________________________________________________" >>test.out
>>> rsh $line cat /home/basks.tbl|awk '{ print $1 }' >>test.out
>>> done
>>> The problem seems to be that script does not work !!! :-)
>>> Any ideas around using cat wiht the while loop in a better way ?
>> Yes, don't use it. Instead of this:
>>
>> cat file |
>> while read line
>> do
>> whatever
>> done
>>
>> do this:
>>
>> while IFS= read -r line
>> do
>> whatever
>> done < file
>>
>> and instead of this:
>>
>> cat file | awk '...'
>>
>> do this:
>>
>> awk '...' file
>>
>> So, do that and then post a followup if your script still doesn't work.
>>
>> Ed.
>
> Ed,
>
> It seems Im now stuck on below error
>
> rsh dubba awk '{ print $1 }' /home/basks.tbl
> syntax error The source line is 1.
> The error context is
> >>> { <<<
> awk: The statement cannot be correctly parsed.
> The source line is 1.
>
> Thankyou

Seems like the quote marks are removed too soon, by rsh. Maybe:

rsh $line cat /home/basks.tbl|awk \'{ print $1 }\' >>test.out

-Wayne

Report this message

#7: Re: Reading from a file

Posted on 2008-04-22 17:27:26 by Ed Morton

On 4/22/2008 10:21 AM, Wayne wrote:
> invincible wrote:
>
>>On Apr 22, 2:49 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>>
>>>On 4/22/2008 8:09 AM, invincible wrote:
>>>
>>>
>>>
>>>
>>>>I am trying to read from a file for the list of servers and then
>>>>instruct the script to login on these servers and run a command to
>>>>check one text file.
>>>>So far its done the below way...
>>>>cat server-list | \
>>>>while read line
>>>>do
>>>>echo "------------------------------------------------" >>test.out
>>>>echo " HOST : $line" >>test.out
>>>>echo "________________________________________________" >>test.out
>>>>rsh $line cat /home/basks.tbl|awk '{ print $1 }' >>test.out
>>>>done
>>>>The problem seems to be that script does not work !!! :-)
>>>>Any ideas around using cat wiht the while loop in a better way ?
>>>
>>>Yes, don't use it. Instead of this:
>>>
>>> cat file |
>>> while read line
>>> do
>>> whatever
>>> done
>>>
>>>do this:
>>>
>>> while IFS= read -r line
>>> do
>>> whatever
>>> done < file
>>>
>>>and instead of this:
>>>
>>> cat file | awk '...'
>>>
>>>do this:
>>>
>>> awk '...' file
>>>
>>>So, do that and then post a followup if your script still doesn't work.
>>>
>>> Ed.
>>
>>Ed,
>>
>>It seems Im now stuck on below error
>>
>>rsh dubba awk '{ print $1 }' /home/basks.tbl
>> syntax error The source line is 1.
>> The error context is
>> >>> { <<<
>> awk: The statement cannot be correctly parsed.
>> The source line is 1.
>>
>>Thankyou
>
>
> Seems like the quote marks are removed too soon, by rsh. Maybe:
>
> rsh $line cat /home/basks.tbl|awk \'{ print $1 }\' >>test.out
>
> -Wayne

ITYM:

rsh "$line" awk \'{ print \$1 }\' /home/basks.tbl >>test.out

Also, if you're on Solaris make sure you're using New awk (nawk), GNU awk
(gawk), or /usr/xpg4/bin/awk, not /usr/bin/awk (oawk - old, broken awk).

Regards,

Ed.

Report this message

#8: Re: Reading from a file

Posted on 2008-04-22 17:29:25 by Bill Marcum

On 2008-04-22, invincible <imanuk2007@googlemail.com> wrote:
>
>
> It seems Im now stuck on below error
>
> rsh dubba awk '{ print $1 }' /home/basks.tbl
> syntax error The source line is 1.
> The error context is
> >>> { <<<
> awk: The statement cannot be correctly parsed.
> The source line is 1.
>
> Thankyou

You might need to write
rsh dubba "awk '{print $1}' /home/basks.tbl"

Report this message

#9: Re: Reading from a file

Posted on 2008-04-22 17:30:59 by Florian Kaufmann

> while IFS= read -r line
> do
> whatever
> done < file

Why do you set IFS? First I thought you do it so blanks are not
removed from the input when read is separating the input into words.
However, I tried this

$ od -a <<< "$IFS"
0000000 sp ht nl nl
0000004
$ while read -r x; do echo "$x" "-"; done <<< 'a b c
> d e f'
a b c -
d e f -

So it works also without setting IFS. Or am I missing something?

Flo

Report this message

#10: Re: Reading from a file

Posted on 2008-04-22 17:45:12 by Dave B

On Tuesday 22 April 2008 17:30, Florian Kaufmann wrote:

>> while IFS= read -r line
>> do
>> whatever
>> done < file
>
> Why do you set IFS? First I thought you do it so blanks are not
> removed from the input when read is separating the input into words.
> However, I tried this
>
> $ od -a <<< "$IFS"
> 0000000 sp ht nl nl
> 0000004
> $ while read -r x; do echo "$x" "-"; done <<< 'a b c
>> d e f'
> a b c -
> d e f -
>
> So it works also without setting IFS. Or am I missing something?

Try with leading blanks. Compare

echo " a b c" | while read -r line; do
echo "$line"
done

vs.

echo " a b c" | while IFS= read -r line; do
echo "$line"
done

--
D.

Report this message

#11: Re: Reading from a file

Posted on 2008-04-22 17:45:28 by invincible

On Apr 22, 4:27 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 4/22/2008 10:21 AM, Wayne wrote:
>
>
>
> > invincible wrote:
>
> >>On Apr 22, 2:49 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
> >>>On 4/22/2008 8:09 AM, invincible wrote:
>
> >>>>I am trying to read from a file for the list of servers and then
> >>>>instruct the script to login on these servers and run a command to
> >>>>check one text file.
> >>>>So far its done the below way...
> >>>>cat server-list | \
> >>>>while read line
> >>>>do
> >>>>echo "------------------------------------------------" >>test.out
> >>>>echo " HOST : $line" >>test.out
> >>>>echo "________________________________________________" >>test.out
> >>>>rsh $line cat /home/basks.tbl|awk '{ print $1 }' >>test.out
> >>>>done
> >>>>The problem seems to be that script does not work !!! :-)
> >>>>Any ideas around using cat wiht the while loop in a better way ?
>
> >>>Yes, don't use it. Instead of this:
>
> >>> cat file |
> >>> while read line
> >>> do
> >>> whatever
> >>> done
>
> >>>do this:
>
> >>> while IFS= read -r line
> >>> do
> >>> whatever
> >>> done < file
>
> >>>and instead of this:
>
> >>> cat file | awk '...'
>
> >>>do this:
>
> >>> awk '...' file
>
> >>>So, do that and then post a followup if your script still doesn't work.
>
> >>> Ed.
>
> >>Ed,
>
> >>It seems Im now stuck on below error
>
> >>rsh dubba awk '{ print $1 }' /home/basks.tbl
> >> syntax error The source line is 1.
> >> The error context is
> >> >>> { <<<
> >> awk: The statement cannot be correctly parsed.
> >> The source line is 1.
>
> >>Thankyou
>
> > Seems like the quote marks are removed too soon, by rsh. Maybe:
>
> > rsh $line cat /home/basks.tbl|awk \'{ print $1 }\' >>test.out
>
> > -Wayne
>
> ITYM:
>
> rsh "$line" awk \'{ print \$1 }\' /home/basks.tbl >>test.out
>
> Also, if you're on Solaris make sure you're using New awk (nawk), GNU awk
> (gawk), or /usr/xpg4/bin/awk, not /usr/bin/awk (oawk - old, broken awk).
>
> Regards,
>
> Ed.

Ed,

The problem is resolved . I am able to get the output for the first
server, but it seems it does not go beyond this. Any problems with the
loop we are using ?

Cheers.

Report this message

#12: Re: Reading from a file

Posted on 2008-04-22 18:01:53 by Ed Morton

On 4/22/2008 10:45 AM, invincible wrote:
> On Apr 22, 4:27 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>>On 4/22/2008 10:21 AM, Wayne wrote:
>>
>>
>>
>>
>>>invincible wrote:
>>
>>>>On Apr 22, 2:49 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>>>
>>>>>On 4/22/2008 8:09 AM, invincible wrote:
>>>>
>>>>>>I am trying to read from a file for the list of servers and then
>>>>>>instruct the script to login on these servers and run a command to
>>>>>>check one text file.
>>>>>>So far its done the below way...
>>>>>>cat server-list | \
>>>>>>while read line
>>>>>>do
>>>>>>echo "------------------------------------------------" >>test.out
>>>>>>echo " HOST : $line" >>test.out
>>>>>>echo "________________________________________________" >>test.out
>>>>>>rsh $line cat /home/basks.tbl|awk '{ print $1 }' >>test.out
>>>>>>done
>>>>>>The problem seems to be that script does not work !!! :-)
>>>>>>Any ideas around using cat wiht the while loop in a better way ?
>>>>>
>>>>>Yes, don't use it. Instead of this:
>>>>
>>>>> cat file |
>>>>> while read line
>>>>> do
>>>>> whatever
>>>>> done
>>>>
>>>>>do this:
>>>>
>>>>> while IFS= read -r line
>>>>> do
>>>>> whatever
>>>>> done < file
>>>>
>>>>>and instead of this:
>>>>
>>>>> cat file | awk '...'
>>>>
>>>>>do this:
>>>>
>>>>> awk '...' file
>>>>
>>>>>So, do that and then post a followup if your script still doesn't work.
>>>>
>>>>> Ed.
>>>>
>>>>Ed,
>>>
>>>>It seems Im now stuck on below error
>>>
>>>>rsh dubba awk '{ print $1 }' /home/basks.tbl
>>>>syntax error The source line is 1.
>>>>The error context is
>>>> >>> { <<<
>>>>awk: The statement cannot be correctly parsed.
>>>>The source line is 1.
>>>
>>>>Thankyou
>>>
>>>Seems like the quote marks are removed too soon, by rsh. Maybe:
>>
>>> rsh $line cat /home/basks.tbl|awk \'{ print $1 }\' >>test.out
>>
>>>-Wayne
>>
>>ITYM:
>>
>> rsh "$line" awk \'{ print \$1 }\' /home/basks.tbl >>test.out
>>
>>Also, if you're on Solaris make sure you're using New awk (nawk), GNU awk
>>(gawk), or /usr/xpg4/bin/awk, not /usr/bin/awk (oawk - old, broken awk).
>>
>>Regards,
>>
>> Ed.
>
>
> Ed,
>
> The problem is resolved . I am able to get the output for the first
> server, but it seems it does not go beyond this. Any problems with the
> loop we are using ?
>
> Cheers.

Post the code you're now using.

Ed.

Report this message

#13: Re: Reading from a file

Posted on 2008-04-22 18:23:19 by Bill Marcum

On 2008-04-22, invincible <imanuk2007@googlemail.com> wrote:
>
>>
>> rsh "$line" awk \'{ print \$1 }\' /home/basks.tbl >>test.out
>>
>> Also, if you're on Solaris make sure you're using New awk (nawk), GNU awk
>> (gawk), or /usr/xpg4/bin/awk, not /usr/bin/awk (oawk - old, broken awk).
>>
>> Regards,
>>
>> Ed.
>
> Ed,
>
> The problem is resolved . I am able to get the output for the first
> server, but it seems it does not go beyond this. Any problems with the
> loop we are using ?
>
> Cheers.

rsh might be consuming standard input. Try
rsh "$line" awk \'{ print \$1 }\' /home/basks.tbl </dev/null >>test.out

Report this message

#14: Re: Reading from a file

Posted on 2008-04-23 00:44:04 by Maxwell Lol

invincible <imanuk2007@googlemail.com> writes:

> The problem is resolved . I am able to get the output for the first
> server, but it seems it does not go beyond this. Any problems with the
> loop we are using ?

Be aware that rsh is unsecure. Use ssh if you can.
On my machine, rsh -> ssh.

Also - Bill says to use </dev/null. Try that.
Another way to do this, from the ssh man page

-n Redirects stdin from /dev/null (actually, prevents reading from
stdin). This must be used when ssh is run in the background. A
common trick is to use this to run X11 programs on a remote
machine. For example, ssh -n shadows.cs.hut.fi emacs & will
start an emacs on shadows.cs.hut.fi, and the X11 connection will
be automatically forwarded over an encrypted channel. The ssh
program will be put in the background. (This does not work if
ssh needs to ask for a password or passphrase; see also the -f
option.)

Report this message