0

I am trying to connect the remote ssh server via ruby using Net::SSH.It is working fine for me for all the commands provided via script and i could able to read the output of the command successfully. But when i use the below command it is getting stuck in SSH.exec!(cmd) and control is not returned from the line. Only if i click Ctrl+c in command line the script is getting ended. The command is ./wcsadmin.sh start --> this is used to start the processes of my application in remote server

Please find the below code snippet of my ruby script:

Net::SSH.start(host, username, :password => password) do |ssh|
puts 'before exit'
output = ssh.exec!(/opt/wcsadmin.sh start)
puts 'Executed command'

The output of the command when i do it manually is :

[root@test bin]# ./wcsadmin.sh start

Starting Network Control System...

This may take a few minutes... stty: standard input: Invalid argument

Network Control System started successfully.

Starting SAM daemon... Done. Starting DA daemon... Starting DA syslog daemon... start

if i use ssh.exec('./wcsadmin.sh start') the only difference is the above output is getting printed but still the program is never ended.I need to manually end it by hitting ctrl+c. When i searched in google i could find you can use

nohup command('nohup /opt/wcsadmin.sh start >/tmp/teststartserver.log 2>&1')

to skip the hangup signals and tried the same.This also writes the output to teststartserver.log but getting hanged.Can anyone please help me out on this issue?

Thanks in Advance!

Thanks, Meena

1 Answer 1

0

If the command itself doesn't return right away, then SSH.exec! will block further execution until the command returns. If for some reason you lose remote contact, then SSH.exec! may not know that you have lost connectivity and it will continue to block.

You could try putting the command in the background:

output = ssh.exec!('/opt/wcsadmin.sh start &')

Or maybe look at the documentation on that command and maybe it has some sort of --no-wait option that will allow it to return immediately, even if it is still working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.