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

Using cron to run scripts at certain times of the day?

Discussion in 'Tomato Firmware' started by dingmel, Nov 30, 2008.

  1. dingmel

    dingmel LI Guru Member

    Hi there. i read that cron enables the running of scripts at certain times. i'm using tomato 1.22.8011 on a WRT54GL. i'd like to have the following script :

    iptables -I FORWARD -s 192.168.1.101 -d 213.155.85.123 -j DROP

    run at certain times of the day, ie. 10am till 11pm daily on certain days. how is that done? Thanks in advance :D
     
  2. fyellin

    fyellin LI Guru Member

    It sounds like what you really want is to run the command
    Code:
    iptables -I FORWARD -s 192.168.1.101 -d 213.155.85.123 -j DROP
    at 10am, and the command
    Code:
    iptables -D FORWARD -s 192.168.1.101 -d 213.155.85.123 -j DROP
    at 11pm. The first adds a rule and then second deletes it.

    So you'd want to run the following two cru commands to cause each command to run every day at the appropriate hour.
    Code:
    cru a AddIptableRule "0 10 * * * iptables -I FORWARD -s 192.168.1.101 -d 213.155.85.123 -j DROP"
    cru a DelIptableRule "0 23 * * *  iptables -D FORWARD -s 192.168.1.101 -d 213.155.85.123 -j DROP"
    
     
  3. dingmel

    dingmel LI Guru Member

    oo thanks for the prompt reply. i'll try adding what you've suggested to the init tab and see how it works.

    i'd like to learn more about cron'ing and iptables. the possibilities seem to be endless atmo. where would be a good place to start? Thanks once again :D
     
  4. dingmel

    dingmel LI Guru Member

    erm, doesn't seem to be working. i've added the command to the Init section of the scripts tab.

    cru a AddIptableRule "0 9 * * * iptables -I FORWARD -s 192.168.1.101 -d 213.155.85.123 -j DROP"
    cru a DelIptableRule "0 23 * * * iptables -D FORWARD -s 192.168.1.101 -d 213.155.85.123 -j DROP"

    is there anything else i'm supposed to do?
     
  5. dingmel

    dingmel LI Guru Member

    update : i've confirmed that the cron job is indeed listed and possibly active. the
    # cru l command lists them, but, # iptables -L doesn't seem to be listing the command. is there something i'm doing wrong?
     
  6. dingmel

    dingmel LI Guru Member

    bump^
     
  7. rhester72

    rhester72 Network Guru Member

    a) You might want to configure these through the GUI rather than CRU.

    b) Have you tried setting these rules manually through the CLI to verify they don't error out?

    Rodney
     
  8. dingmel

    dingmel LI Guru Member

    yes i've tried via the CLI. they don't error. #cru L verifies that they're present, but they don't seem to be working. which GUI option would allow me to do this? Thanks
     
  9. rhester72

    rhester72 Network Guru Member

    Administration/Scheduler/Custom X.

    Rodney
     
  10. dingmel

    dingmel LI Guru Member

    ahhh silly me. thanks loads! i'll try it out right away ! :D

    Edit : I tried entering

    iptables -I FORWARD -s 192.168.1.100 -d 213.155.85.123 -j DROP

    at the scheduler but it doesn't seem to be triggering at the appointed time. weird -.-
     
  11. levelup3

    levelup3 Addicted to LI Member

    is really useful for me
     

Share This Page