Hsko-Godol
Hsko-Godol

Reputation: 1

What's wrong about my script with "ssh + nohup"

I want to execute specific script at remote server by ssh in background.
I found some solution about nohup.
But, nohup is not running without "2>&1"

I want to know what's the difference between existing "2>&1" and not.
nohup needs "2>&1" expression?

(Please understand my bad English)

This is my 'iperf_server.sh' script.

iperf -s -p 1 -w 128K

And, It is my host machine command.

$ ssh [id]@[host] "nohup echo [password] | sudo -S [Home_dir]/iperf_server.sh > /dev/null &"

$ ssh [id]@[host] "nohup echo [password] | sudo -S [Home_dir]/iperf_server.sh > /dev/null 2>&1 &"

$ ssh -t [id]@[host] "nohup echo [password] | sudo -S [Home_dir]/iperf_server.sh > /dev/null &"
Connection to iperf-server closed.

$ ssh -t [id]@[host] "nohup echo [password] | sudo -S [Home_DIR]/iperf_server.sh > /dev/null 2>&1 &"
Connection to iperf-server closed.

This is ps command result in iperf server

# ps -eLf | grep iperf | grep -v grep

# ps -eLf | grep iperf | grep -v grep
  00:00:00 sudo -S [HOME_DIR]/iperf_server.sh
  00:00:00 sh [HOME_DIR]/iperf_server.sh
  00:00:00 iperf -s -p 1 -w 128K
  00:00:00 iperf -s -p 1 -w 128K
  00:00:00 iperf -s -p 1 -w 128K
# killall iperf

# ps -eLf | grep iperf | grep -v grep

# ps -eLf | grep iperf | grep -v grep

Upvotes: 0

Views: 356

Answers (1)

Bela Vizy
Bela Vizy

Reputation: 1164

Take the & off the end.

This should do it:

ssh -t [id]@[host] "nohup echo [password] | sudo -S [Home_dir]/iperf_server.sh > /dev/null 2>&1"

By the way this is a huge security risk. Don't echo the password on the command line! If you really want to use a password like this at least do something like cat pwd.txt | sudo -S instead.

Upvotes: 1

Related Questions