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.
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.
Without escaping, the backticks would be evaluated locally; that was the reason you got the error message about the directory. I thought you said you had it working now, though.
I tried executing just ls -l on the remote server. Actually the abc will wary from server to server, i have a list of servers which iam reading line by line and ssh to each of them and executing this
ssh X.X.X.X "for i in `ls -l /export/home/abc[12]|awk '{Print $9}'`|do cd $i; tar -cvf new.tar file1 file2; done "
bash: -c: line 1: syntax error near unexpected token `|d'
bash: -c: line 1: `for i in |do cd ; ls -l; done '
Here iam putting abc[12] but ideally i want abc*
The content of file1 and file2 will vary between abc1 and abc2, thats why iam putting these directories in the loop.