I have a bash script which I really cannot get to work. The script should first and foremost change VPN every X-minutes, and then also, if my connection drops, shift VPN. The script can be seen below:re='^[0-9]+$'sudo rm -rf /tmp/All_IPs_this_bootsudo -u frederik touch /tmp/All_IPs_this_bootwhile :do    # Restart the VPN, however, only if skype is not running!    if ! [[ $(pidof skype) =~ $re ]] ; then        sudo bash 'restart-vpn.sh' &    else        echo Error: Skype is running    fi    # Generate random overall sleep time before restart is forced    TimesOverall=$(shuf -i 35-65 -n 1)    echo Times to check: $TimesOverall        # Will check whether the restart worked    n=1    while [[ $n -le $TimesOverall ]]; do        # Choose random website to ping        rand=$(shuf -i1-5 -n1)        if [ $rand == 1 ]; then            Website=$(echo duckduckgo.com)        elif [ $rand == 2 ]; then            Website=$(echo pingmyurl.com)        elif [ $rand == 3 ]; then            Website=$(echo ping.eu)        elif [ $rand == 4 ]; then            Website=$(echo lenovo.com)        else            Website=$(echo archlinux.org)        fi        if [[ $(ping -4 -c 3 $Website | \                sed '1d' | sed -n 1,4p | cut -c1-14 | \                awk '{printf(%s, $0 (NR==1 ?  : ))}') \              == 64 bytes from 64 bytes from 64 bytes from  ]]        then            { echo -e IP is $(cat /tmp/ip) at $(date '+%d-%m %H:%M:%S'); \              cat /tmp/All_IPs_this_boot; } > /tmp/All_IPs_this_boot.new            mv /tmp/All_IPs_this_boot.new /tmp/All_IPs_this_boot                    sleep 20            ((n++))        else            sleep 6            # Choose random website to ping            rand=$(shuf -i1-5 -n1)            if [ $rand == 1 ]; then                Website=$(echo duckduckgo.com)            elif [ $rand == 2 ]; then                Website=$(echo pingmyurl.com)            elif [ $rand == 3 ]; then                Website=$(echo ping.eu)            elif [ $rand == 4 ]; then                Website=$(echo lenovo.com)            else                Website=$(echo archlinux.org)            fi            if [[ $(ping -4 -c 4 $Website |                     sed '1d' | sed -n 1,4p | cut -c1-14 | \                    awk '{printf(%s, $0 (NR==1 ?  : ))}') \                  == 64 bytes from 64 bytes from 64 bytes from 64 bytes from  ]]            then                { echo -e IP is $(cat /tmp/ip) at $(date '+%d-%m %H:%M:%S'); \                  cat /tmp/All_IPs_this_boot; } > /tmp/All_IPs_this_boot.new                mv /tmp/All_IPs_this_boot.new /tmp/All_IPs_this_boot                                    sleep 20                ((n++))            else                break            fi        fi    donedoneThe problem with the script is that it works properly for like an hour or so, then suddenly, which I can see in the file /tmp/All_IPs_this_boot, it stops working - it does not write anything to /tmp/All_IPs_this_boot. Furthermore, I can see that the process is running, so it is not because it is not running, the script just doesn't work after an hour, and I have to manually restart my VPN.
Bash script suddenly stops working after an hour
bash;vpn