-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword-expire-check
More file actions
24 lines (21 loc) · 886 Bytes
/
Copy pathpassword-expire-check
File metadata and controls
24 lines (21 loc) · 886 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
#!/usr/bin/ruby
require 'date'
require 'net/smtp'
require 'socket'
expire_warning=10
email_addresses=["test@domain.com","test2@domain.com"]
ignored_users=["root","test"]
hostname=Socket.gethostname
today = Date.today
expire_warning = (today + expire_warning)
user_list = `cat /etc/shadow | sed -n '/:\$.*:/ p' | cut -d ":" -f 1`.split
user_list -= ignored_users
user_list.each do |i|
expire_day = Date.parse(`chage -l #{i} | grep "Password expires" | sed -n -e "s/^.*: //p"`).to_s
if ( Date.parse(expire_day) < expire_warning ) && ( Date.parse(expire_day) >= today )
Net::SMTP.start('localhost') do |smtp|
message = "Subject: Password Expiration Warning\n\nUser #{i}'s password expires on #{expire_day}"
smtp.send_message message, "root@#{hostname}", email_addresses
end
end
end