Script to change password in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to change password in UNIX
# 8  
Old 06-18-2014
What OS and version are you runnning? It really might make all the difference here.

You code contains this:-
Code:
echo -e "test123\test123" ........

What do you get if you run this on the command line? I get test123tabest123

I would also be surpised if passwd would let you feed in the new password like this anyway. It is probably designed to stop such things as they are generally considered to be a bad thing.

What do you plan to do with the file /home/home/raj/password/dateout.txt by the way? Rather than write a file and test it, how about:-
Code:
pswd_val=`grep "`date +"%d-%b"`" file.txt`
if [ "$pswd_val" != "" ]
then
   passwd --expire raj ........ etc.





Robin
# 9  
Old 06-18-2014
file.txt look like

cat file.txt
test123 18-Jun
abcd123 19-Jun

dateout look like

cat dateout
test123 18-Jun

I want to take out test123 from dateout file and use in

Code:
echo -e "test123\test123" | (passwd raj)

---------- Post updated at 12:27 PM ---------- Previous update was at 12:22 PM ----------

i am not able to run shows me error as want to use the passwd from dateout.txt...

ver:- 5.1
# 10  
Old 06-18-2014
You didn't specify the format of your password file (file.txt) so I'm guessing it will be like this:

Code:
18-Jun my-Secret
19-Jun dAily_user
20-Jun Pass:file

This should get the password out and send it to your passwd command - however on my OS passwd required the --stdin parameter and I still couldn't pipe the output to a file. What OS are you on? I'm sure there is better way to change passwords on your OS than piping them to the passwd command...

Code:
#!/bin/sh
CWD=/home/raj/Password
cd $CWD
rm -f result
DT=`date +"%d-%b"`
PASS=`grep "$DT" file.txt | cut -c8-`
if [ -n "$PASS" ]
then
  echo "Todays password is: $PASS"
  passwd --expire raj #EXPIRING THE PASSWORD
  printf "%s\n" "$PASS" "$PASS" | (passwd raj) > /home/raj/Password/out.log
else
  echo "No password for $DT"
fi
if egrep -iq '(Permission)|(successfully)' /home/raj/Password/out.log
then
   MAILTO="abc@abc.com"
   CONTENT="/home/raj/Password/out.log"
   (
        echo "Subject: Password Change Status "
        echo "MIME-Version: 1.0"
        echo "Content-Type: text/html"
        echo "Content-Disposition: inline"
        cat $CONTENT
   ) | /usr/sbin/sendmail -t $MAILTO
else
  echo "bbb"
fi

# 11  
Old 06-18-2014
Change while read pass into while IFS=$'\t' read -r pass date in his loop. That should be able to read the passwords from your password/date file.
# 12  
Old 06-18-2014
Ok you posted the format of file.txt while I was typing - can you change it to put the date first as then things are much simpler to get the password out, especially considering that the password could contain space characters
# 13  
Old 06-18-2014
Thanks Chubler...I am am having another issue I dont have admin rights to use
Code:
password --expire raj

is there any other way to expire the old password or implement it.

my verision is uname -a
SunOS 5.10 Generic
# 14  
Old 06-18-2014
I'm guessing your on ubuntu 5.1

Does this command work to change the password from the command line:

Code:
# usermod -p $(openssl passwd "test123" ) raj

If so you could replace the (passwd raj) line in the script above

Code:
usermod -p $(openssl passwd "$PASS" ) raj > /home/raj/Password/out.log 2>&1

---------- Post updated at 03:03 AM ---------- Previous update was at 02:59 AM ----------

OK SunOS, usermod should still work, do you have the openssl command, try:

Code:
$ openssl passwd test123

These commands will need to be run as root you can't change user attributes without root access - you mentioned cron so again your final script would need to be run as a root cronjob.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Password sent via reset password email is 'weak' and won't allow me to change my password

I was unable to login and so used the "Forgotten Password' process. I was sent a NEWLY-PROVIDED password and a link through which my password could be changed. The NEWLY-PROVIDED password allowed me to login. Following the provided link I attempted to update my password to one of my own... (1 Reply)
Discussion started by: Rich Marton
1 Replies

2. 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

3. Shell Programming and Scripting

A script to change password for all other servers

Hey Gurus, I have this requirement to change the password for other servers remotely from one server. So, I installed public keys on all servers and wrote the following script to do the job. Something appears to be wrong with my loop, as it only changes one server and ignores the rest. I'm... (24 Replies)
Discussion started by: Hiroshi
24 Replies

4. HP-UX

Automatic script to change the UNIX Password

Hi, we have around 50 users and every month we need to change the password manually once its expire. do we have any script to change the password automatically. OS -HP-UX Thanks in advance.. (6 Replies)
Discussion started by: periyasamycse
6 Replies

5. Shell Programming and Scripting

Unix script to change password

Hello Gurus I have little challenge which I do not know how to address it. I have unix account on many servers (let's say over 25). These accounts expire every 60 days. Is there scripts that I can run from my "local computer" and pass a new password to it where it would change it for me on all... (7 Replies)
Discussion started by: nimo
7 Replies

6. UNIX for Dummies Questions & Answers

Where to change the UNIX password prompt?

Hi guys, I got these 3 servers: a, b and c which I ssh from a to b/c. a:$ ssh userid@b Password: a:$ ssh userid@c userid@c's password: Notice that the password prompt is different (highlighted in bold) on both servers even though their SUN Solaris version the same, OpenSSH version... (0 Replies)
Discussion started by: DrivesMeCrazy
0 Replies

7. 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

8. Shell Programming and Scripting

script/program to change the password ?

hi, Somebody have or known where i can find a perl small perl program to change the password. The point: First it verify is the user exist, checking the old typed password and replace it with new. The passwords must be encoded. Thanks, very much! (0 Replies)
Discussion started by: kad
0 Replies

9. Shell Programming and Scripting

Script to change UNIX password

My shop has just ordained that all UNIX passwords expire after 45 days. We do NOT have a "single logon" facility, so I will need to logon to each of the servers (15+) I interact with and change my password by hand. I thought I could invoke passwd inside a ksh script as a Here document and... (12 Replies)
Discussion started by: kornshellmaven
12 Replies

10. UNIX for Advanced & Expert Users

Change password script in Unix easily..

I have more than 50 server unix's password need to change, usually I assign one password for all hosts, for easy remember, but I need to change password every two months..it's very tried to change password every 2 months, is there any unix script that can change password easily? ie ' script... (4 Replies)
Discussion started by: zp523444
4 Replies
Login or Register to Ask a Question