自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用Bash腳本發(fā)送包含幾天內(nèi)到期的用戶賬號(hào)列表的電子郵件

系統(tǒng) Linux
本教程中包含兩個(gè) bash 腳本可以幫助你收集系統(tǒng)中用戶到期天數(shù)的信息。

[[312938]]

密碼強(qiáng)制策略對(duì)所有操作系統(tǒng)和應(yīng)用程序都是通用的。如果要在 Linux 上實(shí)現(xiàn)密碼強(qiáng)制策略,請(qǐng)參閱以下文章。

默認(rèn)情況下,大多數(shù)公司都會(huì)強(qiáng)制執(zhí)行密碼強(qiáng)制策略,但根據(jù)公司的要求,密碼的時(shí)間周期會(huì)有所不同。通常每個(gè)人都使用 90 天的密碼周期。用戶只會(huì)在他們使用的一些服務(wù)器上更改密碼,而不會(huì)在他們不經(jīng)常使用的服務(wù)器上更改密碼。

特別地,大多數(shù)團(tuán)隊(duì)忘記更改服務(wù)帳戶密碼,這可能導(dǎo)致日常工作的中斷,即使他們配置有基于 SSH 密鑰的身份驗(yàn)證。如果用戶帳戶密碼過期,基于SSH密鑰的身份驗(yàn)證和 cronjob 將不起作用。

為了避免這種情況,我們創(chuàng)建了一個(gè) shell 腳本來向你發(fā)送 10 天內(nèi)到期的用戶帳戶列表。

本教程中包含兩個(gè) bash 腳本可以幫助你收集系統(tǒng)中用戶到期天數(shù)的信息。

1) 檢查 10 天后到期的用戶帳戶列表

此腳本將幫助你在終端上檢查 10 天內(nèi)到期的用戶帳戶列表。

  1. # vi /opt/script/user-password-expiry.sh
  1. #!/bin/sh
  2. /tmp/user-expiry-1.txt
  3. /tmp/user-expiry.txt
  4. echo "-------------------------------------------------"
  5. echo "UserName The number of days the password expires"
  6. echo "-------------------------------------------------"
  7. for usern in u1 u2 u3 u4
  8. do
  9. today=$(date +%s)
  10. userexpdate=$(chage -l $usern | grep 'Password expires' |cut -d: -f2)
  11. passexp=$(date -d "$userexpdate" "+%s")
  12. exp=`expr \( $passexp - $today \)`
  13. expday=`expr \( $exp / 86400 \)`
  14. echo "$usern $expday" >> /tmp/user-expiry.txt
  15. done
  16. cat /tmp/user-expiry.txt | awk '$2 <= 10' > /tmp/user-expiry-1.txt
  17. cat /tmp/user-expiry-1.txt | column -t

將文件 user-password-expiry.sh 設(shè)置為可執(zhí)行的 Linux 文件權(quán)限。

  1. # chmod +x /opt/script/user-password-expiry.sh

你將得到如下輸出,但用戶與天數(shù)可能不同。

  1. # sh /opt/script/user-password-expiry.sh
  2.  
  3. -------------------------------------------------
  4. UserName The number of days the password expires
  5. -------------------------------------------------
  6. u1 -25
  7. u2 9
  8. u3 3
  9. u4 5

2) 發(fā)送包含 10 天內(nèi)到期的用戶帳戶列表的電子郵件

此腳本將發(fā)送一封包含 10 天內(nèi)到期的用戶帳戶列表的郵件。

  1. # vi /opt/script/user-password-expiry-mail.sh
  1. #!/bin/sh
  2. SUBJECT="Information About User Password Expiration on "`date`""
  3. MESSAGE="/tmp/user-expiry.txt"
  4. MESSAGE1="/tmp/user-expiry-1.txt"
  5. TO="magesh.m@rentacenter.com"
  6. echo "-------------------------------------------------" >> $MESSAGE1
  7. echo "UserName The number of days the password expires" >> $MESSAGE1
  8. echo "-------------------------------------------------" >> $MESSAGE1
  9. for usern in u1 u2 u3 u4
  10. do
  11. today=$(date +%s)
  12. userexpdate=$(chage -l $usern | grep 'Password expires' |cut -d: -f2)
  13. passexp=$(date -d "$userexpdate" "+%s")
  14. exp=`expr \( $passexp - $today \)`
  15. expday=`expr \( $exp / 86400 \)`
  16. echo "$usern $expday" >> $MESSAGE
  17. done
  18. cat $MESSAGE | awk '$2 <= 10' >> $MESSAGE1
  19. mail -s "$SUBJECT" "$TO" < $MESSAGE1
  20. rm $MESSAGE
  21. rm $MESSAGE1

將文件 user-password-expiry-mail.sh 設(shè)置為可執(zhí)行的 Linux 文件權(quán)限。

  1. # chmod +x /opt/script/user-password-expiry-mail.sh

最后,添加一個(gè) cronjob 去自動(dòng)執(zhí)行腳本。每天早上 8 點(diǎn)運(yùn)行一次。

  1. # crontab -e
  2. 0 8 * * * /bin/bash /opt/script/user-password-expiry-mail.sh

你將收到一封與第一個(gè)腳本輸出類似的電子郵件。 

責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2019-09-20 13:48:23

BashLinux命令

2011-10-31 09:35:50

2020-02-26 13:47:57

Emacs電子郵件開源

2019-08-08 07:25:11

BashLinux命令

2009-10-14 10:10:05

2023-12-31 16:29:31

GoGoroutinesChannels

2011-12-15 10:45:33

2010-09-15 14:14:50

2010-09-09 17:11:32

2020-05-13 08:48:16

JavaScript前端技術(shù)

2011-08-01 11:11:55

2011-08-01 10:54:56

2020-05-21 10:06:04

電子郵件郵件安全惡意軟件

2019-08-08 14:55:19

電子郵件微軟信頭

2016-04-28 13:40:04

2022-03-06 07:01:15

黑客網(wǎng)絡(luò)攻擊

2021-06-28 21:21:54

電子郵件郵件安全惡意軟件

2025-04-11 08:25:36

2011-08-01 12:43:03

2010-06-10 14:10:58

安全電子郵件協(xié)議
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)