ssh execution help needed.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh execution help needed.
# 1  
Old 03-23-2010
ssh execution help needed.

I m writing a program to execute remote script .
(display remote file content)
Whenever i execute following statement it gives me an error.


Code:
$command="cat /root/vm.cfg"
ssh -ttq root@10.180.8.236 $command


However following script work find.
Code:
ssh -ttq root@10.180.8.236 cat /root/vm.cfg

I have added rsa key so that it should not ask for any password while doing ssh.


What is wrong with using variable in ssh.
What could be the issue here?

Last edited by zaxxon; 03-23-2010 at 08:35 AM.. Reason: code tags - this is no php so just use [code] tags.
# 2  
Old 03-23-2010
Please post the error output.

Your example should work. From your explaination it is not clear to me if you only have problem with variable substitution or something with your password/key since you do mention that too.
To use ssh without password prompt you'll have to create and exchange keys that have been generated without entering a password while doing so (as side note).
# 3  
Old 03-23-2010
Thanks for your reply .
As i mentioned
this query work fine from command prompt
Code:
ssh -ttq root@10.180.8.236 cat /root/vm.cfg


Last edited by zaxxon; 03-23-2010 at 08:44 AM.. Reason: coooooooode tags, ty
# 4  
Old 03-23-2010
Hi,

use double quotes for the command variable

ssh -ttq root@10.180.8.236 "$command"
# 5  
Old 03-23-2010
Yes, I have read this.

Your answer does not help much:
Code:
$> VAR="ls -la /etc/hosts"
$> ssh somehost "${VAR}"
-rw-r--r-- 1 root root 1128 2010-03-01 13:45 /etc/hosts

But now I see your typo:
Code:
$command="cat /root/vm.cfg"

Leave the $ out.
# 6  
Old 03-23-2010
It got executed .But My problem is i m not able to execute the same from script.
I think it has something to do with scope of the variable.
# 7  
Old 03-23-2010
As script there is no difference. I asked 2 times already - here is the third and last time: Post your error output you get, thank you.
Guessing around and asking the same stuff all the time is getting tideous Smilie

Code:
$> cat mach.ksh
#!/usr/bin/ksh

VAR="ls -la /etc/hosts"
ssh somehost "${VAR}"
$> ./mach.ksh
-rw-r--r-- 1 root root 1128 2010-03-01 13:45 /etc/hosts

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Screen Output Needed on every execution

Hi , A shell script being executed by multiple user in a host, but i need the output of each user who executed the script user should have screen output as well ...and unique log file name should generated on execution of script is there anyway to get it below file will overwrite... (5 Replies)
Discussion started by: amar1208
5 Replies

2. Programming

Help needed to Spawn Shell on Python and Continue Execution

def gob(url): print "\n\t Running gobuster on target." params = " -e -s '307,200,204,301,302' -t 20 -u " + url + " >> /tmp/%s/gobuster.txt" % (ip) os.system("xterm -e bash -c "tail -f /tmp/%/gobuster.txt"") for i in bflist: dirbf = "gobuster -w " + i... (3 Replies)
Discussion started by: alvinoo
3 Replies

3. Shell Programming and Scripting

Remote script over ssh execution issues.

If I execute below code I am able to get string from column8 and column10 about a process. serverA1$> ps -ef | grep rotate | grep 'config' | awk '{print $8" "$10}' /<Oracle_home>/ohs/bin/odl_rotatelogs -h:/<app_Home>/config/OHS/ohs1/component_events.xml_ohs1... (12 Replies)
Discussion started by: kchinnam
12 Replies

4. HP-UX

Remote ssh execution and .profile issues

Greetings, i'm currently having issues in successfully executing a script from one server to other, and i'm cracking my nut in understanding why. Let's get started with the default info: Server A: briozzo@A:/home/briozzo $ uname -a HP-UX A B.11.31 U ia64 2787251109 unlimited-user license ... (3 Replies)
Discussion started by: nbriozzo
3 Replies

5. Shell Programming and Scripting

Script execution help needed.

I m using multiple scripts which are running on one master computer(server) and fetching records from another computers(client). For example. Machine A running scripts to execute code on Client machines say Machine B ,Machine C and Machine D respectively. Output of the script is then... (2 Replies)
Discussion started by: pinga123
2 Replies

6. Cybersecurity

Log remote execution over SSH

If a user execute commands remotely over ssh : $ ssh USERNAME@SERVER COMMANDSHow the SERVER administrator can log those COMMANDS executed in a "not a tty" session ? I searched for my question and get the following suggestions:Anybody give help how to do this ? what the content of "/bin/bash "... (1 Reply)
Discussion started by: new0h
1 Replies

7. Shell Programming and Scripting

ssh can't back from remote host during script execution

Hi all I wrote a script to execute a script on several remote hosts, but somehow during the execution of the local script, ssh can't come back from the remote host, so that causes my local script hanging... I use the below command to do the job in the local script, any idea? ssh... (12 Replies)
Discussion started by: bzylg
12 Replies

8. Shell Programming and Scripting

Script Execution Help Needed

Hi guys i have a script (takeconsole) as following I have moved it to /usr/local/bin to make the execution of script simpler. below are the content of the file. When i run the file by typing "takeconsole" .it always ask for entering the IP address but when i run it by using ". takeconsole".... (9 Replies)
Discussion started by: pinga123
9 Replies

9. Shell Programming and Scripting

Script lines execution after SSH

Hello Its a simple issue i suppose.I am trying to write a script which first logson to other server via SSH & tries to stop a process ,then returns to its originator & completes a task & finally jumps to that second servers again & starts the (stopped) process. What i am not able to implement... (2 Replies)
Discussion started by: ak835
2 Replies
Login or Register to Ask a Question