Operating System - HP-UX
1825694 Members
3378 Online
109686 Solutions
New Discussion

Re: running remsh with su

 
SOLVED
Go to solution
Safdar Mustafa
Advisor

running remsh with su

Hi,

I am trying ro run a command from server1 to remotely execute on server2. However, the command requires the following:

su diff-user
csh
source /etc/example.cshrc
./run-command-in-script


Is there a simple way to do this?

So far I have unsuccessfully tried:

server1(root)# remsh server2 su diff-user -c "csh /path/run-command-in-script"

....failed miserably :-)

19 REPLIES 19
Warren_9
Honored Contributor

Re: running remsh with su

hi,

u don't need to use su, you can remsh to other user.

# remsh host [-l username] command

GOOD LUCK!!

Peter Nikitka
Honored Contributor

Re: running remsh with su

Hi,

I would enable a passwordless connection from root@server1 to diffuser@server2:
(as diffuser@server2): echo server1 root >>~/.rhosts

and then (as root@server1) use
remsh diffusr@server2 "csh -c 'source /etc/example.cshrc; ./run-command-in-script'"

to connect to server2.

mfG Peter

The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Chan 007
Honored Contributor

Re: running remsh with su

Hi,

What about this script in remote server

as /tmp/test.sh
su diff-user
csh
source /etc/example.cshrc
./run-command-in-script

You run just
remsh server2 /tmp/test.sh

Chan
Jakes Louw
Trusted Contributor

Re: running remsh with su

Sorry, no simple way...
If you want to execute something under diffuser@server2, then a trusted relationship of some kind is required.
That means either remsh or ssh.

However: have you tried putting your su in a script and executing the script?

# echo "su diff-user -c 'csh /path/run-command-in-script'" > local_dir/scriptname
# chmod 750 scriptname
# rcp local_dir/scriptname server2:~/scriptname
# remsh server2 scriptname

Might work?
Trying is the first step to failure - Homer Simpson
Safdar Mustafa
Advisor

Re: running remsh with su

Peter,

remsh diffusr@server2 cmd
does not work, my .rhosts is set ok with passwordless connection (works ok with remsh server2 cmd) - but is does not like diffuser?server2.
Gives: rcmd: diffuser@server2: Unknown host

Chan,
Tried script previously but su diffuser line terminates the script because it switches user and cannot continue the script. That's why I am looking for maybe a one-liner.

Jakes Louw
Trusted Contributor

Re: running remsh with su

An amendment to my previous post:

echo "su - diffuser -c ......"
Trying is the first step to failure - Homer Simpson
Safdar Mustafa
Advisor

Re: running remsh with su

Warren,
-l username does not work for other than root user.

Get error: remshd: Login Incorrect.

Jakes, still trying to figure yours out. Not sure it applies in my case but will do some testing anyway.
Chan 007
Honored Contributor

Re: running remsh with su

try
remsh server2 -n "your commands"

Chan
Jakes Louw
Trusted Contributor

Re: running remsh with su

Safdar, the idea is to encapsulate your su call INSIDE a script, then execute that script as a single call.
Here's the steps:
1) Put the call to "su" inside a script on the local server (my echo statement)
2) change the permissions on the local file (chmod ....)
3) remote copy the file (which preserves the chmod settings) to root on that side (rcp ....)
4) use remsh to execute this script, which then does an "su - diffuser -c ...." (remsh server2 script)
Trying is the first step to failure - Homer Simpson
Safdar Mustafa
Advisor

Re: running remsh with su

Thanks Jakes,
I definately see where your coming from, and this is what I have been trying for a while, however I cannot get the script to work on the local server even. In theory it should work, but its failing. Quite annoying since its quite a basic thing to do :-)

Will keep debugging.
Safdar Mustafa
Advisor

Re: running remsh with su

Alhumdulillah!!!

I cracked it... /etc/hosts.equiv made the difference I think. The following now works:

server1: remsh server2 -l diffuser "csh -c 'source /etc/xxxx.cshrc'; /myscript"


Thanks all you guys for you help.

Safdar
Enrico P.
Honored Contributor
Solution

Re: running remsh with su

Hi,
you can try to write the script in this form:

su - diff-user << EOF

command1
command2
.....

EOF

and remsh it

Enrico
Safdar Mustafa
Advisor

Re: running remsh with su

hey, you da man...

That looks to be the best working solution for all in one script. Reduces user error on running from command line.

Thanks 10/10!!

Safdar
Safdar Mustafa
Advisor

Re: running remsh with su

..the last message was meant for Enrico..
Jeff Schussele
Honored Contributor

Re: running remsh with su

Hi Safdar,

Not to scold but you *really* should be using ssh for this.
remsh is extremely insecure - I could run ethereal or tcpdump & get your PW or compromise your .netrc file as well.
You'll fail ANY SOX audit if you're using remsh.
It's *so* 90s :~()

My $0.02,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Safdar Mustafa
Advisor

Re: running remsh with su

Hi Jeff,

Thannks for the advice, but I don't seem to have ssh on my servers running 11.11.

#ssh server2
sh: ssh: not found.
#ksh
#ssh server2
ksh: ssh: not found
#man ssh
No manual entry for ssh.

how do I get it working...?
Jeff Schussele
Honored Contributor

Re: running remsh with su

Hi (again) Safdar,

The product number is T1471AA & it's available for free here:

http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=T1471AA

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Safdar Mustafa
Advisor

Re: running remsh with su

Thanks for you help, Jeff.
Jeff Schussele
Honored Contributor

Re: running remsh with su

Anytime my friend.
Just understand that there'll be a learning curve here.
But the upside is that it's much more versatile than remsh. For instance you can pass keys between servers & login, run remote processes, do secure ftp & copies all w/o having to pass PWs. But even if you do - they're encrypted as well as *all* data.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!