我有两个文件。File1包含用户名和密码,如下所示:
[reader]
label = anylabel
protocol = cccam
device = some.url,13377
user = Username1
password = password1
password2 = password2
inactivitytimeout = 30
group = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
cccversion = 2.3.2
ccckeepalive = 1File2包含如下一行:
http://link:port/username/password/12345现在我有了这个“代码”来更改File2中的用户名/密码
UsernameOLD=Username1
PasswordOLD=password1
UsernameNEW=Username2
PasswordNEW=password2
sed -i -e "s/\/$UsernameOLD\/$PasswordOLD/\/$UsernameNEW\/$PasswordNEW/" /etc/enigma2/file2.cfg现在我有了不同的用户名,它们总是在File1中更新。现在我正在寻找一个解决方案,将用户名和Password2从File1写入一个变量,然后在File2中设置这个新的用户名和密码。
因此,作为菜鸟,psuedocode应该是这样的:
find "username" & "password1" in file1
set "username" as $UsernameNEW and
"password1" as $PasswordNEW and
then just execute my sed command.有人能帮忙吗?我想我可以用grep来做这个?但是老实说,我很高兴我得到了这个带有变量的sed命令:D
发布于 2021-08-14 14:42:49
这里有一些可以让你开始。
oscam.conf
[reader]
label = anylabel
protocol = cccam
device = some.url,13377
user = xxx1
password = password1
inactivitytimeout = 30
group = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
cccversion = 2.3.2
ccckeepalive = 1
[reader]
label = anylabel
protocol = cccam
device = test.url,13377
user = yyy1
password = password1
inactivitytimeout = 30
group = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
cccversion = 2.3.2
ccckeepalive = 1对于密码文件,我已经更改了一些格式,但可以使用原始格式。
passwd (格式oldUser,newUser,oldPass,newUser)
xxx1,xxx2,passxxx1,passxxx2
yyy1,yyy2,passyyy1,passyyy2Awk命令
awk -F, 'FNR==NR {usr[$1]=$2;pass[$1]=$4;next} FNR!=NR{FS=" = "} /^user/ {t=$2;$2="= "usr[$2]} /^password/ {$2="= "pass[t]} 1' passwd oscam.reader结果
[reader]
label = anylabel
protocol = cccam
device = some.url,13377
user = xxx2
password = passxxx2
inactivitytimeout = 30
group = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
cccversion = 2.3.2
ccckeepalive = 1
[reader]
label = anylabel
protocol = cccam
device = test.url,13377
user = yyy2
password = passyyy2
inactivitytimeout = 30
group = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
cccversion = 2.3.2
ccckeepalive = 1发布于 2021-08-15 22:43:36
快速和肮脏--将旧密码加载到环境参数中:
set -- $(grep -m1 -A1 '^user' File1)
sed -i -e "s#/${UsernameOLD}/${PasswordOLD}#/$3/$6#;T;q" /etc/enigma2/file2.cfg工作原理:grep输出六个空格分隔的项,set将其转化为命令行参数$1 $2 $3 ... $6。我们只需要$3和$6。
https://stackoverflow.com/questions/68781544
复制相似问题