How to store remote variable from remote cat file ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to store remote variable from remote cat file ??
# 1  
Old 08-24-2015
How to store remote variable from remote cat file ??

I am trying to cat on a file located on remote server and assign it to remote variable.


I have both local and remote variables. Running below script from local. test.sh

Code:
J_NAME=XXX2
J_IP=XXX
ssh $J_IP  "ps auxw |grep java | grep -v grep |grep $J_NAME | awk '{print  \$2}'>/tmp/$J_NAME.pid;
chmod u+rwx /tmp/$J_NAME.pid;
pid= cat /tmp/$J_NAME.pid;
echo \$pid; kill -3 \$pid >>/tmp/$J_NAME.log"

I can print remote value by doing cat on remote /tmp/$J_NAME.pid but not able to store in remote variable and do some work on that variable.

I understand concept of `,",',\. Looks like I am missing something Smilie

Last edited by oraclermanpt; 08-24-2015 at 07:38 PM..
# 2  
Old 08-24-2015
Hi, to put the output of a command into a variable, use command substitution
Code:
var=$(command)

# 3  
Old 08-25-2015
A few points I think I should mention:-
  • You are needlessly issuing chmod as the file will be RW by you in any case and there is no need to execute it - it's just the output from ps after all.
    .
  • You ssh finishes and the file $J_NAME.pid is written to the local server, not the remote.
    You then try to kill the remote process on the local server which could be very bad if you have a process id locally that matches.
    Create your script on the remote server, then execute it as one process.
i hope that this helps,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

scp auto logon to remote using remote authorized_keys

Hi~ i have an authorized key which it made remote host(B). i want log on without password from local(A) to the remote host(B) using authorized key of remote host. what shell i do? anybody help me. (1 Reply)
Discussion started by: tomato00
1 Replies

2. Shell Programming and Scripting

Delete line from remote file over ssh passing variable

I have a variable called $a1 which maps to something like "http://servername proxy1 count http" and a lots of entries in a file on remote server. If I have the following in my .sh script: sed -i "\%$a1%d" mylog.txtthe line is deleted from mylog.txt. Great. I'm trying now to remvoe this from a... (3 Replies)
Discussion started by: say170
3 Replies

3. Shell Programming and Scripting

awk remote multiple hosts print remote hostname and output

Hi all, i'm trying to gether multiple pattern on remote hosts, and trying to print hostname and the pattern, ssh remoteserver1 -C 'hostname 2>&1;cat /var/log/server1.log | awk -F ";" '"'"'{ print " "$2" "$5}'"'"'| sort | uniq -c | sort -g -r ' The output is the following, remoteserver1 ... (8 Replies)
Discussion started by: charli1
8 Replies

4. Shell Programming and Scripting

Check/get the exit status of a remote command executed on remote host through script

Geeks, Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s). Here's the complete... (5 Replies)
Discussion started by: lovesaikrishna
5 Replies

5. 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

6. UNIX for Dummies Questions & Answers

Why does SSH store the fingerprints of remote host when connecting for the first time?

I was wondering why does ssh store the fingerprints of remote host when connecting for the first time? I will appreciate a detailed response, can't figure it out. (2 Replies)
Discussion started by: ChiefGandalf
2 Replies

7. Shell Programming and Scripting

Triggering remote UNIX shell script from Remote desktop

I m trying to run a batch script in remote desktop which executes unix commands on the unix server...the problem is i wnt the output in HTML format.so in my batch script i m giving the cmd like ssh hostname path ksh HC_Report.ksh>out.html ...but it generates the HTML file in remote desktop .i... (2 Replies)
Discussion started by: navsan
2 Replies

8. Debian

Launch remote gui apps in remote hosts

Hi, I've been looking for a way to execute a console program (is in windows but by now I accept the linux way) from a linux machine, but this program has to be opened in the remote side. Linux machine acts only as a "signaling" host. My program has to open the camera in the remote side, but only... (7 Replies)
Discussion started by: zauberberg
7 Replies

9. Solaris

how to login with ssh to remote system with out applying the remote root/usr password

how to login with ssh to remote system with out applying the remote root/user password with rlogin we can ujse .rhosts file but with ssh howits possible plz guide (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

10. Solaris

Remote Dial-up Modem Printing With Out Cpu On The Remote Side!

I am looking for a dial-up remote printing solution as under : 1. We have a Centralized location where Sun Solaris (A) is installed. From here printing command will be despatched. 2. This printing command will be routed to WAN cloud to Main Branches (B1,B2,B3)and from there, printer at... (0 Replies)
Discussion started by: jayvee
0 Replies
Login or Register to Ask a Question