0

I am trying to run a perpetual script (data-csv.sh) in a server over ssh. I echo the pid created to a file so to have the pid and be able to kill the process at a later stage

ssh -o StrictHostKeyChecking=no 10.0.0.1 '~/data/data-csv.sh > ~/data/hostname.csv & echo $! > ~/data/pid.log'

The above hangs. Although in the server the process is started and the pid log is created the ssh is hanging

Even like this

ssh -o StrictHostKeyChecking=no 10.0.0.1 '~/data/data-csv.sh > ~/data/hostname.csv &'

it still hangs.

Also the server doesn't accept -t. The connection is closed if you try with -t

Any ideas on that?

joshmeranda
  • 3,001
  • 2
  • 10
  • 24
A D
  • 79
  • 1
  • 10
  • Of course it waits for the subprocess to exit. It started a subprocess with a handle on its stdin and stderr and that subprocess hasn't closed those handles. – Charles Duffy Oct 03 '21 at 14:03
  • 1
    If you want your subprocess to be properly detached, redirect its stdin, stdout and stderr elsewhere. Right now only stdout is redirected. – Charles Duffy Oct 03 '21 at 14:04
  • BTW, why use a hostname in a filename if the file is stored on the named host? Or is there a network filesystem in use here so every system shares the same `~/data`? – Charles Duffy Oct 03 '21 at 14:07
  • Thanks @CharlesDuffy. Redirected the stderr and now works fine. The hostname I want it because I sent the script to many different nodes and then I fetch the results from all of them, so I need to differentiate the results – A D Oct 03 '21 at 15:31
  • Sure, but you _could_ use the hostname-specific filenames only in the fetch phase as opposed to the generation phase; that way they could have a more meaningful name earlier (`yourscript.csv`, f/e, letting someone seeing the file know what it's for). – Charles Duffy Oct 03 '21 at 15:58
  • BTW, I would also suggest making ` – Charles Duffy Oct 03 '21 at 16:18

0 Answers0