Help with fetching the data from remote machine from my jumpbox(local machine)

Team,

Presently i am running a script from my local box(i.e jumpbox) to all the remote machines.Basically fetching basic queries like pwd,mkdir,touch etc and i am able to successfully fetch it from my local machine.But when i want to check certain database related queries like the dbstat command,calling particular shell script on the remote server from my local machine i am not able to fetch it.it says path and directory not found.

from my local machine i fetch the below command

ssh <remote machine name> 'bash-s' < 'my script' 

content of my script as below

#/bin/bash
echo "++check the pwd directory++"
pwd
echo "+++ swith to user abc+++"
sudo su - abc
echo "+++ execute the script as user abc+++"
/home/abc/xyz.sh
echo "+++ check the db status as user abc+++"
dbstat

Unfortunately i am unable to fetch the details for the database status and the shell script executed on the remote machine.Hence need you kind assistance.

Regards
Whizkid

What's the remote user's PATH on the remote machine?

the remote user path is a below

/opt/smp/bin/admintools:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/scfcm/bin:/opt/app/workload/perf

When you sudo su - abc , do you get prompted for a password?
Would ./home/abc/xyz.sh work?

Hi Junior,

When you sudo su - abc , do you get prompted for a password?
No, I am already logged in, it does not prompt me.

Would ./home/abc/xyz.sh work?
No

Between, all the above commands are run from external box(jumpbox)

Hi Whizkid,
yes, your logged in on the remote machine, but with the same user as on your jumpbox, right?
Check this with the whoami command before or after the pwd command in "my script".

With su - abc you (want to) become another user, namely abc.
Usually one needs to provide a password for the new user, unless you run the su command with root user.

I suggest to place the whoami command between su - abc and /home/abc/xyz.sh , so you can see if the su command was successful.

This may ease further troubleshooting...

Hope this helps.

Hi Junior,

I am already logged in with user abc..but have difficulties running scripts (ending with .sh) or any database commands like (dbstat) from external system.

Rest all are meeting my expectations

Regards
Whizkid

@whizkidash

This may be your problem, highlighted in red, I tested your command and it works on RHEL6.

ssh <remote machine name> 'bash-s' < 'my script' 

Remove the space between the hand dash 'bash -s'

jaysunn

@ Jaysunn

There seems to be typo error on my earlier code.
Yes i do mention a space between the [bash -s] code.but still the problem persist

Not sure I got you right: if logged in interactively, can you issue the dbstat command? Does you PATH contain the path of dbstat ?

@ Rudy..
Hope you are asking me about the PATH @ remote server right ?

Yes i can directly do a

'dbstat'

command once i logged in the remote server directly. (steps as provided below)

ssh < remote server name>
sudo su - abc
dbstat

for the PATH at remote server is already provide in my earlier mail chain
Between I am trying to perform the above activity thru my jumpbox using the ssh

---------- Post updated at 07:17 AM ---------- Previous update was at 07:07 AM ----------

@Rudi..

Presently i am getting the below log for dbstat when i execute the script thr ssh(from my local machine(jump box) to remote server)

++checking dbstat++
-nologin[8]: dbstat: not found [No such file or directory]

So - is the PATH when logging in interactively the same as when running the script remotely? Can you issue the whereis dbstat command and post the result?

@Rudi...

below are the output when i manually checked in remote server

whereis dbstat

output is

dbstat:

With that in mind, are you sure you get a result when running dbstat ?

Yes...

I get a response from the remote server when i run dbstat..

Between the remote server is acting as a db & clustered db(i mean all in one)

What's the output of alias dbstat and/or type -a dbstat ?

below is the output

alias dbstat

dbstat=showDbSync

type -a dbstat

dbstat is an alias for showDbSync

Seems like the alias is undefined when you run the script...

ok.. so what will be the way around then.. ?

Define the alias in your script before using it. Or, call the aliased command itself.

1 Like