Script to change password in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to change password in UNIX
# 22  
Old 06-18-2014
Yes, you will need to use perl for that:

Code:
YESTERDAY=`perl -e "use POSIX; print strftime('%d-%b',localtime(time()-86400))"`
OLDPASS=`grep "$YESTERDAY" file.txt | cut -c8-`

# 23  
Old 06-18-2014
i think can we get yesterday password from file without using perl...i dont know bout perl

can u please advise below is one of the example

Code:
| grep -e "\($(($(date +%d)-0))\|$(($(date +%d)-1))\|$(($(date +%d)-2))\) $(date +%b)"

# 24  
Old 06-18-2014
Perl should be installed by default, so I don't think you will need to setup anything.

If you want to process yesterday manually you also need something for 1st/2nd/3rd of month and 1st/2nd/3rd Jan - Dont forget about leap years as well.

I have seen some solutions that try and change the timezone and trick date in displaying yesterdays date but they are a little prone to issues around different timezones and daylight savings and I wouldn't suggest them, below you would adjust the +20 for your actual timezone, again watch out for daylight savings changes and running this early in the morning or late at night:

Code:
TZ=GMT+20 date +%d-%b


Last edited by Chubler_XL; 06-18-2014 at 08:05 PM..
# 25  
Old 06-19-2014
Hey Chubler,

i have compiled the program but it is manually asking for the input of passwords it should automatically take from file.txt
output

sh test.sh
Todays password is: OLiver@123#
Enter existing login password:


Code:
#!/bin/sh
CWD=/home/raj/TEST
cd $CWD
rm outpp.log
DT=`date +"%d-%b"`
PASS=`grep "$DT" file.txt | cut -c8-`
YESTERDAY=`perl -e "use POSIX; print strftime('%d-%b',localtime(time()-86400))"`
OLDPASS=`grep "$YESTERDAY" file.txt | cut -c8-`
if [ -n "$PASS" ]
then
  echo "Todays password is: $PASS"
  printf "%s\n" "$OLDPASS" "$PASS" "$PASS" | (passwd raj) > /home/raj/TEST/outpp.log
else
  echo "No password for $DT"
fi
if egrep -iq '(Permission)|(successfully)' /home/raj/TEST/outpp.log
then
   MAILTO="raj@abc.com"
   CONTENT="/home/raj/TEST/outpp.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

# 26  
Old 06-19-2014
Back in post #21 you said that this:

Code:
printf "%s\n" "oldpass" "newpass" "newpass" | (passwd rsaini)

worked from the command line so we know sending an oldpassword into passwd works OK.

I suspect the $YESTERDAY value is blank

put this debug in: echo "Yesterdays ($YESTERDAY) password is: $OLDPASS" just to confirm the perl+grep is getting the correct date and password.
# 27  
Old 06-19-2014
i have given only below line in command line and it was working

Code:
printf "%s\n" "oldpass" "newpass" "newpass" | (passwd rsaini)

here is the output

sh test.sh
Yesterdays (17-Jun) password is: oss123!
Todays password is: OLiver@123#
Enter existing login password:


added the line in the code
Code:
---------------
---
DT=`date +"%d-%b"`
PASS=`grep "$DT" file.txt | cut -c8-`
YESTERDAY=`perl -e "use POSIX; print strftime('%d-%b',localtime(time()-86400))"`
OLDPASS=`grep "$YESTERDAY" rnc.txt | cut -c8-`
echo "Yesterdays ($YESTERDAY) password is: $OLDPASS"
if [ -n "$PASS" ]
then
--
---

# 28  
Old 06-20-2014
I think you may be stuck without root access, as mentioned before expect can do this sort of thing but it's unlikely to be installed on your system.

It could be time to investigate alternate methods to deal with this. Perhaps a prompt for the daily password from a script run by the users profile? Do they just login via telnet/ssh or are they using ftp/web/other interfaces?
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