Reputation: 1954
I'm running a server and needs to execute following command with the parameters. The scripts works great at the moment but the problem is when I run the script I cannot return back to the console. It keeps running in the console. If I stop it forcefully then the the process also going to stop.
I want to keep running the process and return to the console.
#!/bin/sh
php /home/stjc/app/artisan queue:listen --timeout=60 --tries=5
Thanks
Upvotes: 6
Views: 11531
Reputation: 157
One more option is there to send process in background as explained below:
Run script OR command you wish to run: For example
girishp@~$ ping 10.137.108.192
PING 10.137.108.192 (10.137.108.192) 56(84) bytes of data.
64 bytes from 10.137.108.192: icmp_seq=1 ttl=64 time=7.18 ms
64 bytes from 10.137.108.192: icmp_seq=2 ttl=64 time=0.367 ms
Press Ctrl+Z while command is running, It will stop running
^Z
[1]+ Stopped ping 10.137.108.192
type bg
in terminal to resume execution in background
girishp@~$ bg
[1]+ ping 10.137.108.192 &
girishp@~$ 64 bytes from 10.137.108.192: icmp_seq=5 ttl=64 time=5.46 ms
64 bytes from 10.137.108.192: icmp_seq=6 ttl=64 time=4.56 ms
You can again run it in foreground by typing fg
in terminal:
girishp@~$fg
ping 10.137.108.192
64 bytes from 10.137.108.192: icmp_seq=22 ttl=64 time=0.397 ms
64 bytes from 10.137.108.192: icmp_seq=23 ttl=64 time=3.99 ms
(...)
Upvotes: 1
Reputation: 48794
You can use an &
at the end of your command to run a process in the background, or the nohup
command to disconnect a process from your terminal entirely so that it continues running even after you exit the shell.
The error : command not found
is a separate problem. The text before the :
is a command that the environment couldn't find. Since there's nothing before the :
you're trying to start a command consisting of the empty string; here's an example:
$ foo
-bash: foo: command not found
$ ''
-bash: : command not found
Likely this is because you have a miss-set variable that you're using as a command, and therefore something is trying to to execute the empty-string command (which, of course, doesn't exist).
Upvotes: 1
Reputation: 1526
Run that process in background:
#!/bin/sh
(php /home/stjc/app/artisan queue:listen --timeout=60 --tries=5) &
try adding an ampersand(&
) at the end with brackets on either side of original command.
Edit:
:
is a shell builtin which means NOP depending on your OS it might a problem try escaping the it in the php command and see if it works for you
#!/bin/sh
(php /home/stjc/app/artisan queue\:listen --timeout=60 --tries=5) &
also puting the full path to your php
interpreter is strongly advised.
Upvotes: 5
Reputation: 53
Just append &
after your command and the shell will run the job in the backend.It will returns something like:[1] 3633.[1]
means shell job id, and 3633
means OS process id. If you want to stop the task, just simply type kill 3633
.
#!/bin/sh
php /home/stjc/app/artisan queue:listen --timeout=60 --tries=5 &
Upvotes: 1