Semicolon and Scripts

Discussion in 'Tomato Firmware' started by DarKHawK, Dec 31, 2017.

  1. DarKHawK

    DarKHawK Reformed Router Member

    Hi,

    I'm trying to add this script to the init section of the event scripts "Advanced Tomato v3.5-140 AIO-64K"

    Code:
    while sleep 30; do
      for i in 1 2 3; do
        if ping -qc1 -w10 google.com > /dev/null 2>&1; then
          /sbin/gpio disable 3
          continue 2
        fi
      done
      logger "Can't ping gateway"
      /sbin/gpio enable 3
    done
    But the script does not save, If I removed the semicolons the script saves.

    How should I resolve this.

    Thanks
     
  2. eibgrad

    eibgrad Network Guru Member

    No obvious reason why it shouldn't save. I just tried it on my ASUS RT-AC68U running Shibby Tomato v138 and it saved just fine. Even dumped nvram from a telnet session and I can see it's stored there.

    An alternative is to turn the script into a file in jffs, mark it executable, and call the script from jffs in the init script.
     
  3. eibgrad

    eibgrad Network Guru Member

    P.S. One reason it might not save is if you exceeded available nvram. Perhaps the semi-colons are not the problem, but the fact you removed three chars, so now it fits??
     
  4. DarKHawK

    DarKHawK Reformed Router Member

    Thank you for the reply.
    Here is a small gif:
    [​IMG]
    After refresh as you can see all the script after the semi-colon is not saved.
    And If I wrote any text without a semicolon it would save fine.

    Also nvram is not full, I can save a lot of text but without a semi-colon.
    Can you please explain in more detail how to turn the script into a file and run it?
     
  5. eibgrad

    eibgrad Network Guru Member

    Didn't find the gif helpful. Still not seeing it.

    Regardless, if you want to save a script to jffs (make sure you've enabled this feature, see Administration->JFFS), go to a telnet/ssh session and issue the following command.

    Code:
    cat > /jffs/myscript.sh
    This opens that file for interactive input. The terminal's cursor will move to the far left and wait for you to either type in your code, or cut and paste it. Before doing so, make sure the first line is a shebang.

    Code:
    #!/bin/sh
    Then add the rest of your code.

    When done, hit Ctrl-C and the file will be closed.

    Finally, mark the file executable.

    Code:
    chmod +x /jffs/myscript.sh
    You can now call that script from init:

    Code:
    /jffs/myscript.sh
     
    DarKHawK likes this.
  6. DarKHawK

    DarKHawK Reformed Router Member

    Thank you.
     
  7. chrisls

    chrisls Reformed Router Member

    Just wanted to note that I am experiencing this same issue running R7000-AT-ARM-3.5-140-AIO-64K.trx.

    looks to me that something is striping out anything after the first semicolon maybe a form data sanitation function not working properly? Or perhaps there is no sanitation and the form data is being interpreted?

    In any event if I do a simple echo hello world >> /var/log/test I get the file but if I try to do a simple if statement like:
    if [ "1" != "2" ];
    then
    echo hello world >> /var/log/test
    fi

    after hitting submit I am left with
    if [ "1" != "2" ]

    I am currently working in USB & NAS -> USB Support -> Hotplug script

    But I do get the same behavior in Administration -> Scripts

    I will attempt to do the manual way but does look to be a bug in version 140 maybe not in version 138?
     
  8. eibgrad

    eibgrad Network Guru Member

    FWIW, I'm using Tomato Firmware 1.28.0000 -138 K26ARM USB AIO-64K w/ my ASUS RT-AC68U and do NOT have the problem. Maybe it is related to v140.

    Just curious, can you escape the semicolon?

    Code:
    if [ "1" != "2" ]\;
    then
    echo hello world >> /var/log/test
    fi
     
  9. chrisls

    chrisls Reformed Router Member

    yeah I tried that end up with if [ "1" != "2" ]\
     
  10. eibgrad

    eibgrad Network Guru Member

    Well the good news is that the semicolon is usually optional. In your case, you don't even need the semicolon. In the OP's case, he can remove the semicolons and move what follows to the next line. The only purpose of the semicolon is to allow you to terminate a statement WITHOUT having to move to the next line. And that's purely cosmetic.

    Of course, the problem still needs to be corrected.
     
  11. chrisls

    chrisls Reformed Router Member

    correct I was just using it as an example. I did find that it looks like the semicolon is part of the payload when the form is submitted.

    _ajax=1&_nextpage=/#nas-usb.asp&_service=usb-restart&usb_enable=1&usb_uhci=-1&usb_ohci=1&usb_usb2=1&usb_usb3=1&usb_mmc=&usb_storage=1&usb_printer=1&usb_printer_bidirect=1&usb_fs_ext4=1&usb_fs_fat=1&usb_fs_exfat=1&usb_fs_ntfs=1&usb_automount=1&idle_enable=1&usb_3g=1&usb_apcupsd=1&usb_ntfs_driver=ntfs3g&script_usbmount=&script_usbumount=&script_usbhotplug=if [ "1" != "2" ];&_http_id=TID6bcc9ae115494e0
     
  12. chrisls

    chrisls Reformed Router Member

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice