我有这个脚本:
#!/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
该脚本主要检查以下位置是否有任何新 URL:wget-download-link.txt
每 30 秒一次,如果有新的 URL,它会使用 wget 下载它,问题是当我尝试在 Putty 上运行此脚本时,如下所示
/root/wget/wget_download.sh --daemon
它仍然在前台运行,我仍然可以看到终端输出。如何让它在后台运行?
在 OpenWRT(2023 年之前)中,两者都没有nohup
nor screen
默认情况下可用,因此仅使用内置命令的解决方案是使用括号启动一个子 shell,并将其放在后台&
:
(/root/wget/wget_download.sh >/dev/null 2>&1 )&
您可以在桌面上轻松测试此结构,例如
(notify-send one && sleep 15 && notify-send two)&
...然后在这 15 秒结束之前关闭控制台,您将看到关闭控制台后括号中的命令继续执行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)