orlea orlea - 2 months ago 7
Linux Question

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

I have this script:

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


The script basically checks for any new URLs at
wget-download-link.txt
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

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.

Comments