Changing daemon password Transmission 2.42

Ask for help and report issues not specific to either the Mac OS X or GTK+ versions of Transmission
Post Reply
Random
Posts: 4
Joined: Sun Feb 19, 2012 11:33 pm

Changing daemon password Transmission 2.42

Post by Random »

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?
Random
Posts: 4
Joined: Sun Feb 19, 2012 11:33 pm

Re: Changing daemon password Transmission 2.42

Post by Random »

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 :(
Random
Posts: 4
Joined: Sun Feb 19, 2012 11:33 pm

Re: Changing daemon password Transmission 2.42

Post by Random »

#!/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
gunzip
Posts: 272
Joined: Wed May 05, 2010 2:12 am

Re: Changing daemon password Transmission 2.42

Post by gunzip »

it doesn't look like your script ever writes the changes to the file, it just gives screen output. maybe try this instead..

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
above uses bash's sed in-place substitution
Random
Posts: 4
Joined: Sun Feb 19, 2012 11:33 pm

Re: Changing daemon password Transmission 2.42

Post by Random »

Aha, that worked :D tyvm
Post Reply