Search code examples
shellsshterminalzsh

running ssh process in background gets paused


I have some scripts that I'm developing on a vm but sometimes needs to run on a production server to be properly tested.

I need the output from the scripts for debugging so I've tinkered together the following solution:

function test_remote() {
    scp $1 Prod:/home/xxx/tmp/
    n=${1:t:r}
    f=${1:t}
    cmd="ssh Prod \"/usr/bin/php /home/xxx/tmp/$f\" > /home/xxx/tests/$n-remote-test.html"
    eval ${cmd}
    ssh Prod "rm /home/xxx/tmp/$f"
    echo "done"
}

which I have placed in my .zshrc file

I would like to run it in the background using

test_remote path_to_file/php_file.php &

but as I do I always get the following result

[1]  + 12996 suspended (tty input)  test_remote path_to_file/php_file.php

if I resume it with bg it just repeats the same message


Solution

  • When a background process attempts to read from standard input, it is sent a signal which suspends it. This is so the user can bring the process to the foreground again and provide the necessary input.

    If no input needs to be provided, you can redirect the standard input from /dev/null, either when calling test_remote or in cmd.