problem using ssh

Hi,

I have 2 users say user a and user b both in different unix boxes.

I thave to execute a script in user b via user a.

I tried using ssh for it but my script is not getting executed.

My script goes as:
from user a-
ssh userb@host " sh script.sh"
script.sh is placed in user b only.

Can anyone help me out here??

Thanks in advance...

It looks like it should be working. I gave it a try with two machines I have, and it worked. I tried it with and without the quotation marks, and also by making the file executable and adding a shebang line instead of calling the shell first. Every combination worked. It's kind of a dumb question, but have you tried "bash" instead of "sh"?

Does it work if you log into the other server and manually run the file with "sh filename"?

Hi,
Yes the script does gets executed when logged on from another server

I tried to debug the problem and i got the following error.

MY script :
ssh2 -d -l -n o2oenv8@10.40.6.172 "sh test4.sh"

Debug error

debug: Connecting to 10.40.6.172, port 22... (SOCKS not used)
debug: client supports 3 auth methods: 'publickey,keyboard-interactive,password'
debug: Ssh2Common/sshcommon.c:496: local ip = 10.40.6.172, local port = 61722
debug: Ssh2Common/sshcommon.c:498: remote ip = 10.40.6.172, remote port = 22
debug: Remote version: SSH-2.0-ReflectionForSecureIT_6.1.0.16
debug: Remote host key found from database.
debug: server offers auth methods 'publickey,password'.
debug: Constructing and sending signature in publickey authentication.
debug: Ssh2AuthPubKeyClient/authc-pubkey.c:1615: Public key authentication was successful.
Authentication successful.
debug: Requesting X11 forwarding with authentication spoofing.
rcmd: -l: Unknown host

test4.sh[9]: test: Specify a parameter with this command.
rcmd: -l: Unknown host
test4.sh[18]: test: Specify a parameter with this command.
rcmd: -l: Unknown host
test4.sh[28]: test: Specify a parameter with this command.
test4.sh[35]: test3.sh: not found.
debug: Got session close with exit_status=1

Can anyone help me out here??

Thanks in advance...

Is the question I asked unanswerable?? Or is it too simple??

Can anyone help??

What have you looked at, after reading those error messages you posted? Notice that you're getting multiple errors in your script when trying to run something called "test."

Also, are you attempting to run something that is graphical? I see something in the comments regarding X forwarding, but I don't see the -X or -Y flag in your command. Do "man ssh" to see which of those options you have available, and figure out if you need them for what you are doing.

Hi,
Try this:
1) add user a on the .ssh for ssh without password
2) ssh you@host << EOF
./script
EOF

Let me know if it's work.

It seems your test4.sh on 10.40.6.172, doesn't know the host you are trying to get to. So your login is successful, but the remote execution is broke.

Hi All ,

Thanks for the replies.

I would like to answer each one of them individually.

@Tom de
Hi,the weirdness of the problem is that the script is getting executed when logging on from the environment B ,and is not getting executed when called remotely from server A.
If it is getting executed when logging on from the server B ,then why it si not identifying the script when called remotely?? Weird ,isn't it??

@ mehrdad68
Hi, I already tried using here document ,but to no awail.
My script goes in an indefinite loop and command prompt never returns back while executing this logic.

@ ShawnMilo

Hi, I am not running anything graphical.
The script that is being run just checks the diskspace of the system and informs the user if the threshold increases.

I hope I have made myself clear.

Could anyone guide me now towards the solution of this problem??

Many Thanks.

Taran

Sorry I shoulda looked closer:

This means two things are happening; your '-l' option isn't used correctly. '-l' needs a login name:

man ssh 
-l login_name
         Specifies the user to log in as on the remote machine.  This also
         may be specified on a per-host basis in the configuration file.

So, you get:

...
rcmd: -l: Unknown host
...

This can probably be ignored, it's not your problem - as the rest of this works. But maybe clean it up. SSH thinks '-l' is a host.

Now, the second part is:

test4.sh[9]: test: Specify a parameter with this command.
test4.sh[18]: test: Specify a parameter with this command.
test4.sh[28]: test: Specify a parameter with this command.
test4.sh[35]: test3.sh:  not found.

( I removed the "rcmd: -l: Unknown host" error, as it's a different problem)

Above your problem is in "test4.sh" you are executing a 'test' function. Either the word 'test' or something like 'if (-d file.sh)'. For whatever reason, you are trying to use a shell 'test' in way that requires a parameter see lines 9, 18, 28. And then on line 35 your script is looking for test3.sh.

Now, this could be because b's environment is setup to see all of the files
( maybe a path issue, maybe environment variables point to files ), and a's environment isn't setup to see the same paths/env-vars.

You can test this by putting the full path to a file in 'test4.sh'. Or investigating b's environment vs. a's.

maybe put up 'test4.sh' so we can see what its trying to do.

Tom de

Hi,

My script in server B just do the same thing as it does in server A i.e check the quota of the system.

There is no need to enter any path as I am using remsh command to connect with the server.

Anyways I am hereby attaching both test4 and test3 for debugging purpose.

Hope you could help me in rectifying the error.

Thanks

I've highlighted where you errors happen, and added the errors you posted before.

#!/bin/bash 
 
remsh $HOST -l $TLG_USR_ID -n "quota -v" > fill4 
size=`awk 'NR==3 {print $2}' fill4` 
  

rcmd: -l: Unknown host

echo $size 
  
a=370000 
if [ $size  -ge $a ] ;  then 

test4.sh[9]: test: Specify a parameter with this command.

echo "quota of  your application environment has increased  ,kindly delete the unwanted files " 
#else 
#echo " quota is lessss,u can continue" 
fi 
 
remsh $HOST -l $TLG_RATER_USR_ID -n "quota -v" > fill3 

rcmd: -l: Unknown host

 
size1=`awk 'NR==3 {print $2}' fill3` 
if [ $size1 -ge $a ] ; then 
echo "quota of your rater environment has increased,kindly delete the unwanted files"  

test4.sh[18]: test: Specify a parameter with this command.

#else 
#echo " quota is lessss,u can continue" 
fi 
 
export TUXEDO_USR_ID=`basename $TUX_HOME` 
remsh $HOST -l $TUXEDO_USR_ID -n "quota -v" > fill2 

rcmd: -l: Unknown host

 
size2=`awk 'NR==3 {print $2}' fill2` 
if [ $size2 -ge $a ] ; then 
echo "quota of your tuxedo environment has increased ,kindly delete the unwanted files " 

test4.sh[28]: test: Specify a parameter with this command.

#else 
#echo " quota is lessss,u can continue" 
 
fi  
 
. taran_test1 
 
 

test4.sh[35]: test3.sh: not found. <--- path problem!

Having the script helps, as we don't have to guess at what is happening. Simply put your variables aren't working. $HOST, $a, and probably $TLG_USR_ID.

I'll assume 'taran_test1' has the var's we need, but we aren't getting the vars. Investigate taran_test1 for more clues.

Tom de

Hi Tom,Appreciate your help in this regard.But I am unable to understand if the variables are working when run from server B ,then wy they are not working when called from server A.As fara s taran_test1 goes,it should be test3.sh.I just forgot to rename the variable.Hope i am making myself clear??Kindly advise..Many ThanksTaran