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?

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.

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




when you call the second script.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

ssh M2 "export PATH=/tmp ; A"

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.

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
xewooxAuthor Commented:
Thank you
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.