Operating System - HP-UX
1837882 Members
3384 Online
110122 Solutions
New Discussion

2 separated ssh questions

 
Hanry Zhou
Super Advisor

2 separated ssh questions

1. I have the following command:
ssh root@server_a "cmd1; cmd2; cmd3"
The command is successfuly completed the task on remote server server_a, however, the only problem is I dont get the prompt back on my local system. I have to hit "ctl-c" to get it back. why?

2. This question is not related above problem. In my another separated ssh command:
ssh root@server_b "/full/nameot/xyz -f"
xyz is my own script and can have "-f" option. Also xyz script would also produce two output files on the remote server. However, the script was not actually executed, and no any output files were produced. Why?

Thanks,
none
13 REPLIES 13
Mel Burslan
Honored Contributor

Re: 2 separated ssh questions

the answer to the first question is pretty straightforward and simple, though I can not tell you how to correct it without knowing what cmd1, 2 and 3 are. Obviously your cmd3 most probably do not exit properly, or cmd1 or cmd2 do not complete successfully to yield cmd3 to complete and return.

fir the second question, do you get your prompt back after your xyz script looked like it ran fine ? If so, place a set -x at the top of your script on the remote server and see if your script gets entered into or is it just denying you the ssh login as root.

when you talk about root login via remote commands, it is always tricky as more than one thing can go wrong to deny access.

________________________________
UNIX because I majored in cryptology...
Geoff Wild
Honored Contributor

Re: 2 separated ssh questions

Instead on cmd1; cmd2; cmd3 why not put all those commands in a single script, if it still doesn't return - put a set -x to see what is going on.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Steven E. Protter
Exalted Contributor

Re: 2 separated ssh questions

In the recommended target script

set -x

That will give you details

Also run the ssh with the -v switch. This will give you a better idea of whats going on.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Hanry Zhou
Super Advisor

Re: 2 separated ssh questions

Well, basically, cmd1 is to change a parameter in the script, and cmd2 to stop the script, and cmd3 is to start the script.
all cmd's works file on the local system, and again, they are all completed fine when I put them in the ssh command. The only problem is I could not get the prompt back when I run the ssh on the local, and run cmd1, 2, and 3 remotely on the remote server.

I did put "set -x" in front of cmd1, and did not find anything unusal.

Is there any option in ssh and it could force the ssh to be terminated?


With regards my 2nd question, again, the script doesn't seem to every started at all.


none
Hanry Zhou
Super Advisor

Re: 2 separated ssh questions

SEP,

when I add -v in ssh command, the last line is shown on the screen is the folloing:
"debug: client_input_channel_req: channel 0 rtype exit-status reply 0", and the cursor is just stop there, could not get the prompt back. Any idea, what is this message for?

As I repeatedly say, all cmd's in ssh were successful on the remote server.
none
Abdul Rahiman
Esteemed Contributor

Re: 2 separated ssh questions

Well, few things to check for in the case ssh remote connection is hanging.
First, does any command on the remote script run any jobs in the background ? That may be one of the reasons for this behaviour.

Also, what happens if you run the "ssh .." command with nohup. Do you still have the problem ?
Or try re-directing the output to >/dev/null 2&1
This openSSH FAQ might be helpful.
http://www.openssh.com/faq.html#3.10

regds,
abdul.
No unix, no fun
Hanry Zhou
Super Advisor

Re: 2 separated ssh questions

Adbul,

No, no any commads running in backgound on the rmote site. Also, the issue is existing when I run the ssh... on any servers.

The web site you are refering to doesn't help.


I know that sshd needs to tell the exit status from command to ssh, but the last command, cmd3 IS successful, and I thought that it'd be enough tell sshd "I'M DONE".
none
Abdul Rahiman
Esteemed Contributor

Re: 2 separated ssh questions

How's the behaviour on interactive sessions ?
Does it end normally ?
Is this something new.. ? may be restart sshd daemon..(windows solution;-)
Or update to a later version of openSSH ..

regds,
Abdul.
No unix, no fun
Hanry Zhou
Super Advisor

Re: 2 separated ssh questions

I've tried everyting suggested.

Any other idea?
none
Charles Harris
Super Advisor

Re: 2 separated ssh questions

it's going to be difficult to shed any more light without the specific's of the commands you are running / script details. You should also post the SSH client and server versions to see if there are any known issues with the versions you are running.

Does a normal ssh root@unknown "ls" exit properly?

How about running ssh root@unknown "cmd1 && cmd2 && cmd3" see if all scripts are run?

rgds,

-=ChaZ=-
Hanry Zhou
Super Advisor

Re: 2 separated ssh questions

okay, the following is the command I am running, and I have to hit cntl-c to get out of the command at the end, although all actions have been completed on the remote site:

ssh root@remotename "cp /etc/rc.config.d/nfsconf /etc/rc.config.d/nfsconf.orig && sed 's/AUTOMOUNT=1/AUTOMOUNT=0/' /etc/rc.config.d/nfsconf > /tmp/nfsconf && cp /tmp/nfsconf /etc/rc.config.d/nfsconf && /sbin/init.d/nfs.cleint stop && /sbin/init.d/nfs.cleint start"
none
Abdul Rahiman
Esteemed Contributor

Re: 2 separated ssh questions

Hanry,

Looking at the 'chain' of commands in the quotes, I would strongly recommend you to run the commands in a shell script than all in one command line.

This may work in a normal setting, but since you are having problems returning it with ssh, why don't you try making a shell script with all commands ina separate line and see what happens.
Your problem here may be due to Ssh confused with the syntax or not getting he correct return status in the way it xpected it.

regds,
Abdul.
No unix, no fun
Alzhy
Honored Contributor

Re: 2 separated ssh questions

Hanry,

Aha! I have stumbled onto this a number of times in the past.. it is still a "problem".

If you ssh to a server and execute a script of the like in the "/sbin/rc.?/xxx start/stop" .. after you log off that SSH connection , you WILL NEVER be brought back to your shell/terminal where you invoked ssh from...

Try it.. it happens with SSH distributions on HP and SUN.. I have not been able to explain such behaviour...

Hakuna Matata.