how to use ssh ?

I wrote a shell script "A" which will invoke any shell script "B".

I have both script "A" and "B" on /tmp/test directory of the machine M2

On machine M1,

I do a

ssh M2 "cd /tmp; ls -l"
I see A and B from the list output

However, if I

ssh M2 "cd /tmp; A"
I got a message
/tmp/A[5]:B: not found

It seem that I was successfully cd to /tmp on M2 and executing A on /tmp but it doesn't find B.

Why is that? What should I do to execute A on the directory that I cd to on the remote host?

Thanks!
xewooxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
is B in $PATH on  M2?
0
michofreihaCommented:
try to put the full path of B in A and check
0
TintinCommented:
In script A, put

./B

or

/tmp/B

when you call the second script.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

woolmilkporcCommented:
ssh M2 "export PATH=/tmp ; A"

0
woolmilkporcCommented:
Hi again,
now that it's morning again in old Europe, here some explanations -
1. Your test above does only work because you have the dot ('.' = current directory) in your standard path, probably set in /etc/environment (AIX) or /etc/profile.This is not recommended, as some attacker could place a faked executable (e.g. 'ls') into a directory which is known to be often used as the current one, e.g. your homedir, and do some harmful things with it. If you need the dot in your path, at least take care to place it there as the last element.
 
2. The 'cd /tmp' in your example does work because the subshell for script 'A' is started from the same shell as the 'cd' (see the 'dot' thing above). This shell, however, does not inherit this environment and thus can't find 'B', as its current directory is by default  your home directory.
 
3. My solution works because we set the environment variable 'PATH' there which is recognized by script 'A'  and so, as the shell evaluates PATH to find executables, 'A' can find and execute 'B'
 
Many words, but I hope I could make things a bit clearer.
 
wmp
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
xewooxAuthor Commented:
Thank you
0
xewooxAuthor Commented:
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.