Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Simple Shell Script to remind user of upcoming pw change

  • 24-09-2015 10:32am
    #1
    Registered Users, Registered Users 2 Posts: 3,739 ✭✭✭


    Lads,

    There is a password expiration policy as you would expect on all of our Linux servers globally at work, in the domains I'm part of, users are both sent reminder emails and the shell lets them know when passwords are about to expire, thus reducing tickets etc....but we have one domain I do not have any admin access on, I am a regular user...and the admins of this domain do not provide any for-warning of impending password expiration, pain in the arse, especially when it can can takes days for your ticket for pw reset to be serviced on that domain...

    I cant use the Linux command chage on this domain, to edit passwd file to give notification.

    Short of setting up a goggle calender reminder to myself...does anybody have an idea for a bash script that I could load into my .profile on that domain, echoing a backwards countdown from a future date to remind me to change pre-emptively !

    pseudo code: $expiry_date; $current_date; $date_diff ; echo 'Reminder: Change password in $date_diff days. '

    `date` is complicated when you haven't fooled around with it :-p

    bash or ksh ...Im not good at scripts...any help appreciated cheers.


Comments

  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    Something like this would work (could be tidied up mind you...
    chage -l ${USER} | perl -MTime::Local -ne ' # capture expiry date from chage
    if (($mon,$day,$year)=$_=~/Password expires\s+:\s+(\S+)\s+(\d+),\s+(\d+)/){  # If this is the expiry date line
    %mon=(Jan=>0,Feb=>1,Mar=>2,Apr=>3,May=>4,Jun=>5,Jul=>6,Aug=>7,Sep=>8,Oct=>9,Nov=>10,Dec=>11); # create a month=>localtime hash
    $exp_time=timelocal(0,0,0,$day,$mon{$mon},$year - 1900); #generate epoch for midnight on $date
    $remaining=int(($exp_time - time())/(24 * 60 * 60)); #get remaining days
    print "You have $remaining days to password expiry\n"}' #Display remaining days
    


  • Registered Users, Registered Users 2 Posts: 3,739 ✭✭✭Stuxnet


    Cheers for that, I managed to do it !!

    Should of tried harder before posting here :)
    #!/bin/sh
    
    expiry=`date -d "Dec 22" +%j`
    today=`date +%j`
    difference=$(($expiry - $today))
    
    if [[ ! $difference =~ ^[0-9+$ ]]; then
    echo Change password in $difference days.
    
    else
            echo Password has expired.
    fi
    


  • Registered Users, Registered Users 2 Posts: 1,931 ✭✭✭PrzemoF


    #!/bin/sh
    expiry=`date -d "Sep 19 2016" +%s`
    today=`date +%s`
    diff_days=$(echo "($expiry - $today) / 86400" | bc)
    
    if [ $diff_days -gt 0 ]; then
            echo Change password in $diff_days days.
    else
            echo Password has expired $(echo "-1*$diff_days" | bc) days ago
    fi
    

    I could not understand your code, so I tweaked it a bit :)


Advertisement