-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_expired_user.sh
More file actions
executable file
·30 lines (30 loc) · 977 Bytes
/
check_expired_user.sh
File metadata and controls
executable file
·30 lines (30 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
#Created on:09-02-2010
#Last modified:02-05-2010
#Purpose:To check the user account status in Linux
#Author:Surendra Kumar Anne
#The below command will grep all the users in shadow file
#whose expiry time is set and send them to expirelist.txt
cat /etc/shadow | cut -d: -f1,8 | sed /:$/d > /tmp/expirelist.txt
totalaccounts=`cat /tmp/expirelist.txt | wc -l`
for((i=1; i<=$totalaccounts; i++ ))
do
tuserval=`head -n $i /tmp/expirelist.txt | tail -n 1`
username=`echo $tuserval | cut -f1 -d:`
userexp=`echo $tuserval | cut -f2 -d:`
userexpireinseconds=$(( $userexp * 86400 ))
todaystime=`date +%s`
#check if the user expired or not?
if [ $userexpireinseconds -ge $todaystime ] ;
then
timeto7days=$(( $todaystime + 604800 ))
if [ $userexpireinseconds -le $timeto7days ];
then
#mail -s "The account $username will expire less than 7 days" haf
echo "sss"
fi
else
echo ""
#mail -s "The user account $username already expired" hafeez
fi
done