• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

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!
0
xewoox
Asked:
xewoox
5 Solutions
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now