Shell Script to change a user password using script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to change a user password using script
# 1  
Old 11-23-2010
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
# 2  
Old 11-23-2010
Couple of errors i could find are..highlighted
Code:
#!/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

# 3  
Old 11-23-2010
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
# 4  
Old 11-23-2010
Change the sed part as..
Code:
sed "s/\$PASS1/$PASS2/g" ...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to change the password

Hi Folks, I am trying to change the password for the user "sysservice" Where my requirement is login to each server and exit from that and ssh to the next server.. I have enabled the password less auth for the user sysservice. for i in `cat /home/sysservice/servers.txt` do ssh... (1 Reply)
Discussion started by: gsiva
1 Replies

2. Shell Programming and Scripting

Shell script to change the password on multiple servers in linux

Can any one please let me know the shell script to change the password for a particular user on multiple linux servers. (2 Replies)
Discussion started by: s_madras
2 Replies

3. Linux

script for password change for exiting user

Dear Forum, In our organization 100 user is existing. Now i want to change password for 100 user in linux server. Pls help to write script for changing password. Regads// Taifur (3 Replies)
Discussion started by: taifurakhand
3 Replies

4. UNIX for Dummies Questions & Answers

Change user passwords using shell script

Hi, I want to change the password of unix users on a number of servers.My plan was to ssh to all the servers in a shell script and use the passwd command. I tried to do so but everytime i run it i get this error. ssh -x -n -l user1 host passwd Changing password for "user1" 3004-709 Error... (3 Replies)
Discussion started by: poojabhat
3 Replies

5. Shell Programming and Scripting

how to change root password using shell script with standard password

Hi Friends. I am new to scripting now i want to change the root password using the script with standard password. which is the easy scripting to learn for the beginner, Thanks in advance. (2 Replies)
Discussion started by: kurva
2 Replies

6. Shell Programming and Scripting

force to change password(shell script)

hi How can I force user to change of password by modifying the password expiry and the grace period so that the user has at least 1 week to login and change the password...... (3 Replies)
Discussion started by: tjay83
3 Replies

7. Shell Programming and Scripting

How do i change to super user then revert back to ordinary user ,using shell script?

Hi all, I am trying to eject the cdrom from a livecd after certain stage... Now assuming that it is possible to eject,please consider my issue!!! The OS boots into a regular user by default...so i am unable to use the eject command to push out the drive... However if i try pfexec eject it... (3 Replies)
Discussion started by: wrapster
3 Replies

8. Shell Programming and Scripting

Change Password In A Shell Script

Hi All, I have a problem. I need to write a shell script to change the password. The user may want to change his own password by this script. He will have to provide the required 3 parameters i.e. old password, new password and retype new password as arguments in command line. like,... (6 Replies)
Discussion started by: pintu_asim
6 Replies

9. UNIX for Dummies Questions & Answers

change user through shell script

hi, my problem is that i am calling a script from my perl program. the script checks wether a particular process is running or not if the process is not running then it should start the process. the problem here is that the front end logs into backend with a user which does not have the... (0 Replies)
Discussion started by: raviraushanjha
0 Replies

10. UNIX for Dummies Questions & Answers

How would I telnet & change user password automatically in a script

I would like to create a script that logs into a list of several servers 50+ and changes my password all at once. Every 60 days we are required to login to each system and change our passwords or else they expire and our login account is deleted. I have an idea on how I could do this but... (4 Replies)
Discussion started by: darthur
4 Replies
Login or Register to Ask a Question

Featured Tech Videos