Se você realmente quiser seguir esse caminho e não houver um parâmetro passwd , poderá usar este Espere roteiro:
#!/usr/bin/env expect -f
set old_timeout $timeout
set timeout -1
stty -echo
send_user "Current password: "
expect_user -re "(.*)\n"
set old_password $expect_out(1,string)
stty echo
send_user "\nNew password: "
expect_user -re "(.*)\n"
set new_password $expect_out(1,string)
set timeout $old_timeout
spawn passwd
expect "password:"
send "$old_password\r"
expect "password:"
send "$new_password\r"
expect "password:"
send "$new_password\r"
expect eof
Como funciona:
[dave@hal9000 ~]$ ./passwd.tcl
Current password:
New password: bowman
spawn passwd
Changing password for user dave.
Changing password for dave.
(current) UNIX password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Este shell script também pode funcionar (testado no Fedora 20 com bash-4.2.47-2 e passwd-0.79-2):
#!/bin/sh
stty -echo
echo -n "Current password: "
read old_password
stty echo
echo
echo -n "New password: "
read new_password
passwd << EOF
$old_password
$new_password
$new_password
EOF
Como funciona:
[dave@hal9000 ~]$ ./passwd.sh
Current password:
New password: bowman
Changing password for user dave.
Changing password for dave.
(current) UNIX password: New password: Retype new password: passwd: all authentication tokens updated successfully.