executing commands over ssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting executing commands over ssh
# 1  
Old 07-28-2010
executing commands over ssh

Hi

I am trying to send a command over ssh with a parameter but the shell fails to expand the command properly any ideas what am i doing wrong with this.

This is ssh on AIX

Code:
for i in 71 72 73 74 75   do 
  for server in server1 server2   do 
    somestr="Some String" 
    echo "$server hdiskpower$i \c" ; ssh $server "lsattr -El hdiskpower$i |grep $somestr " 
  done 
done


Last edited by xiamin; 07-28-2010 at 04:35 AM..
# 2  
Old 07-28-2010
What is the error which you are getting? Probably you can try:

Code:
for i in 71 72 73 74 75 
do 
for server in server1 server2 
do 
somestr="Some String" 
cmd="lsattr -El hdiskpower$i |grep $somestr"
echo "$server hdiskpower$i \c" ; ssh $server "$cmd"
done 
done

done
# 3  
Old 07-28-2010
Hi

I get something like

grep: 0652-033 Cannot open volume.
grep: 0652-033 Cannot open identifier

regards
# 4  
Old 07-28-2010
Hi.

You probably just need to quote the grep, as it has a space in it:

Code:
for i in 71 72 73 74 75 
do 
  for server in server1 server2 
  do 
    somestr="Some String" 
    cmd="lsattr -El hdiskpower$i |grep '$somestr'"
    echo "$server hdiskpower$i \c" ; ssh $server "$cmd"
  done 
done

Your original code should also work.

Code:
for i in 71 72 73 74 75   do 
  for server in server1 server2   do 
    somestr="Some String" 
    echo "$server hdiskpower$i \c" ; ssh $server "lsattr -El hdiskpower$i |grep '$somestr'" 
  done 
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing commands sequentially

Hello. I am new in shell script. Could anyone help me? I have un shell script. I need each command in it be sequentielly, when the first command ends the second starts. When the second ends et third starts, and so on Thanks in adavance (1 Reply)
Discussion started by: nurinolo
1 Replies

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

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

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

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

6. Shell Programming and Scripting

Executing commands

I need to execute a command to run my script several times with varying parameters perl ex.pl -b 130198 -e 130884 -c plot plot.txt 1_plot.txt perl ex.pl -b 1345 -e 1308 -c plot plot.txt 2_plot.txt perl ex.pl -b 1345567 -e 130898 -c plot plot.txt 3_plot.txt . . . 100's of excutions ... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

7. Shell Programming and Scripting

Executing commands in different server

Hi Friends, I have a situation here, where I have a script running in one server, namely "SERVER1". Within this script which runs in SERVER1, I have a set of commands which has to connect to a different server (namely "SERVER2") and execute the commands accordingly. I have no experience at all... (1 Reply)
Discussion started by: sravicha
1 Replies

8. Shell Programming and Scripting

Executing many commands at once

Hi, I want to run these two commands one after the other. awk 'BEGIN {OFS="\t"} {print $2}' sort -u rather than typing awk 'BEGIN {OFS="\t"} {print $2}' file1 > file2, then sort -u file2 > file3. Is it possible to run both commands on file1 then get output file3? Its kinda hard for... (5 Replies)
Discussion started by: kylle345
5 Replies

9. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

10. Red Hat

How commands are executing ?

Hi Folks, I have a small doubt, the binary commands under /bin and /sbin as well as other path binary files, if you peek deep into that, you can find the difference in the way of normal perl programming and some commands will be like binary files. how are the commands executing like the... (3 Replies)
Discussion started by: gsiva
3 Replies
Login or Register to Ask a Question