Operating System - HP-UX
1748252 Members
3925 Online
108760 Solutions
New Discussion юеВ

Re: ssh , su , sh re-visited with "for" loop

 
SOLVED
Go to solution
eric lipede_1
Regular Advisor

Re: ssh , su , sh re-visited with "for" loop

Hi
thks Dennis!!!

This problem is a pain but the best solution in this case is running it from 1 single local machine. Can we assume, for the sake of focus and clarity that there is good reason why each step is required. Ie...the use of sh -c, su etc.
Essentially, solutions should be robust and portable. In THIS case that is achieved with my question.

Dennis was correct in his observation. I am ensuring that commands run in the same shell, using common commands producing the same results and error types.

Again, this detracts from the actual question. Its isnt which is the best method for achieving the result....its how do I get the provided bit of "code" to work.

I think we are almost there though.....

Dennis ....I tried :

ssh -f hpuxbox su - adiffuser -c 'sh -c "for i in 1\;do echo this is \$i\; done "'

but got

# The copyright note can be read by typing: cat /etc/copyright
Not a terminal
stty: : Not a typewriter
for: Command not found.

...and as a reminder ...each element works fine when you log on remotely and perform the commands etc.

ps. I do appreciate suggestions on "other ways"...but in this case i really need the solution to this particular question ...thks in advance.

Points will be assigned regardless so feel free to join in ...
Earl_Crowder
Trusted Contributor

Re: ssh , su , sh re-visited with "for" loop

ssh -f otherhost 'su - otheruser -c "sh -c \"for i in 1 2 3 ; do echo this is \\\$i ; done\" " '

Works for me.
eric lipede_1
Regular Advisor

Re: ssh , su , sh re-visited with "for" loop

thanks - that worked !
eric lipede_1
Regular Advisor

Re: ssh , su , sh re-visited with "for" loop

Thks for all the help