bash scripting question

  • hallo

    I've the following problem while bash scripting (my nightly download script)

    I need for an date comparison to convert a file of dates.

    initial date format is "Sun, 03 Jul 2022 02:35:26 GMT" and should be converted to format: 202207030435.

    let say the file is named "dates"

    the following for loop doesn't work cause of the blanks in each line:

    for i in $(cat dates); do date -d $i '+%Y%m%d%H%M'; done.

    How to read the file line by line without stumbling over the blanks in the lines.

    trying to put ' or " in front and at the end of each line doesn't work out ...

    Edited once, last by GDPR-7 (July 4, 2022 at 2:09 AM).

  • CvH

    chewitt

    I'm trying to adjust my script for the coming new server structure:

    https://test3.libreelec.tv/11.0/Generic/

    I now want to avoide some shortages/mistakes [*] of my old script, where I were unable to exactly get what's an update/downgrade.

    so the new script version should work with the field "mtime" (see attached file, it's pre-filtered output from command: curl -s https://test3.libreelec.tv/json/11.0/Generic/)

    to be able to compare the mtime fields I need to convert the date/time string to a form allowing to do integer comparison

    this should be the target format : 202207020834. (CCYYMMDDHHMM)

    my first draft is

    - to create a temporary list of only the mtime strings

    - read the list and convert the mtime string to the above target format

    - do the comparsions

    - notice the next nightly what is elder/newer then the running one

    - (unsure) convert back to the mtime string and grep that mtime string in the list ...

    - download the found nightly and it's sha256 (unsure if needed, cause -AFAIK- the update installer does already a check summing)

    ...

    the problem now are:

    a) read the above temporary file containing the mtime strings for conversion *without* stumbling over blanks the strings contain

    my attempt to fix: set IFS="

    or as I now see via CvH suggestion

    b) doing so I 'll up to now get a additional date, cause -my guess - bash read commands from the right to left, so I get one more date (the current date) then mtime strings are in file

    How to avoid that ???

    [*]

    the "build date-git hash", form 20220623-a81b6d9 doesn't in all cases allow to figure the correct nightly for update/downgrade.

    thinks of builds with same date and different git hash, e.g. builds from 5:00 and 19:00

    converted mtime string seems the way to go and saves me a lot of logical brainer's to get it better as in my current script V0.08

    ===

    other question:

    is there a way to do an inline conversations during an output of awk ?

    let say, I've a file named out-von-JSON containing this:

    { "name":"LibreELEC-Generic.x86_64-11.0-nightly-20220628-f7f28a7.img.gz", "type":"file", "mtime":"Tue, 28 Jun 2022 18:07:28 GMT", "size":221226619 },

    to get the mtime string field I would do the following:

    cat out-von-JSON|grep -v sha256 | grep -v Generic.x|awk -F '"mtime":' '{print $2}'|cut -d '"' -f2

    => Tue, 28 Jun 2022 18:07:28 GMT

    Am I able to do inline conversation for the awk part '{print $2}' ?

    - it's 30 years ago I learned Unix -

  • I'm afraid our busybox date is not able to parse human readable dates after you get the whole line:

    Code
    Recognized TIME formats:
        hh:mm[:ss]
        [YYYY.]MM.DD-hh:mm[:ss]
        YYYY-MM-DD hh:mm[:ss]
        [[[[[YY]YY]MM]DD]hh]mm[.ss]
        'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
  • Thanks ${All}

    I build my own converter and picked the parts with awk, etc, out of the string "Sun, 03 Jul 2022 02:35:26 GMT" to get the [YY]YY]MM]DD]hh]mm format

    one question left:

    why do all nightlies decompress to ~549 MB (in an terminal, in nautilus:~576) even when the compressed size varies (Generic:~211, Generic-legacy: ~274 , RPi*: ~122)

    and

    is there a sort of warranty that it always be ~549 ?

    mglae

    last time you pointed me to piece of code, but I couldn't get why the decompressed size is/seems always the same:

    LibreELEC.tv/mkimage at c8a2d1c81793ad7951d0f9f6ac55ec31524cdadf · LibreELEC/LibreELEC.tv
    Just enough OS for KODI. Contribute to LibreELEC/LibreELEC.tv development by creating an account on GitHub.
    github.com

    what I don't know are the values in line 16 !

    ${SYSTEM_SIZE} and ${SYSTEM_PART_START}

  • is there a sort of warranty that it always be ~549 ?

    Yes. I'm not aware that free space is short on any platform and need to be increased. BTW: 549MiB = 549*2^20 B

    last time you pointed me to piece of code, but I couldn't get why the decompressed size is/seems always the same:

    Because the empty image is created this size: https://github.com/LibreELEC/Libr…pts/mkimage#L52

    what I don't know are the values in line 16 !

    ${SYSTEM_SIZE} and ${SYSTEM_PART_START}

    LibreELEC.tv/options at c8a2d1c81793ad7951d0f9f6ac55ec31524cdadf · LibreELEC/LibreELEC.tv
    Just enough OS for KODI. Contribute to LibreELEC/LibreELEC.tv development by creating an account on GitHub.
    github.com