T tmw May 31, 2009 #1 Hello, I have a question how can i change user password in bash script, this doest work (i run this script as root): Code: #!/usr/local/bin/bash $(passwd foo) <<EOF pass pass EOF Is it possible to do this via bash script?
Hello, I have a question how can i change user password in bash script, this doest work (i run this script as root): Code: #!/usr/local/bin/bash $(passwd foo) <<EOF pass pass EOF Is it possible to do this via bash script?
vivek Jun 1, 2009 #2 Read pw command man page and look for -h FD option. Add user called foo and set password to BAR Code: echo BAR | pw add user foo -h 0 To modify password for existing user called tom: Code: echo jerry | pw mod user tom -h 0
Read pw command man page and look for -h FD option. Add user called foo and set password to BAR Code: echo BAR | pw add user foo -h 0 To modify password for existing user called tom: Code: echo jerry | pw mod user tom -h 0
OP T tmw Jun 1, 2009 Thread Starter #3 Thx for this. But i need this via passwd :/. In other words i need to type a password via script. But script must be non parametrs.
Thx for this. But i need this via passwd :/. In other words i need to type a password via script. But script must be non parametrs.
rhyous Jun 8, 2009 #5 Post an example of your script when you are done so it can be available for others.
OP T tmw Jun 20, 2009 Thread Starter #6 Hi, sorry for a big delay. This script will set password by passwd without user interaction: Code: #!/usr/local/bin/bash LOG=tomek PASS=haslo1 expect << EOF spawn passwd $LOG expect "New Password:" send "${PASS}\r" expect "Retype New Password:" send "${PASS}\r" expect eof; EOF This will set password "haslo1" for user "tomek".
Hi, sorry for a big delay. This script will set password by passwd without user interaction: Code: #!/usr/local/bin/bash LOG=tomek PASS=haslo1 expect << EOF spawn passwd $LOG expect "New Password:" send "${PASS}\r" expect "Retype New Password:" send "${PASS}\r" expect eof; EOF This will set password "haslo1" for user "tomek".
V VictorM Dec 29, 2009 #7 tnx for the script - I could use this to deploy NAS boxes unattended, smart trick...