orlea orlea - 1 year ago 73
Linux Question

How to run a script in background (linux openwrt)?

I have this script:

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

url=$( head -n 1 $urlfile )
if [ "$url" = "" ] ; then
mv $urlfile $urlfile.invalid

mv $urlfile $urlfile.busy
wget -b $url -P $dir -o /www/wget.log -c -t 100 -nc
mv $urlfile.busy $urlfile.done

The script basically checks for any new URLs at
for every 30 seconds and if there's a new URL it'll download it with wget, the problem is that when I try to run this script on Putty like this

/root/wget/wget_download.sh --daemon

it's still running in the foreground, I still can see the terminal output. How do I make it run in the background ?

Answer Source

Try this:

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

It will go to the background so when you close your Putty session, it will be still running, and it won't send messages to the terminal.