Thank you all for your reply. This weekend I'm planning to sit tight and write a script for this. Once done, I'll post that here and would love to get your reviews.
---------- Post updated 09-17-11 at 04:13 PM ---------- Previous update was 09-16-11 at 07:45 PM ----------
Well thanks for your input guys. Here is the bash script I have written for our Linux and Solaris servers. It's almost similar to the ksh script I wrote for the same purpose on AIX servers. The difference is with AIX's lsuser command, it was easy for me to get user details.
Review the code and let me know your thoughts
Code:
#!/bin/bash
# this script searches for the user ids which have not been used for a specific
# number of days
# the number of days to be monitored
expdays=30
expiry=$(( 86400*$expdays ))
LOG1=/tmp/inactive_usr_$expdays_days.$( date '+%m-%d-%Y' ).log
LOG2=/tmp/never_logged_usrs.$( date '+%m-%d-%Y' ).log
tmp1=/tmp/tmp1.log.$$
# list out the accounts which can be used to log in to the server
cat /etc/passwd | grep -Ev ^"root|daemon|nobody|adm|sys" | cut -d ":" -f1 >>$tmp1
# date and time calculation with respect to unix epoch
year=$( date +%Y )
today=$( date +%s )
# now, for each of the user listed above, run a check if the last logged in time exceedes the specified number of days.
cat $tmp1 | while read usr; do
umnt=$( last -1 $usr | head -1 | awk '{ print $5 }' )
uday=$( last -1 $usr | head -1 | awk '{ print $6 }' )
uhour=$( last -1 $usr | head -1 | awk '{ print $7 }' | cut -d ":" -f1 )
umin=$( last -1 $usr | head -1 | awk '{ print $7 }' | cut -d ":" -f2 )
# the below line checks and stores the IDs which were never used
if [ ! $uday ] || [ ! $uhour ] || [ ! $umin ]; then
echo "$usr:__NeveR__" >>$LOG2
else
llogin=$( date +%s -d"$umnt $uday, $year $uhour:$umin:01" )
mini=$(( $today-$llogin ))
if [[ $mini -gt $expiry ]]; then
login=$(( ($today-$llogin)/86400 ))
echo "$usr:$login" >>$LOG1
fi
fi
done
rm -f $tmp1
// AIX 6.1
In need of finding which AIX user accounts will be expired and are
locked.
I have placed the following parameters under /etc/security/user... (1 Reply)
i have my files and the variables value extracted from db is taken as
in1=slot0312
in2=best
in3=it is :veryliong/fine
as varibles..
i have a folder stuctures in my unix machine as :
/2011/hand_sl0312/best/HOD/file1.txt
/2011/hand_sl0312/happy/HOD/file1.txt... (1 Reply)
I am trying to find out the number of days between the current date and user defined date.
I took reference from here for the date2jd() function.
Modified the function according to my requirement. But its not working properly.
Original code from here is working fine.
#!/bin/sh... (1 Reply)
I have looked around on the internet and still i am no wiser as to how to show the number of files in a directory that have been accessed this week and also that as a percentage.
Any help would be much appreciated. (5 Replies)
hello ppl, someone must be able to help with this --> I have an old NCR tower 32 with an ADDS terminal running a unix version 020102 (Im not sure if thats correct but its unix for sure). I have no user names and no passwords and need to login to read a tape. Is there any way to do that? I hear... (3 Replies)
Hi,
I need to count the number of times a script is accessed from within the script. Is it possible ?
Example: I have a script called lo.sh and i execute the script for the first time, then the counter variable declared inside the lo.sh should increment by 1. For every execution the... (1 Reply)
I have found a script to create user accounts. But there are a few lines i dont understand. Can someone help me with this? Here's the code:
######################################
while ;
do
ACCT=${USER_ACCT}${START}
START=`expr $START + 1`
START=`echo ${START} | awk... (3 Replies)