D
D
DILYAR2018-02-11 02:30:14
linux
DILYAR, 2018-02-11 02:30:14

How to automatically change the password in the config?

Hello. There is a game server and I need to somehow automatically change one parameter in the config. For example, there is a variable rcon "faufI21FA"
faufI21FA - a password that needs to be changed randomly. Tell me the bash code so that I can specify the path to the txt file in which I need to write a random password in "". For example, I have this rcon.sh script in root, and the txt file is in /home/server/config.txt. So that I enter sh rcon.sh and the password faufI21FA is replaced with any other. I hope you understand me))
----------
You need a random pass and so that the new pass can also be replaced. I want to do it through cron so that every 30 minutes a variable in the
rcon "faufI21FA" config changes for example to rcon "VFyffa21" and this one to rcon "FGVsa24" and so on

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2018-02-11
@Stalker_RED

#!/bin/bash
newpass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
sed -i.bak "s/^rcon .*$/rcon $newpass/" /path/to/myconfig.cfg

L
LeoCata, 2018-02-11
@LeoCata

pass=$(/urandom tr -dc '[email protected]#^&)(*%KMNP-Za-hjk5-9mnp-z1-9' | head -c8)
sed -i 's/rcon. */rcon '${pass}'/g' /home/server/config.txt

S
Saboteur, 2018-02-11
@saboteur_kiev

Use sed Luke.
But it is better to replace the string with the password through a regular expression.
For example like this:

NEWPASSWORD=$(date +%s | sha256sum | base64 | head -c 10)
sed -i "s/rcon_password=.*/rcon_password=${NEWPASSWORD}/g" config.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question