How to write code inside ssh block in shell?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to write code inside ssh block in shell?
# 1  
Old 02-22-2011
How to write code inside ssh block in shell?

Hi,

I am new to shell script. I am trying to code on shell script but not able to find the correct syntax to write the code once it comes inside ssh.

For eg:
Code:
ssh -q HOST "
 
SwapInUse=\`vmstat -nm  | (while read; do echo "$(date +%Y%m%d.%H%M%S) $REPLY"; done) | tail -n +3 | awk '{print $4}'\`
 
echo \$SwapInUse
"

Does not work it suppose to.

Can someone please help and if possible can some one direct me to good link where I can read more about exceptions inside ssh.

Thanks,
Yagami

Last edited by Franklin52; 02-23-2011 at 03:32 AM.. Reason: Please use code tags, thank you
# 2  
Old 02-22-2011
Code:
man ssh

and focus on the -n and -t and -T options
# 3  
Old 02-24-2011
Hi,

Sorry but I am not able to understand the hint provided by you, can you please elaborate?

Thx.
# 4  
Old 02-24-2011
did you try

Code:
# ssh HOST "SIU=`vmstat -nm | { while read line; do echo \"\$(date +%Y%m%d.%H%M%S) \$line\";done } | tail -n +3 | awk '{print\$4}'`;echo \"SIU=\$SIU\""
SIU=39512080

By the way, why not to setup a script directly on the remote machine and then just call it ?

Last edited by ctsgnb; 02-24-2011 at 04:52 AM..
# 5  
Old 02-25-2011
Thanks for the help! But looks like that is also not giving the correct Swap In Use. I have couple of servers where I want to ssh so that might be a problem. Currently I am looping in HOST names and checking SIU.
# 6  
Old 02-25-2011
I only focused on the syntax : i assumed the command you gave was providing the expected result.

If it is not the case, then fix it first (directly on the remote machine).

When you have fixed the command so that it displays the result you expect, then just show us which command you passed and we will try to help you to find out the right syntax to pass it via ssh
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a Boolean variable which succeed and failed inside the if loop in shell script ?

I have if loop with multiple variable value check in if loop. How can i print only if loop satisfied variable and its value in shell script ? I dont want to check each variable in if loop. That makes my script larger. if ] then echo "Only satisfied variable with value" ... (3 Replies)
Discussion started by: prince1987
3 Replies

2. UNIX for Beginners Questions & Answers

How to have local shell variables in a ksh script seen on remove server in SSH block?

I have googled this and found many solutions, but none of them are working for me. I am in a korn shell, most others reference bsh, maybe that is the issue? Anyway, all I am trying to do is use a variable I have declared in my main script in a remote shell I am running through ssh. So I have a... (8 Replies)
Discussion started by: DJR
8 Replies

3. AIX

Need help on for loop inside ssh

Hi, I am having a file like, #cat file Jun 19 13:08 Jun 19 13:08 Jun 19 13:08 Jun 19 13:14 when I run the below comamnd locally it will work fine, IFS=$'\n'; for i in $(cat file) ;do echo "HI $i" ; done And the output is, HI Jun 19 13:08 HI Jun 19 13:08 HI Jun 19 13:08 HI... (1 Reply)
Discussion started by: sumanthupar
1 Replies

4. Shell Programming and Scripting

Executing multiple ssh commands inside a shell simultaneously

I would like to execute a commands in four different servers through ssh at a single instance(simultaneously). Below are the details with examples, ssh user1@server1 "grep xxxx logs" ssh user1@server2 "grep xxxx logs" ssh user1@server3 "grep xxxx logs" Each statement will take some... (4 Replies)
Discussion started by: Amutha
4 Replies

5. Shell Programming and Scripting

Write Awk output to a file , inside script.

Hi, Can anyone please help me with this issue. I have a Awk command which take file as input, and provides the output having multiple lines, its working in command mode, but not if i plug it in script. #!/bin/ksh infile=a.txt outfile=b.txt awk ' BEGIN{ FS=OFS="|";ORS = "\n";... (1 Reply)
Discussion started by: sp999
1 Replies

6. Shell Programming and Scripting

Using ssh command inside a script

Hi, I have a script file in server A. Inside the script file, I first have a ssh command that will connect to a remote server B. In the same script file itself, I have a sequence of commands that has to be run in server B. I am embedding these commands in the script file that I have in server A.... (2 Replies)
Discussion started by: mick_000
2 Replies

7. Shell Programming and Scripting

variables inside an ssh session

Hello all, I would like to declare and use variables inside an ssh session. I have the feeling that it's not possible. Here is the situtation simpified: #:/bin/sh test="salut" echo $test ssh hudson@10.41.21.99 <<EOF export testssh="salut" echo testssh=$testssh ... (4 Replies)
Discussion started by: Lotfus
4 Replies

8. Shell Programming and Scripting

ssh inside a for loop

Hi, The requirement is to ssh to unix servers and oracle databases, to perform some monitoring activity. I'm using shell script to perfom this. I pass the server details and database to a variable ... SERVERS="SERVER1 SERVER2 SERVER3" DATABASE="DB1 DB2 DB3" for i in $SERVERS do ssh... (2 Replies)
Discussion started by: senthil3d
2 Replies

9. Shell Programming and Scripting

looping a array inside inside ssh is not working, pls help

set -A arr a1 a2 a3 a4 # START ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS integer j=0 for loop in ${arr} do printf "array - ${arr}\n" (( j = j + 1 )) j=`expr j+1` done EOS # END ========= this is not giving me correct output. I... (5 Replies)
Discussion started by: reldb
5 Replies

10. Shell Programming and Scripting

FTP inside a block of code

I need help on the code below. I am getting a compile error syntax error at line 283 : `<<' unmatched Looks like it doesn't like the << on the ftp line below. If I ran the code outside of this block everything work fine, but when I put in a block of code or in a function, I got syntax error. I... (1 Reply)
Discussion started by: leemjesse
1 Replies
Login or Register to Ask a Question