shell脚本
#!/bin/bash
#sh ~/tool/bin/del_profiles.sh 27S6F6T0JP.com.yhs.abc
arg1=$1
echo $arg1
echo "开始"
cd /Users/$(whoami)/Library/MobileDevice/Provisioning\ Profiles/
for element in `ls /Users/$(whoami)/Library/MobileDevice/Provisioning\ Profiles/ `
do
cmd=`security cms -D -i $element`
result=$(echo $cmd)
# ${file##*.}:删掉最后一个 . 及其左边的字符串:txt
# ${file%%.*}:删掉第一个 . 及其右边的字符串:/dir1/dir2/dir3/my
result=${result##*application-identifier}
# ${file%/*}:删掉最后一个 / 及其右边的字符串:/dir1/dir2/dir3
result=${result%com.apple.developer.team-identifier*}
result=${result%</string>*}
result=${result##*string>}
if [[ $result == $arg1 ]]; then
echo 'rm '$element$result
rm $element
fi
ExpirationDate=$(echo $cmd)
ExpirationDate=${ExpirationDate##*ExpirationDate}
ExpirationDate=${ExpirationDate##*<date>}
ExpirationDate=${ExpirationDate%</date>*}
ExpirationDate=${ExpirationDate:0:10}
today=`date +%F`
if [ ${#ExpirationDate} -eq 10 ];then
if [[ $today > $ExpirationDate ]]; then
echo "已过期 $ExpirationDate < $today "
echo "rm $element"
rm $element
fi
fi
done
# open /Users/$(whoami)/Library/MobileDevice/Provisioning\ Profiles/
echo "结束"
网友评论