in reply to Net::OpenSSH and background process

If I change the command to this:
nohup /usr/sbin/tcpdump -i eth1 -s 1500 -w /tmp/tmp.pcap </dev/null >> +myLogFile 2>>myErrorFile&
The background tcpdump process works and stays alive. I'm assuming this is more easily done with a combination of open_ex options just not sure what they should be or if my thought process is correct...

Replies are listed 'Best First'.
Re^2: Net::OpenSSH and background process
by salva (Canon) on Aug 24, 2010 at 16:39 UTC
    nohup only does its redirection magic when stdin/stdout/stderr are connected to a tty, that's why you need to explicitly redirect these streams.

    Besides that, you can use Net::OpenSSH spawn method to launch the command in the background:

    # this code does not check for errors! my $pid = $ssh->spawn('/usr/sbin/tcpdump -i eth1 -s 1500 -w /tmp/tmp.p +cap'); ($out,$err) = $ssh->capture2('ping -I eth1 -c 3 192.168.107.254'); $ssh->system('killall tcpdump'); waitpid($pid, 0); ($out,$err) = $ssh->capture2('tcpdump -r /tmp/tmp.pcap'); print "THE OUT IS $out\nTHE ERROR IS $err\n";
      Thank you for the info and helpful example. I was able to get it working both ways with both spawn and the nohup as you suggested. I sincerely appreciate the help!!!