Tomato router "can't create =: Read-only file system"

Discussion in 'Tomato Firmware' started by dauntingearth, Mar 21, 2014.

  1. dauntingearth

    dauntingearth Reformed Router Member

    Hi I am trying to set up a script in Tomato router that when it runs it will echo a value dependent on the hour. Script written as follow:
    Code:
    HOUR=$(date +"%k")
    
    if [[ $HOUR >= 0 ] && [ $HOUR < 12 ]];then
        echo 'Morning'
    else
        echo 'Evening'
    fi
    However when I execute the script, the following returned:
    Code:
    /tmp/.wxNL0Yv3: line 11: can't create =: Read-only file system
    Evening 
    How to fix it? I am pretty sure I did not ask for an access to any Read-only files
     
  2. darkknight93

    darkknight93 Networkin' Nut Member

  3. koitsu

    koitsu Network Guru Member

    Your if statement is syntactically incorrect, resulting in the interpreter trying to write data to a file called "=" in whatever the cwd (current working directory) is.

    Secondly, understand that the shell environment under Tomato/TomatoUSB by default is Busybox's shell called ash. It tries to be "bash-like" but has many nuances/differences. There is no manual (thank you Busybox folks *sigh*), so it's recommended you try following the Debian ash manual instead; it's as close as you're gonna get.

    Your code should be changed as follows:

    Code:
    HOUR=$(($(date +%k)))
    
    if [[ $HOUR -ge 0 -a $HOUR -lt 12 ]]; then
        echo 'Morning'
    else
        echo 'Evening'
    fi
    
    Things to note:

    1. The HOUR assignment now looks scary, but what it's doing is setting the HOUR variable itself to an actual integer/numeric (vs. a string) using $(( )). Then for the actual value, it uses whatever date +%k returns. Which leads me to...

    2. Your if statement being wrong. > and < for numeric comparisons should be -ge (greater-than-equals) and -lt (less-than). If you were to use > and < on a non-numeric you'd end up doing something very very different than what you expect). Additionally, to add a logical AND, you use -a. All of this is covered in the test man page (or the test section of the above Debian ash page.

    3. I strongly recommend getting in the habit of putting a space after your semicolons, i.e. ]]; then not ]];then. The Busybox ash parser will throw you for a loop (i.e. give you trouble) sometimes.

    Just an FYI: be aware that the % expandos for date on Tomato/TomatoUSB due to use of uClibc, are somewhat different compared to what you might be used to on a "normal" Linux box. The man page for strftime applies "sort of"; some of the expandos are different, and some don't exist at all. Just be aware of this when using date on Tomato/TomatoUSB.

    Finally: for general scripting help, you should really ask folks on the Busybox mailing lists. I understand you're writing a script "on Tomato", but Tomato uses Busybox, and this forum really isn't a "how do I write shell scripts" forum per se. I say that respectfully, no judgement (yes I'm aware of other users having long-standing threads talking about shell scripts here). I just mean to say that the forum here is mainly about Tomato/TomatoUSB as in the firmware, not about Busybox directly.
     
  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