how can I run a command via ssh that will not be terminated while pressing Control+C

Status
Not open for further replies.

Apollo

Wizard
Joined
Jun 13, 2013
Messages
1,458
I am trying to run a shell script or command via ssh terminal and need to be able to prevent it from being terminated via the Control+C key.

Under GUI shell, I can have the following:

trap '' sigint && gstat

however if I run it under ssh, then I get the following message:
trap: Command not found
 

Apollo

Wizard
Joined
Jun 13, 2013
Messages
1,458
I was actually running the script in tmux but got messed-up with the shortcut key and I pressed Ctrl+C key.
It killed the script within tmux.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
I was actually running the script in tmux but got messed-up with the shortcut key and I pressed Ctrl+C key.
It killed the script within tmux.
I hate when I do that.. and I do that too often. :(
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
You can also do this with '&' to run the command in the background and 'nohup' to detach the command from the current session so it doesn't die if you logout.

As in: nohup command &

You'll need to redirect the output of the command to a file so you can actually monitor what the command is up to. It's easier to just run tmux and be careful with your keys.
 

Apollo

Wizard
Joined
Jun 13, 2013
Messages
1,458
I'll try this one later, but it would be more practical and more user friendly if the primary key binding of tmux were always displayed as a tab menu or something, rather than guessing.
 

Duncan

Cadet
Joined
Nov 22, 2014
Messages
3
You could always use screen. Start your command, then detach your screen. Come back later and reattach the screen.

Start: screen
Detach: Ctrl+a then d
Reattach: screen -r
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
tmux is a newer, better screen.

Start: tmux
Detach: Ctrl+b then d
Reattach: tux attach

You can even change the control character to 'a' so it matches screen. (I always used 'n' on both)
 

Apollo

Wizard
Joined
Jun 13, 2013
Messages
1,458
tmux is a newer, better screen.

Start: tmux
Detach: Ctrl+b then d
Reattach: tux attach

You can even change the control character to 'a' so it matches screen. (I always used 'n' on both)

The problem with tmux is that there is now help available unless you type Ctrl+b. That day I was confused and pressed the Ctrl+C and this cause the command within tmux to be canceled.
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
I don't think there's any solution for PEBKAC errors.
 

Apollo

Wizard
Joined
Jun 13, 2013
Messages
1,458
I don't think there's any solution for PEBKAC errors.

This is why the following becomes handy:
Code:
trap '' sigint && gstat


but this doesn't work over ssh as the "trap " command is not found.
 
Status
Not open for further replies.
Top