ssh and executing a for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh and executing a for loop
# 1  
Old 09-05-2008
ssh and executing a for loop

Hi all,

I am trying to run a script which is expected to do:

on the remote machine,
There are two directories /export/home/abc1,/export/home/abc2
i am trying to do,
ssh SERVERNAME "for i in `ls -l /export/home/abc*|awk '{print $9}'`; do cd $i; ls -l; done"

But its not working ,iam getting /export/home/abc*:No such file or directory.
When i run the for loop in the remote system its working fine.

The system is Solaris 8 and running as root.

Please let me know if something wrong


Thanks.
# 2  
Old 09-05-2008
The whole script is enormously overcomplicated.

Code:
ssh SERVERNAME 'ls -l /export/home/abc[12]'

The error message indicates that this is not as such the problem, though. Are you sure the path is correct?
# 3  
Old 09-05-2008
Hi ,

Thanks for the reply.

The paths are correct, i dont want to use abc[12] as they might vary from servers, thats why i use generic abc*,
Please advise.


Thanks.
# 4  
Old 09-05-2008
Feel free to change that, does it work with these changes?
# 5  
Old 09-05-2008
Hi,

It worked.

Is it possible to do other operations like tar etc inside these directories?

Thanks,
# 6  
Old 09-05-2008
Anything you can run at the prompt, you can run with ssh, but properly quoting the arguments you want to pass to the remote server can be a challenge if it's a complex script.
# 7  
Old 09-05-2008
can you tell me what's wrong with my command. Do i need to put any escape characters?


Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remote script via SSH not executing

I have worked on multiple scenarios to execute remote script via ssh. This problem I am not able to resolve. 2 linux hosts. Server1, Server2 on Server1 I have script called ~/scripts/start_standalone.sh XXXX cd $JBOSS_HOME NODENAME=xyz; IP_ADDR=`hostname`; MGMT_IPADDR=`hostname`;... (3 Replies)
Discussion started by: oraclermanpt
3 Replies

2. Shell Programming and Scripting

Query on executing awk using SSH

Hi All, Im trying to find the count of process running on remote server using SSH. Below command dosen't work. ssh -q user@host "ps -ef | grep "pattern" | grep -v 'grep' | awk '{print $2}'|wc -l" But below command works. ssh -q user@host "ps -ef | grep "pattern" | grep -v... (1 Reply)
Discussion started by: Girish19
1 Replies

3. Shell Programming and Scripting

Help with executing awk and While loop

Hi All, I have a file say, sample.txt Source Name: xxx Department|Revenue 1001|3252 1002|3345 I am using the above file in one of my script. I need to read from Line 3 of the above the file and do some process. My script has a code: awk 'NR > 2' sample.txt | while read Dep; do... (9 Replies)
Discussion started by: machomaddy
9 Replies

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

5. UNIX for Dummies Questions & Answers

executing a command using ssh

Hi All, I am trying to execute a command using ssh as below. ssh user123@servername "which ctmcontb" It is gving the error as below no ctmcontb in /usr/bin /usr/sbin /opt/sysadm/bin Not sure from where the PATH is getting picked up. But When I login direclty to the server I am... (5 Replies)
Discussion started by: anilreddy103
5 Replies

6. Shell Programming and Scripting

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 for i in 71 72 73 74 75 do for server in server1 server2 do somestr="Some String" echo "$server... (3 Replies)
Discussion started by: xiamin
3 Replies

7. Shell Programming and Scripting

Problem with executing script using ssh

I'm writing a script which is meant to ssh into a remote machine, sed a file there, and write the output to a new file on the remote machine. Obviously the easy way to do this is to write and execute the script on the remote machine, but I'm trying to do this all via ssh since I like to keep and... (4 Replies)
Discussion started by: maethlin
4 Replies

8. Shell Programming and Scripting

Script not executing second loop

I have a server that receives backup files from several servers. Each server has its own directory to scp their files into, some of the files are received as .tar files and need to be compressed before being dumped. When the scp of the tar file is complete a file named 'flag' is also sent to... (2 Replies)
Discussion started by: thumper
2 Replies

9. Shell Programming and Scripting

Error while executing glance using ssh

Hi, I'm running glance ussing ssh from a "HP-UX" machine for a Sun machine. Here is a sample code:- x:- HP-UX y:- Sun Extracting a value from glance outuput. ssh x@y "/opt/perf/bin/glance -f -adviser_only -iterations 2 -maxpages 1 > glance.op ; echo `head -1 glance.op | a wk '{print... (0 Replies)
Discussion started by: bishweshwar
0 Replies

10. UNIX for Advanced & Expert Users

executing .profile with ssh

Hi, How do I get all my profile settings when connecting with ssh? (5 Replies)
Discussion started by: rein
5 Replies
Login or Register to Ask a Question