Executing awk in a remote server using ssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing awk in a remote server using ssh
# 1  
Old 10-24-2007
Executing awk in a remote server using ssh

Hello Everybody,

I'm facing a weird problem with the awk command.

I'm trying to execute a simple awk command as follows,

echo 1 2 | awk '{print $2}'

This command prints the output 2.

When i try to execute the same command in a remote server using ssh as follows,

ssh user@host <<HERE
echo 1 2 | awk '{print $2}'
HERE

The output i get is '1 2' instead of just 2.

But when i put the command (echo 1 2 | awk '{print $2}') in a file and use a input redirection as follows,

ssh user@host < cmdfile #cmdfile contains the command

i get the output 2.

Can anyone please clarify this difference in the behaviour of awk command.
# 2  
Old 10-24-2007
Executing awk in a remote server using ssh

I found a partial solution to my problem.

Just to let you know, in this case $2 was being treated as a shell variable and not as awk variable

This works and gives me the output 2

ssh user@host <<HERE
> echo 1 2 | awk '{print \$2}'
> HERE

But i'm still not able to figure out why it works when a command file is given as input to ssh without an escape sequence
# 3  
Old 10-25-2007
Quote:
Originally Posted by karthikv
I found a partial solution to my problem.

Just to let you know, in this case $2 was being treated as a shell variable and not as awk variable

This works and gives me the output 2

ssh user@host <<HERE
> echo 1 2 | awk '{print \$2}'
> HERE

But i'm still not able to figure out why it works when a command file is given as input to ssh without an escape sequence

The single quotes do not prevent variable expansion in a here document; they do in a script.

In this case, $2 expands to nothing, so the awk command is just '{print }'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remote script via SSH not executing

I have worked on multiple scenarios to execute remote script via ssh. This problem I am not able to resolve. 2 linux hosts. Server1, Server2 on Server1 I have script called ~/scripts/start_standalone.sh XXXX cd $JBOSS_HOME NODENAME=xyz; IP_ADDR=`hostname`; MGMT_IPADDR=`hostname`;... (3 Replies)
Discussion started by: oraclermanpt
3 Replies

2. Shell Programming and Scripting

Issue in executing cat (remote ssh)

Hi, I need to ssh remotely to a machine and cat a file assign the value to a variable Script: #!/bin/bash -x value=`cat config.txt` echo "$value" ssh me@xxx.host.com "valu='cat /export/home/test.md5'; echo "$valu"" | tee Execution: $ ./x ++ cat config.txt + value='touch me' +... (5 Replies)
Discussion started by: close2jay
5 Replies

3. Linux

Executing a script in remote machine through ssh

How to execute a script in remote machine through ssh I have a script test.sh which does some backup activity in remote machine. Wanted to keep backup also in remote machine. ssh -l username <remote machine> "commands to be exceuted as ; separted" but how to put the script in the place of... (5 Replies)
Discussion started by: sanvel
5 Replies

4. Shell Programming and Scripting

Executing remote commands via ssh

Hi, I'm tryin to write a script that will collect information about a remote servers, put them into variables and print them to screen. # /usr/bin/bash ls $1 > /dev/null 2>/dev/null if then echo "$1 is file" for server in $(cat $1) do # echo $server ... (5 Replies)
Discussion started by: moshesa
5 Replies

5. Shell Programming and Scripting

Executing remote server sqlplus

Hello Guys I have to compare flat file record to oracle table record count count which are on different servers I am taking the flat file record count from the server now I am connecting to remote server first and then running sqlplus But after connecting to remote server the sqlplus... (3 Replies)
Discussion started by: Pratik4891
3 Replies

6. Shell Programming and Scripting

executing commands in remote server using ssh

I have some commands which need to be executed in remote machine. I have Linux Server from where I need to connect to Solaris server using ssh and then declare some variable over there and run some commands. I don't want to call a script which is present in Solaris server from Linux server... (7 Replies)
Discussion started by: maitree
7 Replies

7. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

8. Shell Programming and Scripting

Executing remote application using ssh without full reference to its location

Hello again :) , My script has an ssh command to run a script on a remote machine. The script has commands such as sqlplus and unzip. However, the return I get in my own terminal says it can't find sqlplus and unzip. the ssh command is: ssh user@host "cd ScriptDir; ./Script.sh" and the... (6 Replies)
Discussion started by: jangozo
6 Replies

9. UNIX for Dummies Questions & Answers

how to stay in remote shell after executing commands in ssh?

the ssh calling convention: ssh <server> If I put commands in the section, ssh will execute them immediately after logging in and return to local shell. I want to stay in the remote shell after executing these commands. How can I achieve this? Thanks for all. (1 Reply)
Discussion started by: hplonlien
1 Replies

10. Shell Programming and Scripting

Executing a script on a remote system via SSH

Hello all, I have a relatively simple script I wrote to generate a count of errors broken down. What I would like to do is execute this script from another server so that I don't actually have to log in to the server to run the check. The script on what we'll call "Server A" is: ... (2 Replies)
Discussion started by: DeCoTwc
2 Replies
Login or Register to Ask a Question