Jump to content


Photo

network restart script


  • Please log in to reply
13 replies to this topic

#1 kalehrl

  • Senior Member
  • 476 posts

+8
Neutral

Posted 23 June 2024 - 19:33

I'm using a USB WiFi dongle on a box with openpli 9.0 but from time to time, the box looses internet connection and I have to restart network in the menu of the box for it to work again. Is there a script I can run on the box to automatically check if the network works and if not to restart it? Thanks.



Re: network restart script #2 stro11

  • Senior Member
  • 197 posts

+14
Neutral

Posted 23 June 2024 - 22:46

Hi,

 

With this script you can check your network status and it will restart your network device if the network is down.

You have to set the correct network device in line 4 of the script. (eth0, eth1, wlan0, wlan1, ...etc)

You can set a cron timer to execute the script every hour or 30 minutes.

 

regards,

stro11

Attached Files


Edited by stro11, 23 June 2024 - 22:50.


Re: network restart script #3 kalehrl

  • Senior Member
  • 476 posts

+8
Neutral

Posted 24 June 2024 - 07:16

Thank you. I edited the file changing eth0 to wlan0 and set up the cron job to run the script every minute.

I will report if this fixes the problem.



Re: network restart script #4 40H3X

  • Forum Moderator
    PLi® Contributor
  • 5,956 posts

+191
Excellent

Posted 24 June 2024 - 10:55

The best solution is to find the reason why it looses the connection. Most logical reason for connection loss is that the distance to the Access Point is to far or the location is to "shielded". You could add a long USB cable between the USB WiFi dongle, it helped me once. Better solution is add more Access Points.


Hardware: Vu+ Uno 4K SE - Vu+ Duo 4K  - Fuba 78 cm - Tripleblock LNB Quad 19.2/23.5/28.2 - DS918+
Software : OpenPLi - OSCam - Settings van Hans - Autotimer - EPGImport

---------------------------------------------------------------------------------------------------------------------------------------

Remember: Upvote with the rep_up.png button for any user/post you find to be helpful, informative, or deserving of recognition!

---------------------------------------------------------------------------------------------------------------------------------------

Many answers to your question can be found in our new and improved wiki

Note: I do not provide support via PM !.


Re: network restart script #5 stro11

  • Senior Member
  • 197 posts

+14
Neutral

Posted 24 June 2024 - 11:10

This version creates a log file and every time the network needs to be restarted, a log entry with time and date is made.
This way you can monitor the restarts of your network device over a long period.
This might help you to get more insight about when, and how many times the network needs to be restarted.
 
You can set the location for the log file in line 7 of the script.

Attached Files



Re: network restart script #6 callahan

  • New Member
  • 3 posts

0
Neutral

Posted 24 June 2024 - 11:45

I also encountered cases of the WiFi network interface freezing. The LED on the card then started blinking non-stop and the box lost connection. Even restarting the interface from the menu did not help. Only restarting the entire box restored the network, but only for a while. I was wondering why there are periods when the network works smoothly for up to weeks, and there are also times when the interface freezes several times within 2-3 hours. The problem turned out to be the WiFi channel on which the router was transmitting. It turned out that when the router was transmitting on channel 11, the problem manifested itself. When he was transmitting on channel no. 1, everything was fine. I turned off automatic channel selection on the router and permanently set channel no. 1. Since then, I have not had a single interface hang-up.



Re: network restart script #7 kalehrl

  • Senior Member
  • 476 posts

+8
Neutral

Posted 25 June 2024 - 08:39

 

This version creates a log file and every time the network needs to be restarted, a log entry with time and date is made.
This way you can monitor the restarts of your network device over a long period.
This might help you to get more insight about when, and how many times the network needs to be restarted.
 
You can set the location for the log file in line 7 of the script.

 

It didn't work.

This morning the box is unreachable.

I noticed that the router doesn't have the receiver ip connected.

I will try modifying the script to ping router ip address instead its own.



Re: network restart script #8 stro11

  • Senior Member
  • 197 posts

+14
Neutral

Posted 25 June 2024 - 21:01

Modifying the script for that is easy, you can set an ip address in line 12, like this: IP_ADDRESS="101.102.103.104"



Re: network restart script #9 kalehrl

  • Senior Member
  • 476 posts

+8
Neutral

Posted 26 June 2024 - 07:19

Yes, that's what I did using my router ip address:

#!/bin/sh

## Set the correct network device in the next line. (eth0, eth1, wlan0, wlan1, ...etc) ##
NET_DEV=wlan0

## Set the location for the log file. (/home/root, /media/hdd, /media/usb, ...etc) ##
LOG_LOCATION=/home/root

LOG=$LOG_LOCATION/network_restarts.log
DATE=$(date +%Y-%m-%d)
TIME=$(date +%H:%M:%S)

## Check the presence of the log file and create a log file when it is missing. ##
if [ ! -e $LOG ]; then
    echo -e "\tNetwork Restarts\n" > $LOG
fi

## Check the size of the log file, when the log file has 250 lines rename/save the current log file and create a new log file. ##
count_log_lines() {
    LINES=$(echo -n "$(cat $LOG)" | grep -c '^')
    LOG_DT=/tmp/network_restarts_${DATE}_$(date +%H:%M).log
    if [ $LINES -ge 250 ] ; then
        mv $LOG $LOG_DT
    fi
}

IP_ADDRESS=192.168.0.1

if ! ping -c 3 $IP_ADDRESS ; then
    echo -e "\nNetwork device $NET_DEV down !!\nNetwork will now be restarted.\n"
    echo "$DATE $TIME  Restart Network device $NET_DEV" >> $LOG
    count_log_lines
    /sbin/ifdown $NET_DEV && sleep 3
    /sbin/ifup $NET_DEV
else
    echo -e "\nNetwork device $NET_DEV is active, no need to restart.\n"
fi

exit

 



Re: network restart script #10 s3n0

  • Senior Member
  • 673 posts

+62
Good

Posted 26 June 2024 - 13:14

Hi.

 

I agree with @40H3X - about finding the cause of the problem. A shell-script will not solve the problem.

 

Internet disconnection can be a shared problem in some cases - for example: softcam connection, VPN network, RTC synchronization, use of ping/tracert commands, ... and the like.

 

You should rather look for the causes of the problem.

 

A similar case happened to me. The ethernet connection (metal cables through RJ-45 connectors) in my set-top box started to fall out. I really tried everything. Re-crimp the TwistedPair cable on both of its connectors. Buy a new original TP cable from the store. Reflash the firmware in the set-top box to the latest / to the older one. Replace HDMI and network cables. Use surge protection. Replace the WIFI router with a new one. Finally, I tried to buy and replace the entire set-top box. However, the Ethernet network drop continued even in the new set-top box.

 

Nothing helped. The Ethernet LAN in the set-top box still stopped working occasionally, as if it was stuck. Sometimes it happened twice a day.

 

In the end, only one thing helped... and that was the use of an STP cable - with "tinfoil" shielding inside the cable. That is that there is some kind of strong interference near the WIFI router and I can't figure out which source.

 

But now back to the main problem...

 

I tried to start using different USB WIFI dongles at that time. Many of them showed a weak radio (2.4 GHz) signal. Some even occasionally fell (disconnected).

 

I also tried such an auto-restart shell-script. But that didn't solve my problem at all at the time.



Re: network restart script #11 WanWizard

  • PLi® Core member
  • 70,528 posts

+1,811
Excellent

Posted 26 June 2024 - 14:43

Also, what most people don't seem to realize: wifi is a shared medium, in which the speed of the radio is set to the weakest client.

 

So even if your device says "300 Mbps" as connection speed, if you have an iphone in a second-floor kids bedroom connected to the same AP, chances are the actual speed is only a fraction of it.

 

And... not all AP's are made equal. I used to have Draytek AP's, and sometimes had connection issues too. Now, for the last 2 years, I have 3 Ubiquity Unifi AP's covering all rooms, and since then, no issues anymore. AP roaming works a lot better too.


Currently in use: VU+ Duo 4K (2xFBC S2), VU+ Solo 4K (1xFBC S2), uClan Usytm 4K Ultimate (S2+T2), Octagon SF8008 (S2+T2), Zgemma H9.2H (S2+T2)

Due to my bad health, I will not be very active at times and may be slow to respond. I will not read the forum or PM on a regular basis.

Many answers to your question can be found in our new and improved wiki.


Re: network restart script #12 40H3X

  • Forum Moderator
    PLi® Contributor
  • 5,956 posts

+191
Excellent

Posted 26 June 2024 - 14:58

As I said and will repeat again, solve the cause and not the issue it brings about. With WiFi the most common problem is interference with other Access Points nearby and of course mediocre hardware. Most people will try to boost there transmit power, but this will only make things worse.

The only solution is to buy Access Points that have good hardware and can "work together" and thus have good roaming capabilities, like Unifi Access Points. I use Unifi nanoHD's and bought enough to have good coverage everywhere. I never have WiFi issues and can see clients roaming from one Access Point to the other, as they move around.


Hardware: Vu+ Uno 4K SE - Vu+ Duo 4K  - Fuba 78 cm - Tripleblock LNB Quad 19.2/23.5/28.2 - DS918+
Software : OpenPLi - OSCam - Settings van Hans - Autotimer - EPGImport

---------------------------------------------------------------------------------------------------------------------------------------

Remember: Upvote with the rep_up.png button for any user/post you find to be helpful, informative, or deserving of recognition!

---------------------------------------------------------------------------------------------------------------------------------------

Many answers to your question can be found in our new and improved wiki

Note: I do not provide support via PM !.


Re: network restart script #13 s3n0

  • Senior Member
  • 673 posts

+62
Good

Posted 26 June 2024 - 15:25

Also, in my case, the primary problem was a malfunctioning metallic cable. I tried using USB WIFI, but even there there was some interference (there is no problem on smartphones, laptops, etc. and all the devices at my house are within reach through one wall at a maximum of 5-10 meters - all without problems). I personally can manage USB WIFI very well. However, the problem in my case is somewhere else. Probably a damaged microwave oven (also uses the 2.4 GHz band) which is placed near my set-top box.

 

In the case of the interviewer, however, the problem must be solved. Shell-script, as I wrote, is in my opinion also an insufficient solution, because other/further problems will appear next, if the internet in the set-top box continues to be regularly disconnected (and the shell script only restarts it).



Re: network restart script #14 WanWizard

  • PLi® Core member
  • 70,528 posts

+1,811
Excellent

Posted 26 June 2024 - 18:30

Microwave, DECT phone, Bluetooth, all operate in the same 2.4Ghz band. And like @40H3X wrote, other AP's on the same channel could also be a big interference.

 

Last year I had this in my office, neighbor with a new car with wifi hotspot, broadcasting at full power directly outside my office window...


Currently in use: VU+ Duo 4K (2xFBC S2), VU+ Solo 4K (1xFBC S2), uClan Usytm 4K Ultimate (S2+T2), Octagon SF8008 (S2+T2), Zgemma H9.2H (S2+T2)

Due to my bad health, I will not be very active at times and may be slow to respond. I will not read the forum or PM on a regular basis.

Many answers to your question can be found in our new and improved wiki.



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users