Hello, I'm using ubuntu and running Transmission 2.42, I have a bash script that stops the transmission service, modifies the password in the settings.json file and the restarts the service, however the settings.json just reverts immediately back to the old password :/
Any ideas as to why and what I'm doing wrong?
Changing daemon password Transmission 2.42
Re: Changing daemon password Transmission 2.42
Yeah, before the daemon is restarted it grabs and echos the settings.json file with the new password nicely where it should be, then it starts the daemon and re-echos the file with the old password back
Re: Changing daemon password Transmission 2.42
#!/bin/bash
if [ $# -ne 1 ]; then
echo "usage: ${0##*/} <username>"
exit
fi
user="${1}"
sv -v down "/service/transmission-daemon.$user";
base_dir="/var/lib/transmission-daemon"
user_dir="${base_dir}.${user}"
user_conf="${user_dir}/info/settings.json"
read password
new_line=' "rpc-password": "'$password'",'
perl -pe "s/.*/$new_line/ if $. == 48" < $user_conf #outputs new file with new pass (dosen't seem to save though?)
newPass=`grep -i "rpc-password" "$user_conf"`
#echo $new_line
echo $newPass #echos same old pass
echo $new_line #echos new pass
echo "$(tput setaf 2)Pass for user $user changed to $password $(tput sgr0)"
sv -v up "/service/transmission-daemon.$user";
sv -v term "/service/transmission-daemon.$user";
sv -v hup "/service/transmission-daemon.$user";
newPass2=`grep -i "rpc-password" "$user_conf"` #echos same old pass once again
echo $newPass2
if [ $# -ne 1 ]; then
echo "usage: ${0##*/} <username>"
exit
fi
user="${1}"
sv -v down "/service/transmission-daemon.$user";
base_dir="/var/lib/transmission-daemon"
user_dir="${base_dir}.${user}"
user_conf="${user_dir}/info/settings.json"
read password
new_line=' "rpc-password": "'$password'",'
perl -pe "s/.*/$new_line/ if $. == 48" < $user_conf #outputs new file with new pass (dosen't seem to save though?)
newPass=`grep -i "rpc-password" "$user_conf"`
#echo $new_line
echo $newPass #echos same old pass
echo $new_line #echos new pass
echo "$(tput setaf 2)Pass for user $user changed to $password $(tput sgr0)"
sv -v up "/service/transmission-daemon.$user";
sv -v term "/service/transmission-daemon.$user";
sv -v hup "/service/transmission-daemon.$user";
newPass2=`grep -i "rpc-password" "$user_conf"` #echos same old pass once again
echo $newPass2
Re: Changing daemon password Transmission 2.42
it doesn't look like your script ever writes the changes to the file, it just gives screen output. maybe try this instead..
above uses bash's sed in-place substitution
Code: Select all
cat $user_conf # echo file before change
read password
sed -i -e "s/.*rpc-password.*/ \"rpc-password\": \"$password\",/" $user_conf
cat $user_conf # echo file after change
Re: Changing daemon password Transmission 2.42
Aha, that worked tyvm