Operating System - HP-UX
1834915 Members
2828 Online
110071 Solutions
New Discussion

Re: Executing a Remote Shell Script

 
SOLVED
Go to solution
Andrew Huizenga
Occasional Advisor

Executing a Remote Shell Script

I'm attempting to run a remote shell script from my server on another workstation, but I keep getting the "not found" message anytime I attempt to run the script from my server, but can run it fine on the other server when I'm logged in. I'm using the following line in a local script to try and run the script remotely:

remsh server -l user -n "cd /full/path/of/script/;ls;'callscript $host $dbase $rdg'"

When the "ls" is called I can see the "callscript", but when the script is actually called I get:

sh: callscript host dbase rdg: not found.

Where host, dbase, rdg are values entered by the user. Now, I can take that exact line "callscript host dbase rdg" and it will run succesfully while I'm logged into the remote workstation. The workstations .rhosts file is updated with:

myserver myusername
+ myusername

Any advice on what I need to add to my local script to run the remote script successfully?

Thanks.
14 REPLIES 14
Geoff Wild
Honored Contributor
Solution

Re: Executing a Remote Shell Script

Instead of callscript use full path:

/full/path/of/script/callscript

. and /full/path/of/script/ are in in the default PATH - and . should NEVER be.

Rdgs...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Peter Nikitka
Honored Contributor

Re: Executing a Remote Shell Script

Hi,

change your command line to use the pathname and drop the wrong usage of the single quotes:

remsh server -l user -n "cd /full/path/of/script/;ls;./callscript $host $dbase $rdg"

Your attempt tries to locate a program
'callscript host dbase rdg' (spaces are part of the program name!) via the PATH variable.

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"
Andrew Huizenga
Occasional Advisor

Re: Executing a Remote Shell Script

This time I get:

sh: /home/gp7200/550-PROD/scripts/callPRODscripts 10.31.152.94 3424 7374: not found.

Modified the script to have:

remsh server -l user -n "'/full/name/of/path/callscript $host $dbase $rdg'"
Andrew Huizenga
Occasional Advisor

Re: Executing a Remote Shell Script

Peter-

I modified the line to:

remsh server -l user -n "/full/name/of/path/callscript $host $dbase $rdg"

And now receive:

/full/name/of/path/callscript: expect: not found.

In the remote script "callscript", I'm using the "expect" function- is there something in my local script I need to add to specify a location of "expect"?

Peter Nikitka
Honored Contributor

Re: Executing a Remote Shell Script

Hi Andrew,

it is good practise to check for the existence of non-standard tools, which you are using in scripts.
If its a ksh script, you can do it like this:
#
if ! whence expect >/dev/null
then PATH=$PATH:/path/where/tools_are_found
fi

If you have a setup of an environment commonly used after a normal login (e.g. /usr/local/env/common.env), you could source it explicitly in your remsh-command:

remsh server -l user -n ". /usr/local/env/common.env; cd /full/path/of/script/;ls;./callscript $host $dbase $rdg"

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"
Andrew Huizenga
Occasional Advisor

Re: Executing a Remote Shell Script

I guess I'm a bit confused- when I'm using remsh, I thought it was just the same as being logged into the remote server and running the script. Is it assuming the the "expect" function on the remote server is in the same location as my local server?
Peter Nikitka
Honored Contributor

Re: Executing a Remote Shell Script

Hi,

you can check:

echo $PATH
remsh -l user -n 'echo $PATH'

Reasons:
- it's another user, you are connected to
- it's a remote server and your toolpath may vary
- it's not an interactive session you are using, so some setting may not be done

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"
Andrew Huizenga
Occasional Advisor

Re: Executing a Remote Shell Script

Okay. When I run the echo $PATH on the local server, and then the remote server using remsh, I get the same result. However, when I log into the other server (as a different user not the same as my local server), I get a different result.

I did a "which expect" on both servers, and the expect function appears to be located in the same directory on both (/apps/bin/expect).

I guess I'm still confused as to why I'm getting that "not found" message if "expect" is located in the same place on both servers.
OldSchool
Honored Contributor

Re: Executing a Remote Shell Script

the question is really "what is $PATH for the user id, on the remote server, that is attempting to run the command"

usually, I just set the path to what I need it to be in the script and be done with it.............
Geoff Wild
Honored Contributor

Re: Executing a Remote Shell Script

In your script - hard code the calls to other apps:

/usr/local/bin/expect

not

expect



Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Andrew Huizenga
Occasional Advisor

Re: Executing a Remote Shell Script

Thanks, hardcoding worked!
Geoff Wild
Honored Contributor

Re: Executing a Remote Shell Script

No worries Andrew.

PS - welcome to the forums!

Please have a read through:

http://forums1.itrc.hp.com/service/forums/helptips.do?#28

Basically, points help people determine the relevance of the answer when they search the ITRC for similar questions.

Also, it is a good idea to close a thread when you are satisfied with the answers.

Thanks...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Bill Hassell
Honored Contributor

Re: Executing a Remote Shell Script

Good script writing dictates that NO assumptions are made about the environment. The remsh environment is not set as if you logged in because remsh does not login -- instead, it validates that your request has been validated and then sets a minimal environment. The same is true for cron and other batch operations. So there are three mandatory statements at the beginning of every script you write:

#!/usr/bin/sh
set -u
export PATH=/usr/bin:/usr/contrib/bin....


The first defines the correct shell to use for interpreting the script. The second line prevents spelling errors for variables by stopping the script. The third defines the PATH required for this script. You add only the paths needed for your script. This PATH only exists inside your script. You can hardcode full pathnames in your scripts but it is a lot of extra work -- that's why defining PATH locally makes more sense. Additionally, PATH is a potential security risk so your scripts should never use the currently defined PATH value.

You also look at your required environment variables. To see what is currently defined, use the env command, then pick the ones needed by your script.


Bill Hassell, sysadmin
Andrew Huizenga
Occasional Advisor

Re: Executing a Remote Shell Script

Thanks!