imthekrish Respected Contributor.
Respected Contributor.
4228 views

Using nohup in a shell script - SSH command hangup

Jump to solution

I have a script which run "nohup command &" which basically runs a watchdog process in background and there are other step after this in the script ...... I executed that script using SSH command with timeout 10 mins. SSH commands run upto nohup steps and then wait for it to end and after 10 mins it timeout(as specified in operation).  Not sure if its because of the nohup command. IS there any other operations that I can use ? Or I there other way to skip nohup command and move on to next step in the shell script.

Operation full path in Base cp:: /Base [1.10.0]/Library/Operations/Remote Command Execution/SSH/v1.0/SSH Command  

0 Likes
1 Solution

Accepted Solutions
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: Using nohup in a shell script - SSH command hangup

Jump to solution

and on top of Chris's mentions you could consider the SSH Shell and the v2 operations.

/Base [1.10.0]/Library/Operations/Remote Command Execution/SSH/v2.0/SSH Shell

Note: The operation should always be used as a set like  [SSH Shell Logon] -> [SSH Shell] -> [SSH Shell Logoff] 

when using the nohup you might also expect some regex for the process id that comes afterwards..

Hope it helps,

Andrei Vasile Truta
0 Likes
7 Replies
imthekrish Respected Contributor.
Respected Contributor.

Re: Using nohup in a shell script - SSH command hangup

Jump to solution

@VladM any suggestions

0 Likes
Outstanding Contributor.. csaunderson Outstanding Contributor..
Outstanding Contributor..

Re: Using nohup in a shell script - SSH command hangup

Jump to solution

This is really a shell scripting problem. Some quick googling and it looks like what you really need to do is make sure that your nohup'ed command is not behaving in regards to file descriptors.

 

Take a look here:

 

https://stackoverflow.com/questions/29709790/scripts-with-nohup-inside-dont-exit-correctly

--Chris

0 Likes
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: Using nohup in a shell script - SSH command hangup

Jump to solution

and on top of Chris's mentions you could consider the SSH Shell and the v2 operations.

/Base [1.10.0]/Library/Operations/Remote Command Execution/SSH/v2.0/SSH Shell

Note: The operation should always be used as a set like  [SSH Shell Logon] -> [SSH Shell] -> [SSH Shell Logoff] 

when using the nohup you might also expect some regex for the process id that comes afterwards..

Hope it helps,

Andrei Vasile Truta
0 Likes
imthekrish Respected Contributor.
Respected Contributor.

Re: Using nohup in a shell script - SSH command hangup

Jump to solution

Thank you both @AndreiTruta and @csaunderson.

The script has a command to wait for some time until everything is shutdown or startup. My SSH SHELL is not executing anything after that wait and exits. 

0 Likes
imthekrish Respected Contributor.
Respected Contributor.

Re: Using nohup in a shell script - SSH command hangup

Jump to solution

This work just by adding one more expect for prompt. Operation waited until it got the next prompt.

Problem here is with the exit code or return code. I gave a command echo $PATH and eho $PATH i get return code 0 for both. SHouldnt i get non zero return code for second one ?

0 Likes
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: Using nohup in a shell script - SSH command hangup

Jump to solution

In regard to the return code - it sounds as something that needs to be improved.

I see you opened another thread. let's track it there - https://community.saas.hpe.com/t5/Operations-Orchestration/Return-code-SSH-SHELL-operation/m-p/1611007#M3603

Andrei Vasile Truta
0 Likes
imthekrish Respected Contributor.
Respected Contributor.

Re: Using nohup in a shell script - SSH command hangup

Jump to solution

Thanks @AndreiTruta .... Yes I have another thread.. Its strange that the real exit code is not even returned in the response

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.