-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_crontab_user_expired.sh
44 lines (38 loc) · 1.21 KB
/
check_crontab_user_expired.sh
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
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# Created by hewei.chn#gmail.com 20130315
# Use This Script to Make Sure that Users who have crontab to run will not expired.
# Version v0.1
# You should Run This Script once if you not sure about the user expired info with root permisson.
#if [ -z $1 ] ; then
echo "We will Set the Users' Account & Password Nerver Expired."
#fi
if [ `whoami` != "root" ]; then
echo "You must run with root privilege, Try run with sudo ?"
exit 1
fi
if [ ! -d "/var/spool/cron/" ]; then
echo "No User have use crontab. Nothing to do, Bye."
exit 0;
fi
for user in `ls /var/spool/cron/`; do
echo -ne "checking $user ...\t\t"
COMMANDS=`cat /var/spool/cron/$user | grep -v ^$ | grep -v ^MAILTO | grep -v ^# | wc -l`
if [ $COMMANDS -eq 0 ];then
echo " No Commands in crontab, Skip it."
continue;
fi
chage -l $user >/dev/null 2>&1
if [ $? != 0 ];then
echo "Failed to Check account info with RetCode $?, Skip it."
continue;
fi
EXPINFO=`chage -l $user | grep -E ^"(Password|Account) expires" | grep -v never$`
if [ ${#EXPINFO} -eq 0 ]; then
echo "User Will Nerver Expired. Go to Next.."
continue;
else
echo -n "Set Password And Account Expired to -1(never expired)..."
chage -M -1 -E -1 $user
echo "Done"
fi
done