shell腳本
有需要的小伙伴直接拿去用吧缆娃,轉(zhuǎn)載的話記得注明出處哦
#!/bin/bash
getBetweenDays() {
start=$1
end=$2
p='0'
startDate=$( date -j -v+"$p"d -f "%Y%m%d" "$start" +%s) # +%s代表轉(zhuǎn)成時間戳
# echo $startDate
endDate=$( date -j -v+"$p"d -f "%Y%m%d" "$end" +%s)
# echo $endDate
val=`expr $startDate - $endDate`
m=86400
val=`expr $val / $m`
echo $val
}
echo "---------\033[32m檢測開始\033[0m---------"
cd /Users/$(whoami)/Library/MobileDevice/Provisioning\ Profiles/
for element in `ls /Users/$(whoami)/Library/MobileDevice/Provisioning\ Profiles/`
do
if echo "$element" | grep -q -E '.mobileprovision'
then
command
else
continue
fi
temp_plist_file="test.plist"
rm $temp_plist_file
cmd=`security cms -D -i $element > $temp_plist_file`
AppIDName="AppIDName"
declare -a AppIDName=$( /usr/libexec/PlistBuddy -c "Print $AppIDName" $temp_plist_file)
AppID="Entitlements:application-identifier"
declare -a AppID=$( /usr/libexec/PlistBuddy -c "Print $AppID" $temp_plist_file)
UUID="UUID"
declare -a UUID=$( /usr/libexec/PlistBuddy -c "Print $UUID" $temp_plist_file)
ExpirationDate="ExpirationDate"
declare -a ExpirationDate=$( /usr/libexec/PlistBuddy -c "Print $ExpirationDate" $temp_plist_file)
read dow month day time timezone year <<< "${ExpirationDate}"
export LANG="en_US.UTF-8"
#https://www.cnblogs.com/meitian/p/7768376.html
ymd_expiration=`date -jf "%a %d %b %Y" "${dow} ${day} ${month} ${year}" +%Y%m%d`
ymd_today=`date +%Y%m%d`
expired_in_days=$(getBetweenDays $ymd_expiration $ymd_today)
if [[ expired_in_days -gt 0 ]]; then
if [[ expired_in_days -lt 30 ]]; then
msg=${AppID}"\t"${AppIDName}'\t即將在'$expired_in_days'天內(nèi)過期'
echo "\033[33m$msg \033[0m"
fi
else
msg=${AppID}"\t"${AppIDName}"\t已過期,刪除?"
echo "\033[31m$msg \033[0m"
rm $element
fi
done
echo "---------\033[32m檢測結(jié)束\033[0m---------"