Variable value in ssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable value in ssh
# 1  
Old 04-21-2010
Variable value in ssh

Hi,
I'm creating a script where I connet to a remote machine, I execute a command (I get a pid of an application) and I kill the application.
I wrote this:

Code:
ssh $HOST_WHITEBOARD<<END

COMMAND_GET_PID_WHITE="ps aux | grep something | awk '/Sl+/ {print \$2}' | awk 'begin {row=0} row==0 {print; row++} row>0 {next}'"


echo "Command to execute: $COMMAND_GET_PID_WHITE"


echo "Try to take il PID"

PID=`eval $COMMAND_GET_PID_WHITE`

echo "Pid: $PID"

kill -9 $PID

END

I have the problem in these lines:

COMMAND_GET_PID_WHITE="ps aux | grep something | awk '/Sl+/ {print \$2}' | awk 'begin {row=0} row==0 {print; row++} row>0 {next}'"


echo "Command to execute: $COMMAND_GET_PID_WHITE"

the echo of COMMAND_GET_PID_WHITE is an empty string. Why? How can I solve?
Thanks, bye bye.
# 2  
Old 04-21-2010
can't you use pgrep ?
# 3  
Old 04-21-2010
What happens when you put double quotes around END ?
Code:
ssh $HOST_WHITEBOARD<<"END"

# 4  
Old 04-22-2010
Thanks a lot!
With:

ssh $HOST_WHITEBOARD<<"END"
it works!

Why do I have to put "?
Thanks again.
Bye bye.
# 5  
Old 04-22-2010
Hi abdujaparov,

From man sh:
Code:
       <<[-]word     The  shell input is read up to a line that is the same as
		     word after any quoting has been removed, or to an end-of-
		     file.  No	parameter  substitution, command substitution,
		     arithmetic substitution or file name generation  is  per-
		     formed  on  word.	The resulting document, called a here-
		     document, becomes the standard input. If any character of
		     word is quoted, then no interpretation is placed upon the
		     characters of the document. Otherwise,  parameter	expan-
		     sion,  command  substitution, and arithmetic substitution
		     occur, \NEWLINE is ignored, and \ must be used  to  quote
		     the  characters \, $, `.

S.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass path variable on SSH

hi Gurus, Have been struggling with this for a while I have 2 servers , lets say local A and remote B, I need to use both as a part of a pipeline. The folder structure is shared between the two, so I can access the same files and folders from both A and B. When I try to ssh into B from A,... (15 Replies)
Discussion started by: senhia83
15 Replies

2. Shell Programming and Scripting

Passing a variable via ssh, can't quite get it right

Hi Guys n Girls, Below im using a while command to wait for a file on another server then carrying on with the script..... I dont believe the $Sausage1 variable is being passed to the other server so its not finding the file. If i replace the variable with the date then it works as expected. ... (2 Replies)
Discussion started by: twinion
2 Replies

3. Shell Programming and Scripting

Remote command in variable using ssh

Hi, I've an issue in a shell script: I'm opening an ssh connection to a remote server, then I want to store the result of a ls command in a variable, but it doesn't work: the ls is done on the local machine. ssh user@server << EOF ls # works as expected (ls is done remotely) test=`ls` # the... (1 Reply)
Discussion started by: seloum57
1 Replies

4. Shell Programming and Scripting

how to assign value to the variable through ssh

Hi All, i am writing a shellscript to compare cksum of the file in local machine and after copying to remote machine. i am not able to assign command output value to variable in remote machine through SSH. PFB code for this. code: ###### Get File size of the file in local remote system ... (3 Replies)
Discussion started by: katamsivakumar
3 Replies

5. Shell Programming and Scripting

help about the ssh accpect a variable

# dir=/mnt # ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@10.0.2.3 'cd $dir;ls' The $dir doesn't take effect any help?? ( I want use variable to do something Thanks in advance (1 Reply)
Discussion started by: yanglei_fage
1 Replies

6. Shell Programming and Scripting

setting a variable, using SSH and awk?

hi there I am trying to get a value from a remote machine into a local variable. To get this value i want to use awk but im having trouble getting it to run, am i escaping in the right places here and using the right quotes (i must have tried a million combinations :() # VAR=`ssh server1... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

7. Shell Programming and Scripting

Issue in Variable in SSH

Friends, I want to write a script. The logic follows 1. Script starts 2. SSH to Remote Machine and check whether /home/testUser dir is there or not. 3. If it is there, am assigning a value to a variable. else not 4. If the variable is set, the do the copy from remote machine to my local... (2 Replies)
Discussion started by: balamv
2 Replies

8. Shell Programming and Scripting

Help with capturing homedir via ssh and saving to variable

I need to capture the homedir using the ssh command and then saving it to a variable. The results from the following command is what I need to capture to a variable: NOTE: the value I'm getting back is also incorrect. as it seems to be getting the home dir from the local server and not the... (2 Replies)
Discussion started by: reneuend
2 Replies

9. Shell Programming and Scripting

problem with Variable inside SSH

Hi Friends, i have small issue,... here is my problem............:) i am using two unix box A and B ..using my script i am able to connect from A to B without password(using ssh option like below). A:-> ssh user@B-2.10.32.23 but i declared one variable in A which is something... (5 Replies)
Discussion started by: Shahul
5 Replies

10. Shell Programming and Scripting

awk using ssh variable?

I have a file named Atoms that has a list of atoms listed vertically, like: O C Na etc. There is a variable number of them. I want to count their occurences in another file. I want to do this by saving each atom as a variable, preferabbly in an associative array, then counting how... (3 Replies)
Discussion started by: RisingSun
3 Replies
Login or Register to Ask a Question