I'm quite new in the linux world. I've got a file containing Usernames and Passwords, for browser authentications. eg.:

user:ioeuwz5rf (Password generated with "openssl passwd ABCXYZ")

Now, I want these passwords to get changed automatically every week or whatever.

I tried it with a change.sh file containing:

newpw="`openssl passwd ABCXYZ`"
sed -i 's/WhatToReplace/'$newpw'/g' test.txt

This would replace the word "WhatToReplace" with the generated pw. But I want to do it automatically. Is there a way to replace the 2nd part (user:ioeuwz5rf) with the random password.

I want a new random password generated for every user, and this should be saved into a file (newpw.txt eg.) from which I can generate mails.

1 Answer 1


Instead of replacing all lines in newpw.txt, it would be better to create a new file by iterating over the usernames in the old one, for example:

cut -d: -f1 pw.txt | while read -r user; do
    echo "$user:$(openssl passwd ABCXYZ)"
done > newpw.txt
mv newpw.txt pw.txt
  • 1
    In addition, i think the mention of cron must be here. If author want to really automate the process, he should meet with cron and crontab.
    – ValeriyKr
    Commented Jan 5, 2017 at 23:52
  • Thank you, i just have another few questions, may you can help there as well? For sure i would run it with a Cronjob :)
    – Manu_H
    Commented Jan 6, 2017 at 12:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .