Operating System - HP-UX
1843893 Members
2544 Online
110225 Solutions
New Discussion

remsh loses command auguments

 
SOLVED
Go to solution
Scott Lindstrom_2
Regular Advisor

remsh loses command auguments

I have a command that I remsh from one server to another. It happens to be a execution of sudo, but I dont think that it the problem. It looks like this (with the specific info changed):

remsh rmtserver /usr/local/bin/sudo /usr/bin/su - someuser -c "/usr/local/bin/rmt_script arg1 arg2"

When the script runs on the remote server the two arguments are not being received. (I reference $1 and $2 to save them into variables, and they are blank).

If I run the command directly on 'rmtserver':

/usr/local/bin/sudo /usr/bin/su - someuser -c "/usr/local/bin/rmt_script arg1 arg2"

it runs fine. So it seems that somehow using remsh drops the arguments.

I have tried all sorts of single quotes, double quotes, etc yet have not been able to find some way of making the two arguments gets passed to the remote server. Anyone have any ideas?

Scott
10 REPLIES 10
Steven E. Protter
Exalted Contributor

Re: remsh loses command auguments

Shalom,

/usr/local/bin/rmt_script

echo $# "That was the number of arguments"

Let's see if its getting aruguments or if it is confused.

We are tyring something complex. We sudo to run su to a user to run a commmand.

Other ideas(for grins)

Try the same thing with ssh openssh/secure shell. It might act differently.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Scott Lindstrom_2
Regular Advisor

Re: remsh loses command auguments

Steven -

I did put some of that code in:

echo $#

And get this when I run it with remsh

+ echo 0

I do see the whole setup is a bit odd. I have a script running as user1 to sudo a command that then su's to run as user2. So sudo is just my facilitator to allow this.

Scott
OldSchool
Honored Contributor

Re: remsh loses command auguments

note that the command you pass is sudo, everything else is an argument, so you may need to move the first double quote to just before /usr/local.

also, why are you using sudo to run su? wouldn't sudo -u username work?
OldSchool
Honored Contributor

Re: remsh loses command auguments

Also, are args 1 and 2 literals or shell variables, ie. $arg1 $arg2???
Scott Lindstrom_2
Regular Advisor

Re: remsh loses command auguments

I tried moving the first double quote to right after 'sudo' and get the same results.

I was not familiar that sudo could be used to switch to anything other than root, so I can try that option and see what happens.

The arguments being passed right now are literals (during my initial testing), but later on will be variables.

Scott
Scott Lindstrom_2
Regular Advisor

Re: remsh loses command auguments

I also tried the quotes just before /usr/local/bin; same results.
Steven E. Protter
Exalted Contributor

Re: remsh loses command auguments

Shalom again Scott,

Simply and rectify.

Change the script so it does nothing but echo arguments on the other end, or work with a cotpy.

Then as root, try and get things working.

Once that is resolved, than add sudo to the mix and play with the quotes some more.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
OldSchool
Honored Contributor

Re: remsh loses command auguments

sep beat me to it,

simple script, then
1) remsh the script w/literals
2) remsh script w/ variables (double qouting should, ie remsh srvx "script $a $b")

then start w/ sudos and su
TwoProc
Honored Contributor
Solution

Re: remsh loses command auguments

First off, IMHO, you should not be using remsh, and need to convert to ssh.

That being said, I think that this stands a chance of working , but I can't test it because I don't have remsh working anywhere.

remsh rmtserver "/usr/local/bin/sudo /usr/bin/su - someuser -c \"/usr/local/bin/rmt_script arg1 arg2\""

Just quote the remote shell command, and sub-quot the sudo command with backslashes, so that they are not evaluated unto the sudo command gets the strings.
We are the people our parents warned us about --Jimmy Buffett
Scott Lindstrom_2
Regular Advisor

Re: remsh loses command auguments

John -

That did the trick!

I agree with the ssh comment, and we are moving in that direction with new servers, but sometimes you just have to work with what you have at the moment.

Thanks!