The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
change ip via remsh kenshinhimura HP-UX 7 04-12-2008 10:03 AM
how to use remsh to duplicate all... rauphelhunter Shell Programming and Scripting 0 01-14-2008 01:19 AM
remsh working one way xramm SUN Solaris 2 10-16-2007 05:57 AM
remsh problem sabyasm UNIX for Advanced & Expert Users 2 12-06-2005 07:21 PM
remsh kazanoova2 UNIX for Dummies Questions & Answers 3 12-21-2004 10:39 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-16-2008
Korn0474 Korn0474 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
How To Run AWK via Remsh?

Boy I hope someone can answer this question. I've been beating my head against the wall all day trying to come up with a solution.

I have a carrot delimited file that looks like this:
ANDERSON^678934^1974^BOB
JONES^564564345^1954^ABRAHAM
SMITH^47568465^1948^JON


If I run this command:
awk -F^ '{ if ($4 == "ABRAHAM") print $0 }' file.dat
...directly from the server where the file is located it works great.

But I really need to run it from a remote server so I rewrote it like this:
su userID -c 'remsh server -l local userID awk -F^ '{ if ($4 == "ABRAHAM") print $0 }' file.dat'

But when I do I get the error:
ksh: syntax error: `(' unexpected

I have tried other variations as well. Including: su userID -c 'remsh server -l local userID awk -F^ '$4~/^ABRAHAM$/' file.dat'
But this one gives the error message:
syntax error The source line is 1.
The error context is
>>> ~ <<<
awk: Quitting
The source line is 1.


...and even: su userID -c 'remsh server -l local userID awk -F^ '$4 == "ABRAHAM"{print $0}' file.dat'
And this one gives the error message:
syntax error The source line is 1.
The error context is
>>> == <<<
awk: Quitting
The source line is 1.


I'm really stuck. All these variations seem to work until I wrap it in the remsh syntax and then it just fails. If anyone can help point me in the right direction I'd be very grateful.

Last edited by Korn0474; 09-16-2008 at 09:53 PM..
  #2 (permalink)  
Old 09-16-2008
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
  
 

Join Date: Dec 2007
Posts: 426
can you put the awk command in a script on the remote server and execute that script with remsh?
  #3 (permalink)  
Old 09-16-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321

Code:
su userID -c remsh server -l local userID "awk -F^ '\$4 == \"ABRAHAM\"' file.dat"


This link might be helpful too:

How to execute multiple commands via ssh
  #4 (permalink)  
Old 09-16-2008
Korn0474 Korn0474 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
Quote:
Originally Posted by rubin View Post
Code:
su userID -c remsh server -l local userID "awk -F^ '\$4 == \"ABRAHAM\"' file.dat"


This link might be helpful too:

How to execute multiple commands via ssh
That almost got it.

It gives the error:
su: illegal option -- l
usage: remsh host [ -l login ] [ -n ] command


So I wrapped the remsh call in sinqle quotes (or ticks) as I have done in the past with this type of su to remsh call
su userID -c 'remsh server -l local userID "awk -F^ '\$4 == \"ABRAHAM\"' file.dat"'
...and it doesn't give an error but neither does it give any results at all.

But if I separated the command into two lines like this:
su userID -c
remsh server -l local userID "awk -F^ '\$4 == \"ABRAHAM\"' file.dat"

...and works for some reason. Which is fantastic but I'd really like to know how to get it all in one call if possible.
  #5 (permalink)  
Old 09-16-2008
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
  
 

Join Date: Dec 2007
Posts: 426
how about this? Does awk have to run remotely?


Code:
su userID -c "remsh server -l local userID cat file.dat" | awk -F^ '$4 =="ABRAHAM"'

  #6 (permalink)  
Old 09-17-2008
Korn0474 Korn0474 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
Quote:
Originally Posted by frank_rizzo View Post
how about this? Does awk have to run remotely?


Code:
su userID -c "remsh server -l local userID cat file.dat" | awk -F^ '$4 =="ABRAHAM"'
I'll run some tests but I think catting the file and then running awk will be too slow. The file it's scanning is massive and the scans will be running a lot for varying requests. So speed is relatively important.
  #7 (permalink)  
Old 09-16-2008
Korn0474 Korn0474 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
Quote:
Originally Posted by frank_rizzo View Post
can you put the awk command in a script on the remote server and execute that script with remsh?
Yes and no. It would probably work but the program that is already generating this command call does not create files with sufficient permissions to execute them. So that would require another step to chmod the file. Also, the return from the awk command needs to be output to a file on the local server so that would mean another two steps. One to generate it and a second to remsh it back to the local server. I'd like to avoid this if possible.
Closed Thread

Bookmarks

Tags
unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On




All times are GMT -4. The time now is 01:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0