1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script Question!!!

Discussion in 'Tomato Firmware' started by Zoltair, Mar 4, 2010.

  1. Zoltair

    Zoltair LI Guru Member

    Can anyone tell me if it is possible to execute a script when a particular device appears on the network?

    Here is my scenario!

    I use a WRT54G with Tomato and all my machines utilize static DHCP. I have a particular embedded network unit that gets moved around the house quite frequently and every time it gets unplugged, my defaults disappear and I must telenet back into it to reset some parameters before it can be used again. I would like to automate this so when the unit appears on the network, a script located on the router or the central server can be executed to reload the parameters on its own.

    The scripting syntax is not too much of a problem, but the triggering has me thinking...

    Zol..
     
  2. rhester72

    rhester72 Network Guru Member

    If you use static DHCP or a static IP for it, you should be able to whip up a cru script to execute every minute to check for its presence and take action based on the result.

    Rodney
     
  3. Zoltair

    Zoltair LI Guru Member

    Only need it to be executed once when powered up, I can use a cron job to monitor the system logs for a DHCP assignment, and add the logic to evaluate and determine if already executed, I just thought an event trigger would be less problematic to implement if that facility was present.
     
  4. rhester72

    rhester72 Network Guru Member

    I'm not aware of an event trigger specific to a device appearing on the network - agreed it would be more efficient than polling. A SNMP trap would seem to be most logical here, except that level of SNMP services are also not available (at least in all default Tomato builds I'm aware of).

    Rodney
     
  5. mros

    mros Networkin' Nut Member

    Hi,
    theoretically this "trigger" exists:

    You can add a line in dnsmasq.conf:
    dhcp-script=/jffs/yourscript.sh

    According to dnsmasq man page this script is called whenever a dhcp change occurs (like a device entering or leaving the network).

    For some reason this does not seem to be supported by the dnsmasq that comes with tomato.
    Neither adding this line to the dnsmasq.conf file, nor adding it to a dnsmasq.custom file (nor even pasting it in the custom config text box through the browser) calls the script.
     
  6. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    dhcp-script works just fine for me in Tomato 1.27, adding it to the Dnsmasq custom configuration section...

    This would be a perfect way to solve the original poster's problem.
     
  7. mros

    mros Networkin' Nut Member

    Hi,
    thanks for the reply.
    Did you paste something in the text box or did you use dnsmasq.custom ?

    I used "dhcp-script=/jffs/yourscript.sh" in the text box.

    It seems to me that whenever I do this, dnsmasq crashes (internet connection gone). However that might not be the root cause of this. When I clear the text box and restart dnsmasq, internet connection is back.

    I am using Tomato 1.27 and updating to 1.28 did not change this behavior.

    My script is executable and runs fine when invoked by the command line.

    Any hints ?
     
  8. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    I simply put "dhcp-script=/tmp/dhcp.sh" in the Advanced->DHCP/DNS->Dnsmasq Custom Configuration GUI textarea. The script was simple, though:
    Code:
    #!/bin/sh
    echo $* > /tmp/dhcpoutput
    
    Simply to test the dhcp-script directive. The next time a device renewed its lease (I have a Wii, so it happened almost immediately), /tmp/dhcpoutput had the expected content.

    Maybe you could start with a simple script like that and expand it until it does what you want, to see what's causing the issue?
     
  9. mros

    mros Networkin' Nut Member

    Hi,
    when I put this into the Advanced->DHCP/DNS->Dnsmasq Custom Configuration GUI textarea:

    dhcp-script=/tmp/dhcp.sh

    I get this as an output in /var/log/messages:
    Jul 9 20:15:37 unknown daemon.crit dnsmasq[972]: recompile with HAVE_SCRIPT defined to enable lease-change scripts at line 17 of /etc/dnsmasq.conf
    Jul 9 20:15:37 unknown daemon.crit dnsmasq[972]: FAILED to start up
    Jul 9 20:15:37 unknown daemon.crit dnsmasq[973]: recompile with HAVE_SCRIPT defined to enable lease-change scripts at line 17 of /etc/dnsmasq.conf
    Jul 9 20:15:37 unknown daemon.crit dnsmasq[973]: FAILED to start up

    line 17 is exactly the above statement "dhcp-script..."

    The script dhcp.sh is executable and in the right folder.

    Beats me :-(

    If you had not said that it works with your system, I would have guessed that dnsmasq was compiled with script support disabled. I have a WRT54G router. Has tomato different feature sets for different routers ? It should not since it uses the same update files "tomato.trx" for all systems.

    Any enlightment from your side ?
     
  10. mros

    mros Networkin' Nut Member

    Oh, and btw: I appreciate your help ;-) !!!
     
  11. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    Are you using vanilla Tomato or one of the various mods?
     
  12. mros

    mros Networkin' Nut Member

    After browsing the source code for V1.28 I discovered that in dnsmasq's source code "dhcp-script" is in fact disabled.

    From file config.h:

    /* platform independent options- uncomment to enable */
    #define HAVE_DHCP
    /* #define HAVE_TFTP */
    /* #define HAVE_SCRIPT */ <------ HAVE_SCRIPT must be enabled for dhcp-script !!
    #define HAVE_BROKEN_RTC
    /* #define HAVE_DBUS */

    /* Allow TFTP to be disabled with COPTS=-DNO_TFTP */

    So I guess there is no way around compiling your own version of tomato to enable this feature.
    So sad...
     
  13. mros

    mros Networkin' Nut Member

    Hi, I am using vanilla.
     
  14. mros

    mros Networkin' Nut Member

    What do you use ?
     
  15. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    The router I tried it on is running on (a build based on) Tomato 1.25. It looks like this was made a configurable option in the Dnsmasq version added in 1.26, but it wasn't enabled.

    Mystery solved. :smile:

    You could probably send an email to Jon asking him to enable that option in the next Tomato release (explaining that it used to be always enabled before it was configurable). I think I may go ahead and enable it in TomatoVPN's next release.
     

Share This Page