FW: SUMMARY: Script for changing the password

From: Koul, Minoti <koulmin_at_ugs.com>
Date: Mon Jun 27 2005 - 03:46:29 EDT
Hi Managers,

Here is the more compact version updated script . Thanks to "Andrew
Hall" for advising me to use case statement.This avoids using NFS mount.


#!/usr/bin/ksh -x
########################################################################
########
#Script Written  on 27th June 05 .
#This script is used to change the root password of all unix hosts
#Make sure /usr/sysadm/scripts/minoti/all-hosts is updated with live
hosts before running this script
########################################################################
#######

for i in `cat /usr/sysadm/scripts/minoti/test-hosts`
do
OS=`remsh $i uname`
case $OS in
SunOS)  rsh $i "rm /tmp/shad*"
        rsh $i "cp -p /etc/shadow /etc/shadow.2706"
        rsh $i "cat /etc/shadow|grep -v root>/tmp/shad1"
        rsh $i "echo "root:1EDHxu0aw6jRE:12958::::::">/tmp/shad2"
        rsh $i "cat /tmp/shad1>>/tmp/shad2"
        rsh $i "cp /tmp/shad2 /etc/shadow"
        rsh $i "/usr/sbin/pwconv"
        rsh $i "chown root:sys /etc/shadow"
        rsh $i "chmod 400  /etc/shadow"
;;
HP-UX)  rsh $i "rm /tmp/shad*"
        rsh $i "rm /tmp/pass*"
        rsh $i "cp -p /etc/passwd /etc/passwd.2706"
        rsh $i "cat /etc/passwd|grep -v root>/tmp/shad1"
        rsh $i "echo "root:WkmiDJgfPbUB.:0:3::/:/sbin/sh">/tmp/shad2"
        rsh $i "cat /tmp/shad1>>/tmp/shad2"
        rsh $i "cp /tmp/shad2 /etc/passwd"
        rsh $i "chown root:other /etc/passwd"
        rsh $i "chmod 444 /etc/passwd"
;;
Linux)  rsh $i "rm /tmp/shad*"
        rsh $i "cp -p /etc/shadow /etc/shadow.2706"
        rsh $i "cat /etc/shadow|grep -v root>/tmp/shad1"
        rsh $i "echo
'root:"$"1"$"hluzjp3u"$"bwx/ZLLAM4qANpMXTvBLz1:12961:0:99999:7:::'>/tmp/
shad2"
        rsh $i "cat /tmp/shad1>>/tmp/shad2"
        rsh $i "cp /tmp/shad2 /etc/shadow"
        rsh $i "/usr/sbin/pwconv"
        rsh $i "chown root:root /etc/shadow"
        rsh $i "chmod 400 /etc/shadow"
;;
IRIX*)  rsh $i "rm /tmp/shad*"
        rsh $i "/sbin/cp -p /etc/shadow /etc/shadow.2706"
        rsh $i "/sbin/cat /etc/shadow|grep -v root>/tmp/shad1"
        rsh $i "/sbin/echo "root:kN6gTIyyu5foo:12958::::::">/tmp/shad2"
        rsh $i "/sbin/cat /tmp/shad1>>/tmp/shad2"
        rsh $i "/sbin/cp /tmp/shad2 /etc/shadow"
        rsh $i "/sbin/pwconv"
        rsh $i "chown root:sys /etc/shadow"
        rsh $i "chmod 400 /etc/shadow"
;;
*)      echo "platform $OS not supported"
;;
esac
done

Regards
Minoti Koul


-----Original Message-----
From: Andrew Hall [mailto:halla3@corp.earthlink.net]
Sent: Friday, June 24, 2005 6:20 PM
To: Koul, Minoti
Subject: Re: SUMMARY: Script for changing the password

FYI,

If you want to only have one pass.sh script you could do this

#!/bin/sh

case $1 in $OS
    "HP-UX")
          hppass.sh contents here
          ;;
    "SunOS")
          sunpass.sh contents here
          ;;
       "IRIX64")
          sgipass.sh contents here
          ;;
       "Linux")
          linuxpass.sh contents here
          ;;
          *)
             echo "I don't know about $OS"
             exit 1
             ;;
esac


Basically you would have one script that is run on each machine and runs
the appropriate code based upon $OS.  And to take it a step further, you
could change your "if [ $OS =" lines to a case statement.  Just and FYI
hoping to help.

HTH,

Drew

Koul, Minoti wrote:

> Thanks for all the valuable replies I got .
>
>1.Anthony D'Atri [aad@verio.net]
>2.Tony van Lingen [tony.vanlingen@epa.qld.gov.au] 3.Tim Evans
>[tkevans@tkevans.com] 4.Polachak, Jason M CTR NAVSEA
>[jason.polachak.ctr@navy.mil#### Jason,Let me know if it helps
>5.JULIAN, JOHN C (AIT) [jj2195@sbc.com] 6.Andrew Hall
>[halla3@corp.earthlink.net] 7.Brad_Morrison@capgroup.com 8.David Ledger

>[dledger@ivdcs.co.uk] 9.Shaw, Kevin [Kevin.Shaw@CAX.USA.XEROX.COM]
>
>I should have mentioned in my original post that mine was hetrogeneous
>env. Solaris,HP-UX,AIX,SuSE,RedHat,SGI.....
>Lot of people recommended using expect but installing expect on all
>platforms was a huge effort.This is how I finally did (again a crude
>way as I had called in my original post)
>
>
>root@pnqccase2:>cat changepass.sh
>###################################################################
>
>#!/usr/bin/ksh -x
>for i in `cat /usr/sysadm/scripts/minoti/all-hosts` # 200 odd unix
>systems do OS=`remsh $i uname`
>
>        if [ $OS = "HP-UX" ]
>then
>        rsh $i "/u/koulmin/scripts/hppass.sh"        #/u/koulmin is an
>automount
>fi
>
>        if [ $OS = "SunOS" ]
>then
>        rsh $i "/u/koulmin/scripts/sunpass.sh"
>fi
>
>        if [ $OS = "IRIX64" ]
>then
>        rsh $i "/u/koulmin/scripts/sgipass.sh"
>fi
>
>        if [ $OS = "Linux" ]
>then
>        rsh $i "/u/koulmin/scripts/linuxpass.sh"
>fi
>done
>#######################################################################
>#
>#####
>Here are the contents of /u/koulmin/scripts/sunpass.sh
>
>#/bin/ksh -x
>rm /tmp/shad*
>cp -p /etc/shadow /etc/shadow.2406
>cat /etc/shadow|grep -v root>/tmp/shad1 echo
>"root:1EDHxu0aw6jRE:12958::::::">/tmp/shad2 #encripted string of
>changed password.
>cat /tmp/shad1>>/tmp/shad2
>cp /tmp/shad2 /etc/shadow
>/usr/sbin/pwconv
>chown root:sys /etc/shadow
>chmod 400  /etc/shadow
>#######################################################################
>#
>########
>Here are the contents of /u/koulmin/scripts/hppass.sh Remember HP-UX
>does not maintain shadow file
>
>root@pnqccase2:>cat /u/koulmin/scripts/hppass.sh #/bin/ksh -x rm
>/tmp/shad* rm /tmp/pass* cp -p /etc/passwd /etc/passwd.2406 cat
>/etc/passwd|grep -v root>/tmp/shad1 echo
>"root:WkmiDJgfPbUB.:0:3::/:/sbin/sh">/tmp/shad2
>cat /tmp/shad1>>/tmp/shad2
>cp /tmp/shad2 /etc/passwd
>chown root:other /etc/passwd
>#######################################################################
>#
>#############
>And so on for all platforms
>
>Thanks once again to all who spared some time to share their valuable
>inputs.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>-----Original Message-----
>From: sunmanagers-bounces@sunmanagers.org
>[mailto:sunmanagers-bounces@sunmanagers.org] On Behalf Of Koul, Minoti
>Sent: Wednesday, June 22, 2005 11:03 AM
>To: sunmanagers@sunmanagers.org
>Subject: Script for changing the password
>
>Hi Managers,
>I am in a situation wherein I have to change root password of 100 odd
>unix boxes. I wanted to do the same via a script.
>
>I used to do it the crude way
>#!/bin/ksh -x
>cp -p /etc/shadow /etc/shadow.11
>cat /etc/shadow|grep -v root>/tmp/shad1 echo
>"root:O75xmUttfitCw:12794::::::">>/tmp/shad2 ## here I am echoing the
>encripted string for new password"
>cat /tmp/shad1>>/tmp/shad2
>cp /tmp/shad2 /etc/shadow
>/usr/sbin/pwconv
>chown root:sys /etc/shadow
>chmod 400  /etc/shadow
>
>I understand that we can input the new password via a script using !! .
>But have'nt been able to do this successfully.
>Can you please help out.
>
>
>
>#####################################
>
>MY NEW MOBILE  NUMBER: 9860092579
>
>#####################################
>
>Regards,
>
>Minoti Koul
>
>UGS - Pune, India
>
>Direct: +91-20-22930635
>
>Board:  +91-20-22930900
>
>Cell:   +91-9860092579
>
>E-mail: minoti.koul@ugs.com
>_______________________________________________
>sunmanagers mailing list
>sunmanagers@sunmanagers.org
>http://www.sunmanagers.org/mailman/listinfo/sunmanagers
>_______________________________________________
>sunmanagers mailing list
>sunmanagers@sunmanagers.org
>http://www.sunmanagers.org/mailman/listinfo/sunmanagers
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Mon Jun 27 09:32:01 2005

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:49 EST