- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ssh , su , sh re-visited with "for" loop
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2010 07:22 PM
тАО10-29-2010 07:22 PM
does anyone have any ideas on how to write (as root):
ssh -f hpuxbox su - adiffuser -c sh -c "for i in 1\;do echo this is \$1\;done"
correctly as I currently get :
"for: Command not found."
Thks in advance for the answers and for all those that are tempted to say ..why dont you try using another method ie remote scripts ..thks for that but I really need the answer to the queston I have specifically asked. Cheers.
Points will be assigned.
Solved! Go to Solution.
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2010 09:10 PM
тАО10-29-2010 09:10 PM
Re: ssh , su , sh re-visited with "for" loop
Which command ur exactly try to run??
That command is not getting to shell thats y ur getting this error command not found.
If ur running from non root user, u need to ad d that command to users shell.
Hope this solves ur query.
Regards
Vishnu Khandare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2010 09:38 PM
тАО10-29-2010 09:38 PM
Solutionnot really as you didnt read/ understand the question right...but thks for your attempt anyway
Ill try to elaborate.....
I am logged in as root.
I wish to ssh to hpuxbox.
I wish to su - to adiffuser.
I wish change / switch shell from the default shell of adiffuser (csh) to sh.
I wish to run a for loop once im in that shell.
......all in one line.
The command i provided encapsulates what i want to do and what commands I wish to run.
fyi -> if i ssh , then su, then sh, then via the cmd line run "for....." ..it works .
thks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 04:21 AM
тАО10-30-2010 04:21 AM
Re: ssh , su , sh re-visited with "for" loop
You might try (untested):
# ssh -f hpuxbox su - adiffuser -c "{ for i in 1;do echo this is $i;done; }"
You might also reference the dialog that began in your initial thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1454190
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 04:36 AM
тАО10-30-2010 04:36 AM
Re: ssh , su , sh re-visited with "for" loop
mmmm tried but no peanuts, i also tried different combos of adding "\" and no joy :-(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 04:41 AM
тАО10-30-2010 04:41 AM
Re: ssh , su , sh re-visited with "for" loop
ssh -f hpuxbox su - adiffuser -c sh -c "{for i in 1\;do echo this is \$1\;done}"
..and no
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 05:12 AM
тАО10-30-2010 05:12 AM
Re: ssh , su , sh re-visited with "for" loop
You don't offer what "didn't work" --- syntax error?
Make sure that you have whitespace surrounding the curly braces. Use single quotes, too:
These work in a local environment:
# sh -c '{ for i in 1 2 3;do echo this is $i;done; }'
# su - adiffuser -c '{ for i in 1 2 3; do echo this is $i;done; }'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 05:27 AM
тАО10-30-2010 05:27 AM
Re: ssh , su , sh re-visited with "for" loop
Ive listed the errors..
ssh -f ahpuxbox su - adiffuser -c sh -c '{ for i in 1\;do echo this is \$i\;done }'
ssh -f ahpuxbox su - adiffuser sh -c '{ for i in 1;do echo this is $i;done }'
sh: Syntax error at line 1 : `do' is not expected.
ssh -f ahpuxbox su - adiffuser sh -c '{ for i in 1\;do echo this is $i\;done }'
sh: No such file or directory
ssh -f ahpuxbox su - adiffuser -c sh -c '{ for i in 1\;do echo this is $i\;done }'
The copyright note can be read by typing: cat /etc/copyright
Not a terminal
stty: : Not a typewriter
{: Command not found.
ssh -f ahpuxbox su - adiffuser -c sh -c "{ for i in 1\;do echo this is \$i\;done }"
The copyright note can be read by typing: cat /etc/copyright
Not a terminal
stty: : Not a typewriter
{: Command not found.
As you know the issue is associated with the ssh use and passing the commands when they get to the remote node. I hope the errors throw more light on the issue.
Running each part of the command separately works fine....just a problem when you put all of them together.
Thks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 06:10 AM
тАО10-30-2010 06:10 AM
Re: ssh , su , sh re-visited with "for" loop
I don't see why you need/want to impose another shell (... 'sh -c' ...)
Instead of:
# ssh -f hpuxbox su - adiffuser -c sh -c { for i in 1 2 3; do echo this is $i;done; }'
...try:
# ssh -f hpuxbox su - adiffuser -c '{ for i in 1 2 3; do echo this is $i;done; }'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 02:00 PM
тАО10-30-2010 02:00 PM
Re: ssh , su , sh re-visited with "for" loop
I would suggest you first need to quote the stuff after the first -c:
ssh -f hpuxbox su - adiffuser -c 'sh -c "for i in 1; do echo \"this is \$1\"; done"'
>JRF: I don't see why you need/want to impose another shell (... 'sh -c' ...)
Eric made it quite clear. That user is using the scummy C shell and he didn't want to be caught dead using it. ;-)
It seems that copying a real shell script over to the machine as suggested in the previous thread looks more and more the easiest solution.
- Tags:
- scummy C shell