Results 1 to 6 of 6

Thread: generate random number inset into text file

  1. #1
    Join Date
    Nov 2019
    Beans
    17

    generate random number inset into text file

    Hello all.

    I'm trying to generate a random number between 1/2147483647 and insert/replace an existing number within a text file
    I just cant get it to work ?

    Code:
    newseed=$((1 + RANDOM*RANDOM % 2147483647))
    sed -i -e '17c\seed="'"$newseed"'"' /home/test/lgsm/config-lgsm/rustserver/rustserver.cfg
    The file is located at ~ /home/test/lgsm/config-lgsm/rustserver/rustserver.cfg
    and within that file i have a filed called seed=""

    Code:
    ip="xx.xx.xx.xx"
    port="28017"
    rconport="28018"
    appport=28083
    rconpassword=""
    rconweb="1" # Value is: 1 for the Facepunch web panel, Rustadmin desktop and Rustadmin Online; 0 for RCON tools like Rusty.
    servername="test"
    maxplayers="1"
    salt="" # range: unknown, used to recover a known setting from an existing map.
    worldsize="3000" # default: 3000, range: 1000-6000, map size in meters.
    saveinterval="300" # Auto-save in seconds.
    tickrate="30" # default: 30, range: 15-100.
    seed="2042821"
    I want to be able to run a cronjob that will change this value in the text file, currently i do this manually

    Thanks for any pointers!
    Last edited by youmustnot; February 27th, 2021 at 12:01 PM.

  2. #2
    Join Date
    Jun 2018
    Beans
    163

    Re: generate random number inset into text file

    Arithmetic expression look wrong, try:

    Code:
    newseed=$((1 + (($RANDOM * $RANDOM) % 2147483647)))
    Have a ubuntastic day!

  3. #3
    Join Date
    Nov 2019
    Beans
    17

    Re: generate random number inset into text file

    thanks for your help. I have made the changes however It still fails to write to the file

    Code:
    newseed=$((1 + (($RANDOM * $RANDOM) % 2147483647)))
    sed -i -e '17c\seed="'"$newseed"'"' /home/rust5/lgsm/config-lgsm/rustserver/rustserver.cfg

  4. #4
    Join Date
    Jun 2018
    Beans
    163

    Re: generate random number inset into text file

    Try this then:

    Code:
    sed -i 's/seed=.*/seed="'$newseed'"/' /path/to/file.txt
    Have a ubuntastic day!

  5. #5
    Join Date
    Nov 2019
    Beans
    17

    Thumbs up Re: generate random number inset into text file

    hey dinkidonk

    Thanks for that it's working as expected now

  6. #6
    Join Date
    Jun 2018
    Beans
    163

    Re: generate random number inset into text file

    Great! Please mark the thread as solved..
    Have a ubuntastic day!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •