skip to Main Content

Due to some issues I wont elaborate here to not waste time, I made a bash script which will ping google every 10 minutes and if there is a response it will keep the loop running and if not then the PC will restart. After a lot of hurdle I have been able to make the script and also make it start on bootup. However the issue is that i want to see the results on the terminal, meaning I want to keep monitoring it but the terminal does not open on bootup. But it does open if I run it as ./net.sh.
The script is running on startup, that much I know because I use another script to open an application and it works flawlessly.

My system information

NAME="Linux Mint"
VERSION="18.3 (Sylvia)"
ID=linuxmint
ID_LIKE=ubuntu
PRETTY_NAME="Linux Mint 18.3"
VERSION_ID="18.3"
HOME_URL="http://www.linuxmint.com/"
SUPPORT_URL="http://forums.linuxmint.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/linuxmint/"
VERSION_CODENAME=sylvia
UBUNTU_CODENAME=xenial

The contents of my net.sh bash script are

#! /bin/bash

xfce4-terminal &

sleep 30

while true
do
        ping -c1 google.com
        if [ $? == 0 ]; then
                echo "Ping Sucessful. The Device will Continue Operating"
                sleep 600
        else
                systemctl reboot
        fi

done

I have put the scripts in /usr/bin and inserted the scripts for startup at boot in /etc/rc.local

2

Answers


  1. Chosen as BEST ANSWER

    So I did some further research and with help from reddit I realized that the reason I couldnt get it to show on terminal was because the script was starting on bootup but I needed it to start after user login. So I added the script on startup application (which can be found searching on start menu if thats whats it called). But it was still giving issues so I divided the script in two parts. I put the net.sh script on startup and directed that script to open my main script which i named net_loop.sh

    This is how the net.sh script looks

    #! /bin/bash
        
    sleep 20
    xfce4-terminal -e usr/bin/net_loop.sh
    

    And the net_loop.sh

    #! /bin/bash
    
    while true
    do
            ping -c1 google.com
            if [ $? == 0 ]; then
                    echo "Ping Sucessful. The Device will Continue Operating"
                    sleep 600
            else
                    systemctl reboot
            fi
    
    done
    

    The results are the results of the net_loop.sh script are open in another terminal.
    Note: I used help from this thread


  2. If minute interval is usable why not use "cron" to start your?

    $> crontab –e

    or

    $> sudo crontab –e

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search