Koozali.org: home of the SME Server

Crontab wizard wanted!

Offline MSmith

  • *
  • 675
  • +0/-0
Crontab wizard wanted!
« on: July 12, 2012, 05:43:44 PM »
So I've been tasked with shutting off internet access every day at 5 p.m. and restarting it every day at 6 a.m.  Crontab magicians, will these entries work?

* 17 * * * /sbin/ifdown eth1
* 6 * * * /sbin/ifup eth1

...

Offline jameswilson

  • ****
  • 739
  • +0/-0
    • Security Warehouse, trade security equipment
Re: Crontab wizard wanted!
« Reply #1 on: July 12, 2012, 07:59:02 PM »
You can set times in dans guardian i believe. Might be better to go that way?

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: Crontab wizard wanted!
« Reply #2 on: July 13, 2012, 11:51:08 AM »
So I've been tasked with shutting off internet access every day at 5 p.m. and restarting it every day at 6 a.m.  Crontab magicians, will these entries work?

* 17 * * * /sbin/ifdown eth1
* 6 * * * /sbin/ifup eth1



Code: [Select]
man 5 crontab
will help you

Offline MSmith

  • *
  • 675
  • +0/-0
Re: Crontab wizard wanted!
« Reply #3 on: July 13, 2012, 03:10:24 PM »
Well, that's what I get for reading the man pages, working up the commands and thinking that I'd get a bit of feedback that I'd gotten the syntax right, or wrong, as the case may be. I had hoped that someone who's more familiar than I am with crontab entries would look at these and say, "Looks good" or "No, you'd be better off writing a small script that calls ifconfig" or some such.

Gentlemen, I do appreciate your taking the time to reply, but neither of you provided actual help. Thanks anyway.


...

Offline chris burnat

  • ****
  • 1,135
  • +2/-0
    • http://www.burnat.com
Re: Crontab wizard wanted!
« Reply #4 on: July 13, 2012, 06:28:30 PM »
Hello MSmith,  I tends to agree with you, we could be more helpful.  I am not a guru by any means but there may be a way around this: I have schedule your requirements in dungog-cronjob (I know it works) and then copy and paste the actual commands.

#(lan off)
0 17 * * 0-6 /sbin/ifdown eth1

#(lan on)
0 6 * * 0-6 /sbin/ifup eth1

 Hope it helps, no warranty...
« Last Edit: July 14, 2012, 02:21:50 AM by chris burnat »
- chris
If it does not work out of the box, please fill in a Bug Report @ Bugzilla (http://bugs.contribs.org)  - check: http://wiki.contribs.org/Bugzilla_Help .  Thanks.

Offline MSmith

  • *
  • 675
  • +0/-0
Re: Crontab wizard wanted!
« Reply #5 on: July 17, 2012, 09:53:35 PM »
Thank you, Chris, that was very helpful indeed.  I used mrhjb3's suggestions (well, with nano instead of pico, and rebooted instead of doing restart-crond) so we'll know shortly on my test machine! :)  Thanks again.
« Last Edit: July 17, 2012, 09:57:15 PM by MSmith »
...

Offline MSmith

  • *
  • 675
  • +0/-0
Re: Crontab wizard wanted!
« Reply #6 on: July 18, 2012, 12:08:25 AM »
So I had to edit those slightly ...

#(lan off)
0 17 * * * root /sbin/ifdown eth1

#(lan on)
0 6 * * * root /sbin/ifup eth1

The "ifdown" command worked great but "ifup" gives me an IP of 1.1.1.1 :(

Gonna dig around a little more to see how to restart networking in SME 8.
...

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: Crontab wizard wanted!
« Reply #7 on: July 18, 2012, 12:44:24 AM »
Gonna dig around a little more to see how to restart networking in SME 8.

something like
Code: [Select]
service network restart
should work

Offline MSmith

  • *
  • 675
  • +0/-0
Re: Crontab wizard wanted!
« Reply #8 on: July 18, 2012, 03:26:39 PM »
This whole thing is showing me just how little I've actually learned about Linux. One way or another, I'm just misunderstanding what's happening.

The cronjobs run fine ... ifdown works great ... but ifup does not bring eth1 back to functionality! This is completely stock SME8, on an old P4, and I've tried two different NICs for eth1.

"ifup eth1" gives eth1 an IP address of 1.1.1.1 and obviously that doesn't work.
"ifconfig eth1 up" results in the correct IP, but the SME machine can't reach out to the Internet.
"service network restart" doesn't restore network function either.  Only a reboot fixes Internet access.

The test box is behind another NAT router, is it possible that could be the problem? I *can* hook directly to my Internet feed for testing if necessary.

So, does this actually warrant a trip to the bug tracker? I'm thinking it's just me.

...

Offline _alex

  • ***
  • 103
  • +0/-0
Re: Crontab wizard wanted!
« Reply #9 on: July 18, 2012, 04:00:00 PM »
It looks like You are loosing your default route. You can try:

ifconfig eth1 up && route add default gw your.router.ip.addr

Offline MSmith

  • *
  • 675
  • +0/-0
Re: Crontab wizard wanted!
« Reply #10 on: July 18, 2012, 04:23:54 PM »
Interesting. That restored DNS lookup when, for instance, pinging google.com but resulted in "Destination host unreachable" for ping reply. HOWEVER, I *can* ping the next hop gateway, i.e. eth1 pulls 10.20.30.101 from DHCP, SME can ping 10.20.30.1. But not beyond.

Subsequently, "service network restart" = no eth1 !

I'm wondering if being behind a NAT box is the problem. May have to grub around in the wires after all.
« Last Edit: July 18, 2012, 04:26:19 PM by MSmith »
...

Offline _alex

  • ***
  • 103
  • +0/-0
Re: Crontab wizard wanted!
« Reply #11 on: July 18, 2012, 04:33:19 PM »
and with:
ifconfig eth1 up && route add default gw your.router.ip.addr dev eth1

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Crontab wizard wanted!
« Reply #12 on: July 18, 2012, 11:34:49 PM »
something like
Code: [Select]
service network restart
should work

No. The WAN interface has its own service.

Code: [Select]
sv down /service/wan

will bring the WAN interface down (you could also use "service wan stop"). I'll let you guess what you would do to bring the interface 'up'.

Offline MSmith

  • *
  • 675
  • +0/-0
Re: Crontab wizard wanted!
« Reply #13 on: July 23, 2012, 04:26:13 PM »
Charlie, thanks for entering the discussion. However, on a completely stock SME 8.0 with all updates to date, neither of those commands did what I wanted.

"sv down" returned me to the command line, but ifconfig eth1 showed address and ping to Internet still worked.

"service wan" returned "shutting down wan ... OK" but again, ifconfig showed address and ping to Internet still worked.

Submitted:
http://bugs.contribs.org/show_bug.cgi?id=7047



...