# problem using ssh

**URL:** <https://community.unix.com/t/problem-using-ssh/233207>\
**Category:** Shell Programming and Scripting\
**Created:** [February 26, 2009, 11:01am UTC](https://community.unix.com/t/problem-using-ssh/233207 "2009-02-26T11:01:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taranjeet\_Singh](https://community.unix.com/letter_avatar/taranjeet_singh/32/5_5575768a8748004e209b776fc1b2916d.png) [@Taranjeet\_Singh](https://community.unix.com/u/Taranjeet_Singh)\
**Post date:** [February 26, 2009, 11:01am UTC](https://community.unix.com/t/problem-using-ssh/233207/1 "2009-02-26T11:01:39Z")

</div>

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](mailto:userb@host) " sh script.sh"  
script.sh is placed in user b only.

Can anyone help me out here??

Thanks in advance...

---

<div class="post-metadata">

**Author:** ![ShawnMilo](https://community.unix.com/user_avatar/community.unix.com/shawnmilo/32/3304_2.png) [@ShawnMilo](https://community.unix.com/u/ShawnMilo)\
**Post date:** [February 26, 2009, 2:31pm UTC](https://community.unix.com/t/problem-using-ssh/233207/2 "2009-02-26T14:31:49Z")

</div>

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"?

---

<div class="post-metadata">

**Author:** ![Taranjeet\_Singh](https://community.unix.com/letter_avatar/taranjeet_singh/32/5_5575768a8748004e209b776fc1b2916d.png) [@Taranjeet\_Singh](https://community.unix.com/u/Taranjeet_Singh)\
**Post date:** [February 27, 2009, 5:52am UTC](https://community.unix.com/t/problem-using-ssh/233207/3 "2009-02-27T05:52:55Z")

</div>

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](mailto: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...

---

<div class="post-metadata">

**Author:** ![Taranjeet\_Singh](https://community.unix.com/letter_avatar/taranjeet_singh/32/5_5575768a8748004e209b776fc1b2916d.png) [@Taranjeet\_Singh](https://community.unix.com/u/Taranjeet_Singh)\
**Post date:** [March 2, 2009, 1:55am UTC](https://community.unix.com/t/problem-using-ssh/233207/4 "2009-03-02T01:55:07Z")

</div>

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

Can anyone help??

---

<div class="post-metadata">

**Author:** ![ShawnMilo](https://community.unix.com/user_avatar/community.unix.com/shawnmilo/32/3304_2.png) [@ShawnMilo](https://community.unix.com/u/ShawnMilo)\
**Post date:** [March 2, 2009, 7:10am UTC](https://community.unix.com/t/problem-using-ssh/233207/5 "2009-03-02T07:10:27Z")

</div>

> [@taranjeet singh](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![mehrdad68](https://community.unix.com/letter_avatar/mehrdad68/32/5_5575768a8748004e209b776fc1b2916d.png) [@mehrdad68](https://community.unix.com/u/mehrdad68)\
**Post date:** [March 2, 2009, 7:30am UTC](https://community.unix.com/t/problem-using-ssh/233207/6 "2009-03-02T07:30:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tom\_de](https://community.unix.com/letter_avatar/tom_de/32/5_5575768a8748004e209b776fc1b2916d.png) [@Tom\_de](https://community.unix.com/u/Tom_de)\
**Post date:** [March 2, 2009, 8:48am UTC](https://community.unix.com/t/problem-using-ssh/233207/7 "2009-03-02T08:48:08Z")

</div>

> [@taranjeet singh](#):
>
> 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](mailto: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...

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.

---

<div class="post-metadata">

**Author:** ![Taranjeet\_Singh](https://community.unix.com/letter_avatar/taranjeet_singh/32/5_5575768a8748004e209b776fc1b2916d.png) [@Taranjeet\_Singh](https://community.unix.com/u/Taranjeet_Singh)\
**Post date:** [March 2, 2009, 9:31am UTC](https://community.unix.com/t/problem-using-ssh/233207/8 "2009-03-02T09:31:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tom\_de](https://community.unix.com/letter_avatar/tom_de/32/5_5575768a8748004e209b776fc1b2916d.png) [@Tom\_de](https://community.unix.com/u/Tom_de)\
**Post date:** [March 2, 2009, 1:50pm UTC](https://community.unix.com/t/problem-using-ssh/233207/9 "2009-03-02T13:50:49Z")

</div>

Sorry I shoulda looked closer:

> [@taranjeet singh](#):
>
> 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](mailto: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...

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

```plaintext
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:

```plaintext
...
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:

```plaintext
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

---

<div class="post-metadata">

**Author:** ![Taranjeet\_Singh](https://community.unix.com/letter_avatar/taranjeet_singh/32/5_5575768a8748004e209b776fc1b2916d.png) [@Taranjeet\_Singh](https://community.unix.com/u/Taranjeet_Singh)\
**Post date:** [March 2, 2009, 11:26pm UTC](https://community.unix.com/t/problem-using-ssh/233207/10 "2009-03-02T23:26:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tom\_de](https://community.unix.com/letter_avatar/tom_de/32/5_5575768a8748004e209b776fc1b2916d.png) [@Tom\_de](https://community.unix.com/u/Tom_de)\
**Post date:** [March 3, 2009, 7:59am UTC](https://community.unix.com/t/problem-using-ssh/233207/11 "2009-03-03T07:59:12Z")

</div>

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

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

```

rcmd: -l: Unknown host

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

```

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

```nohighlight
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

```nohighlight
 
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.

```nohighlight
#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

```nohighlight
 
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.

```nohighlight
#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

---

<div class="post-metadata">

**Author:** ![Taranjeet\_Singh](https://community.unix.com/letter_avatar/taranjeet_singh/32/5_5575768a8748004e209b776fc1b2916d.png) [@Taranjeet\_Singh](https://community.unix.com/u/Taranjeet_Singh)\
**Post date:** [March 3, 2009, 11:00pm UTC](https://community.unix.com/t/problem-using-ssh/233207/12 "2009-03-03T23:00:07Z")

</div>

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
