Score:-1

Nohup to run multiple PHP scripts

bf flag
Tom

I have about 5 different PHP scripts that must be run by the server continuously even with the terminal closed.

How do I run the 5 scripts once via nohup, each with a log of what it generated, and be able to close the terminal?

I tried to run the script below and an error occurs.

sudo nohup php send-mail.php > mail.txt
-bash: mail.txt: Permission denied

nohup php send-mail.php > sudo mail.txt
-bash: sudo: Permission denied
vidarlo avatar
ar flag
In short, you should look into running at as a systemd service. Regarding the permission denied you get... You have to read up on how redirects work. The file is opened in the context of your user, because the *shell* opens it, not sudo. This is *basic* Unix shell know-how.
Score:0
us flag

There are two parts in your question.

  1. Permission denied case: which you may write the logs in a path which your regular user doesn't have write permissions to the root directory.
  2. Running scripts when terminal is closed: To run the five PHP scripts continuously with nohup and generate log files for each script, you can use the following commands:
nohup php /path/to/script1.php > ~/script1.log 2>&1 &
nohup php /path/to/script2.php > ~/script2.log 2>&1 &
nohup php /path/to/script3.php > ~/script3.log 2>&1 &
nohup php /path/to/script4.php > ~/script4.log 2>&1 &
nohup php /path/to/script5.php > ~/script5.log 2>&1 &
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.