When you run a command with nohup
, the stdin
is redirected from /dev/null
. So you cannot use nohup
and manually enter a password.
Depending up on the program that you're using, you can use redirections to enter the password:
$ nohup bash -c 'read; echo $REPLY' <<<'hello'
$ tail -1 nohup.out
hello
So you could save your password in a file (say password.txt
), and encrypt it using something like gpg
with a password-protected private key (to get password.txt.gpg
), and do:
gpg -d password.txt.gpg | nohup php hat
Or, you could use something like screen
.
First start a screen
session (this command actually either starts a session named my-php-script-session
, or brings one that is already running to the foreground):
screen -D -RR -S my-php-script-session
Then in the shell that opens, run your command normally:
php hat
Enter your password, and then detach the screen
session: Ctrla, followed by d.
You can re-attach it by running the first screen
command again.