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

Script that hits a URL every minute - but how?

Discussion in 'Tomato Firmware' started by yocal, Aug 6, 2007.

  1. yocal

    yocal LI Guru Member

    Hi there,

    I got a Linksys WRT54G with Tomato 1.07 and I am trying to figure out make a script that hits an URL, lets say, every minute.

    Interval: 1 minute
    URL: www.mydomain.com/jobexecuter.php

    How in the world do i do that? It just needs to hit the URL, doesnt have to wait for the page to complete loading.

    Any help? :)

    // Yoc.
     
  2. azeari

    azeari LI Guru Member

  3. yocal

    yocal LI Guru Member

    See, this is where we hit the wall :)

    What to do, where, and why :) Im pretty much on from scratch here ;-)

    // Yoc.
     
  4. azeari

    azeari LI Guru Member

    something like
    cru a lalalaid "1-59 * * * * wget http://mydomain.com/hit.php"

    not sure if that'll work though.. try working from here.. me forgot how to use cron
     
  5. yocal

    yocal LI Guru Member

    Well, considering that i am doing this from cratch, i have NO idea of the different parameters... lalala? random name? Why the "? 1-59? * * * * means?

    I've tried to look for some docs on cru, because that was also what i figured i could use - but didnt find anything. Would be helpful if you could point me in the direction of some documentation, or something would explain how all this works, hehe.

    // Yoc.
     
  6. yaqui

    yaqui LI Guru Member

  7. Overflow-ar

    Overflow-ar LI Guru Member

    actually, you asked to hit a url every min

    place this script in the Init and it should work fine.

    echo -e "wget www.mydomain.com/jobexecuter.php" > /tmp/jobexecuter
    chmod 777 /tmp/jobexecuter
    cru a jobexecuter "*/1 * * * *" /tmp/jobexecuter

    this way you could easily add more places to be hit every minute :biggrin:
     
  8. yaqui

    yaqui LI Guru Member

    Or just put this under Wan Up script:
    Code:
    ### Replace somesite.com with site of your choice 
    site='http://www.somesite.com'
    while [ true ] ; do
      sleep 60
      ping -c 1 "$site"
    done
     
  9. Overflow-ar

    Overflow-ar LI Guru Member

    yaqui, I think he's trying to execute some php code on the server side, isn't the ping a lower OSI level ? I mean, it would not execute nothing on server side as it will not go to the application level.
     
  10. yaqui

    yaqui LI Guru Member

    Sorry didn't read all of his first post. Just do this then..
    Code:
    site='http://www.mydomain.com/jobexecuter.php'
    while [ true ] ; do
      sleep 60
      wget -O /dev/null "$site"
    done
     
  11. azeari

    azeari LI Guru Member

    well personally i feel cron is more elegant in such a case :p i usually don't use while sleeps unless its shorter than 1min =X
     
  12. yaqui

    yaqui LI Guru Member

    I don't think your cru works...
    Code:
    # wget http://www.google.com
    wget: index.html: Read-only file system
    # echo $?
    1
    #
    You get a return 1 if you do a wget like how you have it.
    Should be like this, and you should be able to just use all *'s (they mean every - so every minute)
    Code:
    cru a jobexecuter "* * * * * wget -O /dev/null http://www.mydomain.com/jobexecuter.php"
    See this will give you return 0:
    Code:
    # wget -O /dev/null http://www.google.com
    Connecting to www.google.com[208.67.217.230]:80
    # echo $?
    0
    Edit: Yes you can use all stars... put this in your shell to test
    Code:
    cru a crutest "* * * * * wget -O /dev/null http://www.google.com | date >> /tmp/crutest"
    Now check the contents of /tmp/crutest:
    Code:
    Tue Aug  7 13:45:01 CDT 2007
    Tue Aug  7 13:46:01 CDT 2007
    Tue Aug  7 13:47:01 CDT 2007
    Tue Aug  7 13:48:01 CDT 2007
    Tue Aug  7 13:49:01 CDT 2007
    Tue Aug  7 13:50:01 CDT 2007
    Tue Aug  7 13:51:01 CDT 2007
    Tue Aug  7 13:52:01 CDT 2007
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    - /tmp/crutest 1/9 11%
    Yep, works with just all asterisks *'s
     
  13. yaqui

    yaqui LI Guru Member

    To hit multiple sites every minute, you might want to put them in a 'here document' and place the script under Wan Up:
    Code:
    sleep 45
    if [ ! -x /tmp/hitsites ] ; then
    cat > /tmp/hitsites <<EOF
    #!/bin/sh
    wget -O /dev/null http://www.site1.com
    wget -O /dev/null http://www.site2.com
    wget -O /dev/null http://www.site3.com
    wget -O /dev/null http://www.site4.com
    wget -O /dev/null http://www.site5.com
    wget -O /dev/null http://www.site6.com
    wget -O /dev/null http://www.site7.com
    EOF
    chmod 777 /tmp/hitsites
    cru a hitsites "* * * * * /tmp/hitsites"
    fi
     
  14. t4thfavor

    t4thfavor Network Guru Member

    I like the last one, I also would put it in the cron job since cron is already running, you only have a larger memory footprint when the cron job is actually executing.
     

Share This Page