Skip to main content
added 141 characters in body
Source Link
IGGt
  • 2.6k
  • 9
  • 36
  • 48

I have a script which is composed of two parts. part1 creates an ssh connection, part2 runs a script (about 800 lines and counting so far).

part1:
ssh $target_server "bash -s" < $target_script

The problem is that part2 contains the following lines:

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }
. . .
fc_START_WINE_APP $applicationFull

Basically, it checks if an application is running, and if not restarts it (as well as some other stuff).

The problem is that, when the function is executed to start the application, it causes the ssh connection to hang.

Is there a way of forcing the ssh connection to exit when it gets to the end of the script.

I have tried exit, exit 0, exit 1 etc at the end of part2. I tried ssh -f in part1 but then part2 doesn't seem to execute.


UPDATE 2016-01-28

An example would be as follows

**SCRIPT1**
#!/bin/bash

target_server="1.2.3.4"
target_script="/home/user/script2.sh"

echo "Script 1 Started"

ssh $target_server "bash -s" < $target_script

echo "Script 1 Ended"

.

**SCRIPT 2**
#!/bin/bash

echo "Script 2 Started"

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }

applicationFull="/home/tech/myApp.exe"

fc_START_WINE_APP $applicationFull

echo "Script 2 Ended"

When running this It gets as far as Script 2 Ended, but doesn't close the ssh connection, and hence never gets as far Script 1 Ended.

As you can probably tell, the main point of the script is to connect to a given server, and start an (Old Windows) application using Wine.

My understanding is that it has to be started using nohup . . & to stop the application closing when the ssh connection is closed, in the same way that if I log in directly (using putty for instance), run nohup myCommand & and then exit, then myCommmand still runs.

I have a script which is composed of two parts. part1 creates an ssh connection, part2 runs a script (about 800 lines and counting so far).

part1:
ssh $target_server "bash -s" < $target_script

The problem is that part2 contains the following lines:

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }
. . .
fc_START_WINE_APP $applicationFull

Basically, it checks if an application is running, and if not restarts it (as well as some other stuff).

The problem is that, when the function is executed to start the application, it causes the ssh connection to hang.

Is there a way of forcing the ssh connection to exit when it gets to the end of the script.

I have tried exit, exit 0, exit 1 etc at the end of part2. I tried ssh -f in part1 but then part2 doesn't seem to execute.


UPDATE 2016-01-28

An example would be as follows

**SCRIPT1**
#!/bin/bash

target_server="1.2.3.4"
target_script="/home/user/script2.sh"

echo "Script 1 Started"

ssh $target_server "bash -s" < $target_script

echo "Script 1 Ended"

.

**SCRIPT 2**
#!/bin/bash

echo "Script 2 Started"

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }

applicationFull="/home/tech/myApp.exe"

fc_START_WINE_APP $applicationFull

echo "Script 2 Ended"

When running this It gets as far as Script 2 Ended, but doesn't close the ssh connection, and hence never gets as far Script 1 Ended.

As you can probably tell, the main point of the script is to connect to a given server, and start an (Old Windows) application using Wine.

My understanding is that it has to be started using nohup . . & to stop the application closing when the ssh connection is closed.

I have a script which is composed of two parts. part1 creates an ssh connection, part2 runs a script (about 800 lines and counting so far).

part1:
ssh $target_server "bash -s" < $target_script

The problem is that part2 contains the following lines:

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }
. . .
fc_START_WINE_APP $applicationFull

Basically, it checks if an application is running, and if not restarts it (as well as some other stuff).

The problem is that, when the function is executed to start the application, it causes the ssh connection to hang.

Is there a way of forcing the ssh connection to exit when it gets to the end of the script.

I have tried exit, exit 0, exit 1 etc at the end of part2. I tried ssh -f in part1 but then part2 doesn't seem to execute.


UPDATE 2016-01-28

An example would be as follows

**SCRIPT1**
#!/bin/bash

target_server="1.2.3.4"
target_script="/home/user/script2.sh"

echo "Script 1 Started"

ssh $target_server "bash -s" < $target_script

echo "Script 1 Ended"

.

**SCRIPT 2**
#!/bin/bash

echo "Script 2 Started"

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }

applicationFull="/home/tech/myApp.exe"

fc_START_WINE_APP $applicationFull

echo "Script 2 Ended"

When running this It gets as far as Script 2 Ended, but doesn't close the ssh connection, and hence never gets as far Script 1 Ended.

As you can probably tell, the main point of the script is to connect to a given server, and start an (Old Windows) application using Wine.

My understanding is that it has to be started using nohup . . & to stop the application closing when the ssh connection is closed, in the same way that if I log in directly (using putty for instance), run nohup myCommand & and then exit, then myCommmand still runs.

added 721 characters in body
Source Link
IGGt
  • 2.6k
  • 9
  • 36
  • 48

I have a script which is composed of two parts. part1 creates an ssh connection, part2 runs a script (about 800 lines and counting so far).

part1:
ssh $target_server "bash -s" < $target_script

The problem is that part2 contains the following lines:

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }
. . .
fc_START_WINE_APP $applicationFull

Basically, it checks if an application is running, and if not restarts it (as well as some other stuff).

The problem is that, when the function is executed to start the application, it causes the ssh connection to hang.

Is there a way of forcing the ssh connection to exit when it gets to the end of the script.

I have tried exit, exit 0, exit 1 etc at the end of part2. I tried ssh -f in part1 but then part2 doesn't seem to execute.


UPDATE 2016-01-28

An example would be as follows

**SCRIPT1**
#!/bin/bash

target_server="1.2.3.4"
target_script="/home/user/script2.sh"

echo "Script 1 Started"

ssh $target_server "bash -s" < $target_script

echo "Script 1 Ended"

.

**SCRIPT 2**
#!/bin/bash

echo "Script 2 Started"

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }

applicationFull="/home/tech/myApp.exe"

fc_START_WINE_APP $applicationFull

echo "Script 2 Ended"

When running this It gets as far as Script 2 Ended, but doesn't close the ssh connection, and hence never gets as far Script 1 Ended.

As you can probably tell, the main point of the script is to connect to a given server, and start an (Old Windows) application using Wine.

My understanding is that it has to be started using nohup . . & to stop the application closing when the ssh connection is closed.

I have a script which is composed of two parts. part1 creates an ssh connection, part2 runs a script (about 800 lines and counting so far).

part1:
ssh $target_server "bash -s" < $target_script

The problem is that part2 contains the following lines:

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }
. . .
fc_START_WINE_APP $applicationFull

Basically, it checks if an application is running, and if not restarts it (as well as some other stuff).

The problem is that, when the function is executed to start the application, it causes the ssh connection to hang.

Is there a way of forcing the ssh connection to exit when it gets to the end of the script.

I have tried exit, exit 0, exit 1 etc at the end of part2. I tried ssh -f in part1 but then part2 doesn't seem to execute.

I have a script which is composed of two parts. part1 creates an ssh connection, part2 runs a script (about 800 lines and counting so far).

part1:
ssh $target_server "bash -s" < $target_script

The problem is that part2 contains the following lines:

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }
. . .
fc_START_WINE_APP $applicationFull

Basically, it checks if an application is running, and if not restarts it (as well as some other stuff).

The problem is that, when the function is executed to start the application, it causes the ssh connection to hang.

Is there a way of forcing the ssh connection to exit when it gets to the end of the script.

I have tried exit, exit 0, exit 1 etc at the end of part2. I tried ssh -f in part1 but then part2 doesn't seem to execute.


UPDATE 2016-01-28

An example would be as follows

**SCRIPT1**
#!/bin/bash

target_server="1.2.3.4"
target_script="/home/user/script2.sh"

echo "Script 1 Started"

ssh $target_server "bash -s" < $target_script

echo "Script 1 Ended"

.

**SCRIPT 2**
#!/bin/bash

echo "Script 2 Started"

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }

applicationFull="/home/tech/myApp.exe"

fc_START_WINE_APP $applicationFull

echo "Script 2 Ended"

When running this It gets as far as Script 2 Ended, but doesn't close the ssh connection, and hence never gets as far Script 1 Ended.

As you can probably tell, the main point of the script is to connect to a given server, and start an (Old Windows) application using Wine.

My understanding is that it has to be started using nohup . . & to stop the application closing when the ssh connection is closed.

Source Link
IGGt
  • 2.6k
  • 9
  • 36
  • 48

How to force ssh connection to exit at end of script

I have a script which is composed of two parts. part1 creates an ssh connection, part2 runs a script (about 800 lines and counting so far).

part1:
ssh $target_server "bash -s" < $target_script

The problem is that part2 contains the following lines:

fc_START_WINE_APP () { nohup `DISPLAY=:11.0 wine "$1"` & }
. . .
fc_START_WINE_APP $applicationFull

Basically, it checks if an application is running, and if not restarts it (as well as some other stuff).

The problem is that, when the function is executed to start the application, it causes the ssh connection to hang.

Is there a way of forcing the ssh connection to exit when it gets to the end of the script.

I have tried exit, exit 0, exit 1 etc at the end of part2. I tried ssh -f in part1 but then part2 doesn't seem to execute.