How To Run AWK via Remsh?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How To Run AWK via Remsh?
# 1  
Old 09-16-2008
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  
Old 09-16-2008
can you put the awk command in a script on the remote server and execute that script with remsh?
# 3  
Old 09-16-2008
Code:
su userID -c remsh server -l local userID "awk -F^ '\$4 == \"ABRAHAM\"' file.dat"


This link might be helpful too:

https://www.unix.com/shell-programmin...s-via-ssh.html
# 4  
Old 09-16-2008
Quote:
Originally Posted by frank_rizzo
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.
# 5  
Old 09-16-2008
Quote:
Originally Posted by rubin
Code:
su userID -c remsh server -l local userID "awk -F^ '\$4 == \"ABRAHAM\"' file.dat"


This link might be helpful too:

https://www.unix.com/shell-programmin...s-via-ssh.html
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.
# 6  
Old 09-16-2008
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"'

# 7  
Old 09-17-2008
Quote:
Originally Posted by frank_rizzo
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remsh

Hello All, I am on HP-UX. Problem is that my remote script behaves different depending on execution method. Method1 (Remote execution): remsh remoteserver /home/myscript.sh Method2 (Local execution): remoteserver :/home#sh myscript.sh In method 2, I can succesfully set timestamp with... (6 Replies)
Discussion started by: mrcrowley
6 Replies

2. UNIX for Advanced & Expert Users

Remsh command

Hi Can any 1 tell me how to use REMSH command with example actually i wanted to run the following command on different severs thru script "df -k .| tail -1 | tr -s ' ' ' ' | cut -d ' ' -f5" :) please reply ASAP.:) (3 Replies)
Discussion started by: maddy_07
3 Replies

3. Shell Programming and Scripting

How To Run A For Loop In A Remsh?

Hi all, I'm trying to remsh to another server and then execute a for loop command there but I'm getting unexpected errors and would appreciate any suggestions. Ideally what I want to do is this: for host in `cat host_file` do remsh $host -n " cd /home/ for DATABASE in `ls -d... (5 Replies)
Discussion started by: Korn0474
5 Replies

4. Shell Programming and Scripting

Remsh

Hi All, Im using remsh to execute shell script on remote server. And this script gets called from another AIX server. My code is: remsh $rHost -l $rUser -n "export JAVA_HOME=/usr/java6_64_SR7; export ORACLE_HOME=/oravl01/oracle/11.1.0.7; export... (3 Replies)
Discussion started by: AB10
3 Replies

5. UNIX for Advanced & Expert Users

How To Grep Via REMSH

Well I didn't think this would be so complicated when I started it but, well, here we are. :( I'm trying to REMSH to other servers and run a grep command. Now this works just fine until the item I'm grepping for has whitespaces in it and then UNIX gets stubborn. Normally one would grep for a... (1 Reply)
Discussion started by: Korn0474
1 Replies

6. UNIX for Dummies Questions & Answers

remsh from HP-UX to Solaris

Hi, I have encountered a problem when I try to issue a remsh command to a remote system (Solaris). I have created the .rhost file in the home directory on the remote system and added the hostname and user. "cat .rhosts 192.168.133.26 root" But when I issue the command from the... (5 Replies)
Discussion started by: mr_andrew
5 Replies

7. HP-UX

remsh + HPUX

Hi, I am trying to remsh from a HPUX to another unix server What is happening is I cant run commands on the other server ie I can remsh <remoteserver> -l <remotelogin> but I cant remsh <remoteserver> -l <remotelogin> -n pwd getting error message rshd: 0826-826 The host name for... (3 Replies)
Discussion started by: belfastbelle
3 Replies

8. UNIX for Advanced & Expert Users

remsh problem

Hi All, We have 2 unix boxes HP UX. From Box1 we need to run a script on Box2 using remsh. The job at Box2 exits with status 0 on successful completion & 1 if fails. But even if the scrips fails (exits with return status 1) at Box2, the $? get the value 0. script at Box2 : remote_script.sh... (2 Replies)
Discussion started by: sabyasm
2 Replies

9. UNIX for Dummies Questions & Answers

remsh

i m try to do remsh i need to know what are the step to define the user and password i try .rhosts it give me operator:/export/home/operator>remsh billmed ps -ef permission denied just for testing (3 Replies)
Discussion started by: kazanoova2
3 Replies

10. Shell Programming and Scripting

remsh and run script

Help! I'm would like to log in su - within a script an contuine to run the commands within the script. Every time I log in as su - I have to exit for the rest of the script to run! e.g. #!/bin/ksh su - oracle ps -ef |grep som <--- doesn't excute command until I log out su oracle.... (1 Reply)
Discussion started by: bugggg
1 Replies
Login or Register to Ask a Question