CodingBash if -eq

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  ANT_THOMAS  
 To:  ALL
39973.1 
Got a bash script for checking the speed of my router and rebooting when necessary. It is now time dependant but the line I've used is awful.

Here's the line
Bash code:
HOUR=$(date "+%H")
if [ "$SPEED" -le 7000 ] &&
[ "$HOUR" -eq 01 -o  "$HOUR" -eq 02 -o  "$HOUR" -eq 03 -o  "$HOUR" -eq 04 -o  "$HOUR" -eq 05 -o  "$HOUR" -eq 06 -o  "$HOUR" -eq 07 -o  "$HOUR" -eq 08 ]; then
blah blah blah


There is surely a nicer way to do the hour thing rather then using "-o" for each hour.

Something like this (but obviously something that actually works)

Bash code:
HOUR=$(date "+%H")
if [ "$SPEED" -le 7000 ] &&
[ "$HOUR" -eq 01,02,03,04,05,06,07,08 ]; then


Ideas on a postcard.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
39973.2 In reply to 39973.1 
Why can't you write:
code:
"$HOUR" -le 8


?
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
39973.3 In reply to 39973.2 
Good point. For some reason it was because I was going to include 23 (11pm) but I don't think I want to.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
39973.4 In reply to 39973.3 
Well even then, a lt 8 or gt 23 would still be simpler than listing numbers.

But yeah, the Bash conditional stuff is super shitty, and if you are going to make this any more complex, I'd definitely consider doing it in a language that has proper ORs/etc.
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
39973.5 In reply to 39973.4 

I hope it doesn't need to get any more complex.

 

Basically I want the script to only reboot the router at night, rather than have it loop when people are in the bathroom.

 

I shouldn't have to be making this (fail) :@ :@ :@

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
39973.6 In reply to 39973.5 
Replace the bulb with an oil lamp. Problem solved. :)
0/0
 Reply   Quote More 

 From:  sinkywinky  
 To:  ANT_THOMAS     
39973.7 In reply to 39973.5 
You could remove the time checking stuff from the script and set a cron job to run it every hour between 1 and 8am.
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  sinkywinky     
39973.8 In reply to 39973.7 
I want it to still log the sync speed throughout the day. (I'm not sure why now).
0/0
 Reply   Quote More 

 From:  koswix  
 To:  ANT_THOMAS     
39973.9 In reply to 39973.8 
Does it not log the speed changes in its own log? My sky router.does (i think...)



                                                
                                                
                                                
                           ▪                    
             ┌────┐    ┌────┐                      
          │    │    │    │ ▪                    
          │    └────┘    │                      
          │   ──┐  ┌──   │ ▪                    
   ┌──────┤    ▪    ▪    │                      
  ┌┘      │              │ ▪                    
┌─┤       └──┐  │  │  ┌──┘                      
│ │          │ ││  ││ │   ┌─┐                   
│ │          └─┼┤  └┴─┴───┘ │                   
│ │           ─┘│           │                   
│ │   ┌──────┐  └┬──────────┘                   
  │   │      │   │                              
  │   │      │   │                              
  └───┘      └───┘                              
If Feds call you and say something bad on me, it may prove what I said are truth, they are afraid of it.
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  koswix     
39973.10 In reply to 39973.9 
Maybe, but the web admin is very slow.
0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  ANT_THOMAS     
39973.11 In reply to 39973.5 
quote: ANT_THOMAS

Got a bash script for checking the speed of my router and rebooting when necessary. It is now time dependant but the line I've used is awful.

quote: ANT_THOMAS

Basically I want the script to only reboot the router at night, rather than have it loop when people are in the bathroom.

So if I've understood this correctly, you want your router to check its speed and reboot only if someone's not using the connection? Dumb question: why not just get it to (check and) reboot once before a new user session?

truffy.gifbastard by name
bastard by nature

0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  99% of gargoyles look like (MR_BASTARD)     
39973.12 In reply to 39973.11 

Eh? New user session?

 

There's always things connected to it using the connection. So it's not really a time with no activity, just much less. And detecting a "new user session" can't be easy.

0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  ANT_THOMAS     
39973.13 In reply to 39973.12 
quote: ANT_THOMAS

Eh? New user session?

When real people, who care about d/l speed are using the connection.

quote: ANT_THOMAS

And detecting a "new user session" can't be easy.

Au contraire, it doesn't have to be detected, it's the time when real people (if you have any in Manchester) start to use the connection. Innit?

truffy.gifbastard by name
bastard by nature

0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  99% of gargoyles look like (MR_BASTARD)     
39973.14 In reply to 39973.13 

That varies far too much.

And using it at a slower sync for browsing is better than waiting for it to reboot. Also, if I was to reboot just before I get back from work there's a good chance I'll go to the loo when I get home, fucking the whole thing up.

I'm sticking to early hours reboots and manual ones if I'm really bothered. Since 4mbps is actually fine for casual browsing, just not streaming and torrenting stuff quickly.

0/0
 Reply   Quote More 

Reply to All    
 

1–14

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats