Shell Script to change a user password using script

Hi Experts,

I had tried to executes this script to change the user password through script:

No lines in buffer
#!/bin/ksh
cat /etc/passwd | grep -v userid >> /tmp/pass.tmp1
cat /etc/passwd | grep userid >> /tmp/pass.tmp2
PASS1=`cat /tmp/pass.tmp2 | cut -d ":" -f2`
PASS2=`q2w3e4r5`
sed 's/$PASS1/$PASS2/g' /tmp/pass.tmp2 > TMPFILE && mv TMPFILE /tmp/pass.tmp2
cat /tmp/pass.tmp2 >> /tmp/pass.tmp1
mv /tmp/pass.tmp1 /etc/passwd

After executing i am getting the following error messages:
mlbept0340-root> sh -x -v testpasswd
#!/bin/ksh
cat /etc/passwd | grep -v userid >> /tmp/pass.tmp1
+ cat /etc/passwd
+ grep -v userid
+ 1>> /tmp/pass.tmp1
cat /etc/passwd | grep userid >> /tmp/pass.tmp2
+ grep userid
+ cat /etc/passwd
+ 1>> /tmp/pass.tmp2
PASS1=`cat /tmp/pass.tmp2 | cut -d ":" -f2`
+ + cat /tmp/pass.tmp2
+ cut -d : -f2
PASS1=*
PASS2=`q2w3e4r5`
+ + q2w3e4r5
testpasswd[5]: q2w3e4r5: not found.
PASS2=
sed 's/$PASS1/$PASS2/g' /tmp/pass.tmp2 > TMPFILE && mv TMPFILE /tmp/pass.tmp2
+ sed s/$PASS1/$PASS2/g /tmp/pass.tmp2
+ 1> TMPFILE
+ mv TMPFILE /tmp/pass.tmp2
cat /tmp/pass.tmp2 >> /tmp/pass.tmp1
+ cat /tmp/pass.tmp2
+ 1>> /tmp/pass.tmp1
mv /tmp/pass.tmp1 /etc/passwd
+ mv /tmp/pass.tmp1 /etc/passwd

Please suggested, and it added one more line with same user id in /etc/passwd
ucmdb:.VQDaeUFiPtWE:5555:5555::/app/common/home/ucmdb:/sbin/sh
nagios::112:541::/home/nagios:/sbin/sh
+::-2:-2:::
ibhagat:
:129:20::/home/ibhagat:/sbin/sh
ibhagat:*:129:20::/home/ibhagat:/sbin/sh

Couple of errors i could find are..highlighted

#!/bin/ksh
cat /etc/passwd | grep -v userid >> /tmp/pass.tmp1
cat /etc/passwd | grep userid >> /tmp/pass.tmp2
PASS1=`cat /tmp/pass.tmp2 | cut -d ":" -f2`
PASS2="q2w3e4r5"
sed "s/$PASS1/$PASS2/g" /tmp/pass.tmp2 > TMPFILE && mv TMPFILE /tmp/pass.tmp2
cat /tmp/pass.tmp2 >> /tmp/pass.tmp1
mv /tmp/pass.tmp1 /etc/passwd

Still something wrong is there in script:

The output of the script. It is givng sed: Function s/* cannot be parsed.

mlbept0340-root> sh -x -v testpasswd
#!/bin/ksh
cat /etc/passwd | grep -v ibhagat >> /tmp/pass.tmp1
+ grep -v ibhagat
+ cat /etc/passwd
+ 1>> /tmp/pass.tmp1
cat /etc/passwd | grep ibhagat >> /tmp/pass.tmp2
+ grep ibhagat
+ cat /etc/passwd
+ 1>> /tmp/pass.tmp2
PASS1=`cat /tmp/pass.tmp2 | cut -d ":" -f2`
+ + cat /tmp/pass.tmp2
+ cut -d : -f2
PASS1=*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
PASS2="q2w3e4r5"
+ PASS2=q2w3e4r5
sed "s/$PASS1/$PASS2/g" /tmp/pass.tmp2 > TMPFILE && mv TMPFILE /tmp/pass.tmp2
+ sed s/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
/q2w3e4r5/g /tmp/pass.tmp2
+ 1> TMPFILE
sed: Function s/
cannot be parsed.
cat /tmp/pass.tmp2 >> /tmp/pass.tmp1
+ cat /tmp/pass.tmp2
+ 1>> /tmp/pass.tmp1
mv /tmp/pass.tmp1 /etc/passwd
+ mv /tmp/pass.tmp1 /etc/passwd

Please help me out

Change the sed part as..

sed "s/\$PASS1/$PASS2/g" ...