关闭终端 SSH 后进程终止
Process killed after closing terminal SSH
我正在尝试每 2 秒清除一次服务器上的 facebook 缓存,所以我登录了 SSH 并执行了 运行 这个命令
while true; do sleep 2; curl -F id="http://twd.ma" -F scrape=true -F access_token='token' -F appID=appID https://graph.facebook.com; done &
一切正常,缓存开始每 2 秒清理一次。但是,当我关闭终端 SSH 时,缓存停止清理,我认为进程已终止,请问我该怎么办?
您的命令将停止执行,因为当您注销时,shell 会丢失。 '&' 表示脚本在后台运行 "as long as the shell is active"
您可以执行以下操作:
将您的脚本写入文件,即 clearcache.sh 并省略 '&'
#!/bin/bash
while true; do
sleep 2
curl -F id="http://twd.ma" -F scrape=true -F access_token='token' -F appID=appID https://graph.facebook.com
done
将脚本的路径写入 /etc/rc.local
/path/to/clearcache.sh > /dev/null 2&>1 &
' >/dev/null 2&>1 表示您的脚本产生的所有输出都将被删除。
如果 screen
可用,那么您可以通过 运行 宁 screen
、运行 您的命令开始屏幕会话,然后按 ctrl-a ctrl-d
分离会话。
稍后登录时,您可以发出 screen -r
以重新连接到分离的会话。
我正在尝试每 2 秒清除一次服务器上的 facebook 缓存,所以我登录了 SSH 并执行了 运行 这个命令
while true; do sleep 2; curl -F id="http://twd.ma" -F scrape=true -F access_token='token' -F appID=appID https://graph.facebook.com; done &
一切正常,缓存开始每 2 秒清理一次。但是,当我关闭终端 SSH 时,缓存停止清理,我认为进程已终止,请问我该怎么办?
您的命令将停止执行,因为当您注销时,shell 会丢失。 '&' 表示脚本在后台运行 "as long as the shell is active"
您可以执行以下操作: 将您的脚本写入文件,即 clearcache.sh 并省略 '&'
#!/bin/bash
while true; do
sleep 2
curl -F id="http://twd.ma" -F scrape=true -F access_token='token' -F appID=appID https://graph.facebook.com
done
将脚本的路径写入 /etc/rc.local
/path/to/clearcache.sh > /dev/null 2&>1 &
' >/dev/null 2&>1 表示您的脚本产生的所有输出都将被删除。
如果 screen
可用,那么您可以通过 运行 宁 screen
、运行 您的命令开始屏幕会话,然后按 ctrl-a ctrl-d
分离会话。
稍后登录时,您可以发出 screen -r
以重新连接到分离的会话。