shell脚本
有需要的小伙伴直接拿去用吧,转载的话记得注明出处哦
#!/bin/bash
getBetweenDays() {
start=$1
end=$2
p='0'
startDate=$( date -j -v+"$p"d -f "%Y%m%d" "$start" +%s) # +%s代表转成时间戳
# 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'天内过期'
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检测结束\033[0m---------"
网友评论