Go Back   The UNIX and Linux Forums > Special Forums > Infrastructure Monitoring
Search Forums:



Infrastructure Monitoring Forum for Nagios, Zabbix and other network monitoring and management tools.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #15  
Old 09-23-2003
Perderabo's Avatar
Unix Daemon (Adminstrator Emeritus)
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,679
Thanks: 26
Thanked 237 Times in 147 Posts
Do you have ksh available?
    #16  
Old 09-23-2003
Registered User
 

Join Date: Sep 2003
Location: Paris
Posts: 181
Thanks: 1
Thanked 0 Times in 0 Posts
Doing this install , you need "root" rights , i'm onlu user !!

christian
    #17  
Old 09-23-2003
Registered User
 

Join Date: Sep 2003
Location: Paris
Posts: 181
Thanks: 1
Thanked 0 Times in 0 Posts
Yes i have "ksh"

christian
    #18  
Old 09-23-2003
Perderabo's Avatar
Unix Daemon (Adminstrator Emeritus)
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,679
Thanks: 26
Thanked 237 Times in 147 Posts
OK, when I have some time I'll experiment with ksh. I think I might be able to use a telnet coprocess to allocate the pty.
    #19  
Old 09-23-2003
Perderabo's Avatar
Unix Daemon (Adminstrator Emeritus)
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,679
Thanks: 26
Thanked 237 Times in 147 Posts
No money back guarantees on this one. But I tested it on both HP-UX and SunOS and it works for me.
Code:
#! /usr/bin/ksh

#  changepass --- change the user's password on a list of hosts
#  perderabo  9/23/03  Version 0.0
#
#  You will need to adjust HOSTLIST.  You may need to adjust DELAY
#  and all of section 2.
#


#
#  Section 0 --- Set stuff up

HOSTLIST="test1 test2"
DELAY=3
stty -echo
print -n Enter Old Password-
read OLDPASS
print 
print -n Enter New Password-
read NEWPASS
print
stty echo
USER=$(whoami)
exec 4>&1


#
#  Section 1 --- Prove that we can talk with the hosts in HOSTLIST
#     Part 1 --- telnet to each and touch a file

for HOST in $HOSTLIST ; do
	telnet $HOST >&4 2>&4 |&
	sleep $DELAY
	print -p $USER
	sleep $DELAY
	print -p $OLDPASS
	sleep $DELAY
	print -p touch changepassdatafile.$HOST
	sleep $DELAY
	print -p exit
	wait
done

#
#  Section 1 --- Prove that we can talk with the hosts in HOSTLIST
#     Part 2 --- Retrieve the files via ftp

ftp -nv >&4 2>&4 |&
for HOST in $HOSTLIST ; do
	print -p open $HOST
	print -p user $USER $OLDPASS
	print -p get changepassdatafile.${HOST}
	print -p close
done
print -p bye
wait

#
#  Section 1 --- Prove that we can talk with the hosts in HOSTLIST
#     Part 3 --- Inspect the retrieved files

errors=0
for HOST in $HOSTLIST ; do
	if [[ -f changepassdatafile.${HOST} ]] ; then
		echo $HOST was ok
		rm changepassdatafile.${HOST}
	else
		echo $HOST has a problem
		((errors=errors+1))
	fi
done
((errors)) && exit 1

#
#  Section 2 --- Change the passwords

for HOST in $HOSTLIST ; do
    telnet $HOST >&4 2>&4 |&
    sleep $DELAY
    print -p $USER
    sleep $DELAY
    print -p $OLDPASS
    sleep $DELAY
    print -p passwd
    sleep $DELAY
    print -p $OLDPASS
    sleep $DELAY
    print -p $NEWPASS
    sleep $DELAY
    print -p $NEWPASS
    sleep $DELAY
    print -p exit
    wait
done

#
#  Section 3 --- Verify that the passwords were changed
#     Part 1 --- Retrieve those files via ftp again

ftp -nv >&4 2>&4 |&
for HOST in $HOSTLIST ; do
    print -p open $HOST
    print -p user $USER $NEWPASS
    print -p get changepassdatafile.${HOST}
    print -p delete changepassdatafile.${HOST}
    print -p close
done
print -p bye
wait

#
#  Section 3 --- Verify that the passwords were changed
#     Part 2 --- Inspect the retrieved files

errors=0
for HOST in $HOSTLIST ; do
    if [[ -f changepassdatafile.${HOST} ]] ; then
        rm changepassdatafile.${HOST}
    else
        echo $HOST has a problem!
        ((errors=errors+1))
    fi
done
((errors)) && exit 1


exit 0

    #20  
Old 09-24-2003
Registered User
 

Join Date: Sep 2003
Location: Paris
Posts: 181
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks for your help ,

i will test this script as soon as possible and tell you in return !

christian
    #21  
Old 09-24-2003
davidg's Avatar
Registered User
 

Join Date: Jul 2003
Location: Holland
Posts: 207
Thanks: 0
Thanked 1 Time in 1 Post
Real great work Perderabo !!!

This is the kind of script I like to keep a copy of

Thanks a lot for all the work. I don't understand the 4> yet, but I'll probably find out somewhere.

Regs David
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with expect script somedude Shell Programming and Scripting 4 06-04-2009 12:39 PM
Need Help with EXPECT script markus2008 UNIX for Advanced & Expert Users 5 03-12-2008 07:49 PM
help with 'expect' script? maeve Shell Programming and Scripting 0 06-02-2004 06:18 PM
Expect Script HELP zuinc Shell Programming and Scripting 2 04-30-2002 09:42 AM
'expect' tool shaggy UNIX for Dummies Questions & Answers 2 09-27-2001 02:54 PM



All times are GMT -4. The time now is 12:44 AM.