我有这个脚本:
#!/bin/sh
while [ true ] ; do
urlfile=$( ls /root/wget/wget-download-link.txt | head -n 1 )
dir=$( cat /root/wget/wget-dir.txt )
if [ "$urlfile" = "" ] ; then
sleep 30
continue
fi
url=$( head -n 1 $urlfile )
if [ "$url" = "" ] ; then
mv $urlfile $urlfile.invalid
continue
fi
mv $urlfile $urlfile.busy
wget -b $url -P $dir -o /www/wget.log -c -t 100 -nc
mv $urlfile.busy $urlfile.done
done
Run Code Online (Sandbox Code Playgroud)
该脚本基本上wget-download-link.txt每30秒检查一次新的URL,如果有一个新的URL,它将用wget下载,问题是当我尝试在Putty上运行这个脚本时这样
/root/wget/wget_download.sh --daemon
Run Code Online (Sandbox Code Playgroud)
它仍然在前台运行,我仍然可以看到终端输出.如何让它在后台运行?
在OpenWRT中,默认情况下既没有nohup也没有screen,所以只有内置命令的解决方案是使用括号启动子shell并将其放在后台&:
(/root/wget/wget_download.sh >/dev/null 2>&1 )&
Run Code Online (Sandbox Code Playgroud)
您可以在桌面上轻松测试此结构,例如
(notify-send one && sleep 15 && notify-send two)&
Run Code Online (Sandbox Code Playgroud)
...然后在15秒结束之前关闭控制台,关闭控制台后,您将看到括号中的命令继续执行.
jcb*_*rmu -4
尝试这个:
nohup /root/wget/wget_download.sh >/dev/null 2>&1 &
Run Code Online (Sandbox Code Playgroud)
它将进入后台,因此当您关闭 Putty 会话时,它仍将运行,并且不会向终端发送消息。
| 归档时间: |
|
| 查看次数: |
10146 次 |
| 最近记录: |