gpt4 book ai didi

linux - 如何在后台运行脚本(linux openwrt)?

转载 作者:IT王子 更新时间:2023-10-29 00:32:09 44 4
gpt4 key购买 nike

我有这个脚本:

#!/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

该脚本基本上每 30 秒检查一次 wget-download-link.txt 中的任何新 URL,如果有新 URL,它将使用 wget 下载它,问题是当我尝试像这样在 Putty 上运行这个脚本

/root/wget/wget_download.sh --daemon

它仍在前台运行,我仍然可以看到终端输出。如何让它在后台运行?

最佳答案

在 OpenWRT 中,默认情况下既没有 nohup 也没有 screen 可用,因此只有内置命令的解决方案是启动一个带括号的子 shell 并将其放在背景 &:

(/root/wget/wget_download.sh >/dev/null 2>&1 )&

您可以在桌面上轻松测试此结构,例如

(notify-send one && sleep 15 && notify-send two)&

...然后在 15 秒结束之前关闭控制台,您将看到括号中的命令在关闭控制台后继续执行。

关于linux - 如何在后台运行脚本(linux openwrt)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27634696/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com