Instead of reading in
STDOUT of
`ssh`, redirect the output to a file:
$backup_command = "backup.pl >! output123.txt";
Also, when "killing" the process, you may wish to send a
SIGTERM first before
SIGKILL (like
kill -9). This gives your
$backup_command a change to catch and handle the signal to end its operation (i.e., flushing out its output buffer).
See
perlipc on how to catch signals.
See
Suffering from Buffering on how to flush output.