bin sh DAYS 90 if -eq then DAYS fi real_accounts cat etc passwd awk BE

 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
#!/bin/sh
DAYS=90
if [ $# -eq 1 ]
then
DAYS=$1
fi
#real_accounts=`cat /etc/passwd | awk 'BEGIN {FS=":"} {print $1,$7}' | grep -v '/bin/false' | awk 'BEGIN {FS=" "} {print $1}'`
real_accounts=`sudo passwd -Sa | grep ' P' | awk 'BEGIN {FS=" "} {print $1}'`
active_accounts=`lastlog -t$DAYS | awk 'BEGIN {FS=" "} {print $1}'`
for user in $real_accounts
do
flag=0
for test_user in $active_accounts
do
if [ "$user" = "$test_user" ]
then
flag=1
fi
done
if [ $flag -eq 0 ]
then
echo $user
fi
done