rsh [server] gawk "gawk-program" fails

rsh [server] gawk "gawk-program" fails

Post by Guy Waug » Sat, 18 Aug 2001 09:15:13



Hi there,

I'm trying to invoke a gawk command on host B from host A using rsh, like
this:
/usr/bin/rsh server2 /usr/bin/gawk "'{ MY_DATE = strftime(\"%d/%m/%Y\",\$1)
MY_INDEX = index(\$4, \"/\")  TCP_CODE = substr(\$4, 1, (MY_INDEX-1))  if
(!(TCP_CODE==\"NONE\" || TCP_CODE==\"TCP_DENIED\"))  print MY_DATE,
TCP_CODE, \$5, \$7, \$8  }' /var/logs/cache/access.log.0 >
/var/logs/cache/access.log.0.tmp"

When I run this command, here's what happens:
gawk: cmd. line:1: { MY_DATE = strftime("%d/%m/%Y",$1) MY_INDEX = index($4,
"/") TCP_CODE = substr($4, 1, (MY_INDEX-1)) if (!(TCP_CODE=="NONE"
|| TCP_CODE=="TCP_DENIED")) print MY_DATE, TCP_CODE, $5, $7, $8  }
gawk: cmd. line:1:                                              ^ parse
error
gawk: cmd. line:1: { MY_DATE = strftime("%d/%m/%Y",$1) MY_INDEX = index($4,
"/") TCP_CODE = substr($4, 1, (MY_INDEX-1)) if (!(TCP_CODE=="NONE"
|| TCP_CODE=="TCP_DENIED")) print MY_DATE, TCP_CODE, $5, $7, $8  }
gawk: cmd. line:1:
^ parse error
gawk: cmd. line:1: { MY_DATE = strftime("%d/%m/%Y",$1) MY_INDEX = index($4,
"/") TCP_CODE = substr($4, 1, (MY_INDEX-1)) if (!(TCP_CODE=="NONE"
|| TCP_CODE=="TCP_DENIED")) print MY_DATE, TCP_CODE, $5, $7, $8  }
gawk: cmd. line:1:
^ parse error

The first two parse errors seem to be referring to the equals signs between
MY_INDEX and index(), and between TCP_CODE and substr(). The third parse
error doesn't seem to refer to anything in the code, but always appears a
certain amount of characters after the beginning of the command.

The gawk program works when run from a shell script on server2.

I've looked in a few shell books and done a bit of searching, but I'm still
stuck... any pearls of wisdom, anyone?

Thanks in advance,
Guy.

 
 
 

rsh [server] gawk "gawk-program" fails

Post by Chris F.A. Johnso » Sat, 18 Aug 2001 09:32:31



> Hi there,

> I'm trying to invoke a gawk command on host B from host A using rsh, like
> this:
> /usr/bin/rsh server2 /usr/bin/gawk "'{ MY_DATE = strftime(\"%d/%m/%Y\",\$1)
> MY_INDEX = index(\$4, \"/\")  TCP_CODE = substr(\$4, 1, (MY_INDEX-1))  if
> (!(TCP_CODE==\"NONE\" || TCP_CODE==\"TCP_DENIED\"))  print MY_DATE,
> TCP_CODE, \$5, \$7, \$8  }' /var/logs/cache/access.log.0 >
> /var/logs/cache/access.log.0.tmp"

> When I run this command, here's what happens:
> gawk: cmd. line:1: { MY_DATE = strftime("%d/%m/%Y",$1) MY_INDEX = index($4,
> "/") TCP_CODE = substr($4, 1, (MY_INDEX-1)) if (!(TCP_CODE=="NONE"
> || TCP_CODE=="TCP_DENIED")) print MY_DATE, TCP_CODE, $5, $7, $8  }
> gawk: cmd. line:1:                                              ^ parse
> error
> gawk: cmd. line:1: { MY_DATE = strftime("%d/%m/%Y",$1) MY_INDEX = index($4,
> "/") TCP_CODE = substr($4, 1, (MY_INDEX-1)) if (!(TCP_CODE=="NONE"
> || TCP_CODE=="TCP_DENIED")) print MY_DATE, TCP_CODE, $5, $7, $8  }
> gawk: cmd. line:1:
> ^ parse error
> gawk: cmd. line:1: { MY_DATE = strftime("%d/%m/%Y",$1) MY_INDEX = index($4,
> "/") TCP_CODE = substr($4, 1, (MY_INDEX-1)) if (!(TCP_CODE=="NONE"
> || TCP_CODE=="TCP_DENIED")) print MY_DATE, TCP_CODE, $5, $7, $8  }
> gawk: cmd. line:1:
> ^ parse error

> The first two parse errors seem to be referring to the equals signs between
> MY_INDEX and index(), and between TCP_CODE and substr(). The third parse
> error doesn't seem to refer to anything in the code, but always appears a
> certain amount of characters after the beginning of the command.

> The gawk program works when run from a shell script on server2.

> I've looked in a few shell books and done a bit of searching, but I'm still
> stuck... any pearls of wisdom, anyone?

I recommend:
        Formatting the code so that it is more readable (that often brings
        errors to light)

        Putting the code into a file to eliminate the vagaries of shell
        escapes. By executing the file, you can make sure you are running
        the same code both on the server and via rsh.

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2001, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

1. How to "rcp"/"rsh" as "root"?

Hi all.

I guess this is a security safeguard; I find that I cannot use "rcp" and
"rsh" to operate another Linux machine while being the root user. How do I
enable this? I need this in order to transfer, load and map drivers, as
per the scripts accompanying KGDb. (Security is not a concern for now.)

I am using RedHat 7.2 with kernel 2.4.18.

If you see a 'X' in my address, remove it before e-mailing me.

-------------------------------------------------------------------------------
The FAQ files v1.21 for the Tropez, and v1.01 for the TBS-2001 sound
boards can be obtained from:
http://www.landfield.com/faqs/PCsoundcards/
http://www.cs.colorado.edu/~mccreary/tbeach/faq.html
http://www.pasteur.fr/infosci/FAQ/PCsoundcards/
http://faqs.org/faqs/by-newsgroup/comp/comp.sys.ibm.pc.soundcard.misc...
-------------------------------------------------------------------------------

2. : Problems restarting SuSE 6.0 after first boot

3. GETSERVBYNAME()????????????????????"""""""""""""

4. setting up a network

5. """"""""My SoundBlast 16 pnp isn't up yet""""""""""""

6. 486 mb question PLEASE HELP!

7. failed "Read Cd/Dvd Capacity";failed "Prevent/Allow Medium Removal"

8. telnetd x.c worm

9. "sar -f <file>" fails with "sar: malloc failed"

10. failed "Read Cd/Dvd Capacity";failed "Prevent/Allow Medium Removal"

11. failed "Prevent/Allow Medium Removal" ;failed "Read Cd/Dvd Capacity"

12. "Source Route Failed", "LOGIN FAIL..", "Malformed response", and "Lame server" messages in /var/log

13. combining "tail -f" and gawk