- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ssh using su and a different shell
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 02:44 AM
тАО10-29-2010 02:44 AM
Im attempting to ssh to another box (as root), su as another user and change shell to run a "for loop".
so...
it should look like :
ssh -t hpbox su - auser -c "sh for i in 1\;do echo \$i\;done"
Yes (in advance) I know that one method would be to add the shell to auser another would be to create a script and run that etc.
Im really interested in this method.
ssh -t hpbox su - auser -c 'ls' -> works
ssh -t hpbox su - auser -c 'sh ls' -> this logs me into the shell without running ls...
All help appreciated and rewarded - thks in advance. I have looked at the related threads but they dont address all 3 things - cheers
Solved! Go to Solution.
- Tags:
- sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2010 06:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2010 06:50 AM
тАО10-29-2010 06:50 AM
Re: ssh using su and a different shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2010 06:53 AM
тАО10-29-2010 06:53 AM
Re: ssh using su and a different shell
ssh -t hpbox su - auser -c 'sh -c ls'
Maintaining proper quoting through all the different command line parsing layers will be a bit of a challenge:
- local shell parses the command line once (removing the outermost set of quotes, and un-escaping backslash-escaped characters) before passing it to the ssh command
- root@hpbox's shell parses the su command line again (removing another set of quotes and possibly acting on special characters un-escaped in the previous step) before passing it to the su command
- auser@hpbox's "sh -c" should receive the payload part of the command line as one argument
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-29-2010 07:31 AM
тАО10-29-2010 07:31 AM
Re: ssh using su and a different shell
There's a definite limit to the amount of complexity you can have on a ssh remote command. Heck, even awk or perl one-liners can get a bit entertaining with quoting, escaping $ signs etc.
Any type of looping, in my opinion, definitely falls into the 'easier to do other ways' category.
If this is for an operational requirement, I'd look into those, if I were you. (even generating the script file on the fly and scp'ing it over...).
If this is just a mental exercise: good luck!
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 05:43 AM
тАО10-30-2010 05:43 AM
Re: ssh using su and a different shell
Maybe the following is also an option for you, by running the for loop on the local server the escaping would be much less complicated:
for i in 1;
do
ssh -t hpbox su - auser -c 'sh -c echo '$i;
done
Regards,
Viktor
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 06:01 AM
тАО10-30-2010 06:01 AM
Re: ssh using su and a different shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2010 09:47 PM
тАО10-30-2010 09:47 PM