需要在文本文件中更新新密码

时间:2015-06-23 07:01:56

标签: linux shell

我有大约100个文件需要根据linux服务器中不同位置文件中的不同用户更新新密码。

那么,是否有任何常见的shell脚本可以根据用户名从旧密码更新为新密码。

请查看下面的文件内容“Resource driverClassName =”com.mysql.jdbc4.jdbc.sysdert“name =”jdbc / ryr_ined“type =”sql.DataSource“url =”jdbc:mysql:xyz .com:1025 / weare“username =”xyz“password =”abcd“autoCommit =”false“maxActive =”20“maxIdle =”10“maxWait =”20000“”和“资源名称=”Tkmool“用户名=”weare “password =”abcd“maxActive =”20“maxIdle =”10“maxWait =” - 1“”

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

这是你在寻找什么?

read -p "path (eg. *.conf will match a.conf)?" path
read -p "username?" username
read -p "new password?" password 
find $path -exec sed -r "s/(username="${username}".*password=)\w*/\1"${password}"/g" \{} >temporaryPasswordFile.tmp \; -exec mv temporaryPasswordFile.tmp \{} \;

要求不存在名为temporaryPasswordFile.tmp的文件。