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

Script won't run !

Discussion in 'Tomato Firmware' started by yaqui, Jun 13, 2007.

  1. yaqui

    yaqui LI Guru Member

    Script won't run ! - under jffs

    I put my script in /jffs/reconnect/reconnect.sh

    this is under init:
    sleep 5
    cru a macrestart "00 05 * * * /jffs/reconnect/reconnect.sh"

    All that is in the file reconnect.sh is:
    #!/bin/ash
    killall -hup pppoecd

    I also did chmod 755 to the file

    When I check the log, it shows it sent the command 'reconnect.sh' at 5am but nothing else, like nothing ever reconnected.

    Edit: edited my typo.
     
  2. roadkill

    roadkill Super Moderator Staff Member Member

    try this as the header
    #!/bin/sh or #!/bin/ash
     
  3. yaqui

    yaqui LI Guru Member

    It was #!/bin/ash and still nothing. Sorry for typo in post
     
  4. roadkill

    roadkill Super Moderator Staff Member Member

    try -HUP instead of -hup
     
  5. yaqui

    yaqui LI Guru Member

    when i do ./reconnect.sh in the shell to run it,
    it keeps saying " -sh: ./reconnect.sh: not found"

    I am in it's directory and ls shows it's there.... why can't I run it ?? I gave it chmod 755 what is wrong ?
     
  6. roadkill

    roadkill Super Moderator Staff Member Member

    tried to run from cifs...?
     
  7. yaqui

    yaqui LI Guru Member

    why would I want to try to run it from there?

    Shouldn't it run straight from the command line in telnet?
     
  8. roadkill

    roadkill Super Moderator Staff Member Member

    because jffs can have mounting permissions which don't allow execution
    and from the cifs mounting script from the gui I know it's working.
     
  9. mraneri

    mraneri LI Guru Member

  10. yaqui

    yaqui LI Guru Member

    Mike, thanks for your examples !! Where did you learn how to do all that scripting? nice..
     
  11. yaqui

    yaqui LI Guru Member

    I assume you can just keep adding commands to the file in RAM like this??

    Code:
    echo -e "#!/bin/sh\ncommand here" > /tmp/scriptfilename.sh
    echo -e "#!/bin/sh\ncommand here" > /tmp/scriptfilename.sh
    echo -e "#!/bin/sh\ncommand here" > /tmp/scriptfilename.sh
    echo -e "#!/bin/sh\ncommand here" > /tmp/scriptfilename.sh
    echo -e "#!/bin/sh\ncommand here" > /tmp/scriptfilename.sh
    echo -e "#!/bin/sh\ncommand here" > /tmp/scriptfilename.sh
    
    And it will run all those commands sequentially you put in there ??

    Thanks for your help
     
  12. yaqui

    yaqui LI Guru Member

    what if you are using nvram set variable = "variable"

    Do you use double quotes?
    Like this?
    echo -e "#!/bin/sh\nnvram set somevariable="variablex""

    Or what is proper way?
     
  13. mraneri

    mraneri LI Guru Member

    Nope.

    I think you realize, this echo stuff is just creating an ordinary text file...

    echo -e "something here" > filename

    puts "something here" in the file. the "\n" is like a new-line. If you want to append, you could use >>. This appends the stuff in "" to the existing file. Also, you put the #!/bin/sh on the first line of the script only...

    So, this would work as intended..
    Code:
    echo -e "#!/bin/sh" > /tmp/scriptfilename.sh
    echo -e "command here" >> /tmp/scriptfilename.sh
    echo -e "command here" >> /tmp/scriptfilename.sh
    echo -e "command here" >> /tmp/scriptfilename.sh
    echo -e "command here" >> /tmp/scriptfilename.sh
    echo -e "command here" >> /tmp/scriptfilename.sh
    
    Don't forget, you still have to chmod or it won't execute.
     
  14. mraneri

    mraneri LI Guru Member

    Not sure much about nvram stuff. I do know, that because " character are special, you have to do special tricks to have them echo to the file correctly.

    i.e. you can use \n to insert a new line into the file. You can use \" to insert a quote into the file... So, perhaps you can do:

    Code:
    echo -e "#!/bin/sh\nnvram set somevariable=\"variablex\""
    You don't want to be writing to NVRAM too often, though. NVRAM can wear out if you commit changes too many times. (Well 10's of thousands, but in a script that executes hourly, this adds up...) Hence my avoidance of JFFS.

    For more scripting ideas, lookup "Bourne Shell scripting" in your favorite search engine and start reading. Also, recognize that these lite Linux OS's that run on our routers are not as powerful and as feature full as PC's running linux. telnet into your router and try this stuff out.

    (Though I'm not responsible if you screw up your router!)


    - Mike
     
  15. yaqui

    yaqui LI Guru Member

    Nvram set does not write to nvram... I think only nvram commit does?

    If I reboot after nvram set, the settings go will away? so I assume it doesn't get written? not sure...
     
  16. mraneri

    mraneri LI Guru Member

    I believe you are correct. I wasn't sure if you were using nvram commit later on in your script. Note, if you change settings in your router through the GUI, stuff changed from your script will be committed...
     

Share This Page