Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I need someone please to provide me with shell/bash script that reset users' passwords. this script should read the usernames list from a file and the passwords list from another file. the usernames and passwords files format is entry per line.
I am not that good in writing scripts. I think I need two nested loops.
I tried that before a long time but it didnt work. now I need it urgently and quickly because that I posted it here now.
Using two nested loops is more difficult, since you have to read both files one line at a time. You can previously merge the two files side by side, then read the two fields in a single while loop. You can also do this on the fly. Suppose you have two files called users and passwd:
Why does this sound like a homework assignment Anyway, to add to colucix's excellent advice, use an expect script to actually change the password. If you don't have it, use the package management utility for your distro and install it.
Once that's done, create an expect script called changepw.exp as follows:
Good call, kenoshi. However I think the --stdin option of passwd is enough. I would try something like
Code:
echo "$passwd" | passwd --stdin "$user"
It should work fine as well.
Just a side note: if the passwords contain some special characters, most likely they must be escaped. For example a literal backslash \ should be escaped with another backslash \\ so that the script can interpret it correctly.
after using the merged file, how can I extract from each line the username and password and put them on two different place holders in order to use them in echo "$passwd" | passwd --stdin "$user"
I guess we may need to use awk, is that right?? I would appreciate if you send me the complete script
well if you aren't tied to an actual shell script perl has modules on cpan for modifying password entries and I'm pretty sure python has something similar.
Hi, Rahmad and the rest:
I am, in fact, totally newbie to linux. I'm trying to add a bunch of users using scripts but I got stuck setting users' password via script and I found this thread. Could you please be more specific on your code? Is that a .sh file? Did you use a separate files or a single one for the user/pass pairs?
Thanks beforehand,
Gux.
Quote:
Originally Posted by rahmad
thanks, its done now
but you made a mistake when you put -d\ in done < <(paste -d\ users passwd)
for all newbie this is the complete script:
while read user passwd
do
echo "$passwd" | passwd --stdin "$user"
done < <(paste user passwd)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.