Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37575642
en ru br
ALT Linux repos
S:5.45.4-alt4
5.0: 5.44-alt3
4.1: 5.44-alt2
4.0: 5.43-alt3
3.0: 5.43-alt1

Other repositories
Upstream:5.44.1

Group :: Development/Tcl
RPM: expect

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

#!/usr/bin/tclsh
# $Id: autopasswd.expect,v 1.6 1999/08/27 19:39:18 moniot Exp $
# Wrapper to run passwd(1) non-interactively
# Usage: autopasswd username password
# or echo " username password" | autopasswd
# Returns code 0 if successful, nonzero otherwise (bad password)
#
# Author: R. Moniot, based on simpler version found in expect distribution
# Date: 27 August 1999

package require Expect

if "$argc > 0" {

# Get username and password from commandline if present.

set username [lindex $argv 0]
set password [lindex $argv 1]
} else {

# Otherwise read username and password from stdin: they must be separated
# by exactly one blank space and contain no blanks themselves.

expect_user {
-re "(.*) (.*)" {
set username $expect_out(1,string);
set password $expect_out(2,string)
}
}
}

spawn passwd $username

# The sleep is needed to give passwd time to get ready.
expect {
"password:" { sleep 1; send -- "$password\r" } # send
}

expect {
"BAD PASSWORD:*" { exit 1 }
"password:" { sleep 1; send -- "$password\r" } # resend
}

expect {
"successfully" { exit 0 } # OK (Linux flavor)
eof { exit 0 } # OK (AIX flavor)
timeout { exit 2 } # something went wrong
}

exit 0
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin