如何在后台逐个运行命令?

时间:2013-12-20 00:42:31

标签: linux bash ssh nohup

nohup php /home/www/api/24 > 24.out 2> 24.err < /dev/null
nohup php /home/www/api/27 > 27.out 2> 27.err < /dev/null
nohup php /home/www/api/19 > 27.out 2> 16.err < /dev/null

我需要进行几千个api调用,需要逐个完成,所以我不会通过Web调用充斥其他服务器。运行sh文件后,如何在不中断进程的情况下关闭终端,CTRL + Z?

3 个答案:

答案 0 :(得分:4)

您输入...

$ screen

...然后按Enter键。

运行命令或脚本。

按control-a,然后按d

然后你可以断开连接,注销,做任何事情......稍后回来查看脚本:

$ screen -r

然后你想知道如果没有它你会如何相处。

https://www.gnu.org/software/screen/

答案 1 :(得分:2)

将所有内容放入脚本中,然后使用nohup

运行该脚本
#!/bin/bash
for i in 24 27 19 ...
do
    php /home/www/api/$i > $i.out 2> $i.err
done

然后做:

nohup /path/to/script </dev/null >/dev/null 2>&1 &

答案 2 :(得分:1)

您还可以将batch(1)命令与here document一起使用,例如:

 batch << EOJ
   php /home/www/api/24 > 24.out 2> 24.err < /dev/null
   php /home/www/api/17 > 17.out 2> 17.err < /dev/null
   php /home/www/api/19 > 19.out 2> 19.err < /dev/null
 EOJ
相关问题