User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,432 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,619 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1873 | Replies: 0
Reply
Join Date: Aug 2007
Posts: 1
Reputation: StingRay411 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
StingRay411 StingRay411 is offline Offline
Newbie Poster

Help ksh scripting

  #1  
Aug 17th, 2007
I have found a script which does password changes on multiple machines without installing additional packages which is what I need. Problem is it uses telnet and ftp. I need to modify this to use ssh and scp. Any help greatly appreciated.

Thanks

#! /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
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC