LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Wrapper needed for BASH Script (http://www.linuxquestions.org/questions/programming-9/wrapper-needed-for-bash-script-276891/)

outspoken 01-12-2005 09:04 AM

Wrapper needed for BASH Script
 
The comments have been made on what is needed, trying to figure out how to get this thing to be functional.

passwd-policy.sh
Code:

#!/bin/sh
Min=7      # stops the users from changing their password for 7 days after a new password is set
Max=180    # 180 days after the password is set it expires
Warn=7      # 7 days warning about a password expiration
Inactive=60 # User account will expire 30 days after the password has expired

# On new systems:
if [ $NEWSYS ];then
        useradd -D -f $Inactive
fi

# New users
if [ $NEWUSER ];then
        useradd -f $Inactive -c $GCOS $USER -k $SKEL_DIR
        passwd -n $Min -x $Max -w $Warn -i $Inactive $USER
fi

# Force a password change by setting the last password changed date to 2000-01-01
# and the days between changes as 180
if [ $FORCE ];then
        DATE="2004-05-01" #need a routine that subtracts $Max + 1 days from today's date
        DATE=`./daysfrom.pl $Max`;
        passwd -i $Inactive -x $Max $USER #prevents locking the account
        chage -d $DATE $USER #last password change
fi


daysfrom.pl
Code:

#!/usr/bin/perl -w
#Calculate the number of days in the past
#Does not account for Daylight savings time (I think)
#
use strict;

use POSIX qw/strftime/;

my $DaysFactor = 60 * 60 * 24;  #Number of seconds in  a day
my $Days = 0;
$Days = $ARGV[0] if $ARGV[0];
print strftime('%Y-%m-%d',localtime( time - ($DaysFactor * $Days)) );



All times are GMT -5. The time now is 07:53 AM.