我正在尝试获取标记为具有“安全更新”的软件包列表
我的基础系统是 Ubuntu 14.04
例如,Ubuntu 14.04 上有一个脚本,它会列出可用更新的数量。dynamic-ish motd 会使用它。
/usr/lib/update-notifier/apt-check
运行没有参数的程序会将分号分隔的输出提供给 stderr,例如:
$ /usr/lib/update-notifier/apt-check
60;11 <-- (this is actually standard error)
此脚本有“人性化”和“软件包名称”标志。太棒了!但“软件包名称”只会转储正在更新的软件包,而不会将它们放入安全/非安全堆中。
我如何知道“安全更新”存储桶里有什么?
我尝试过类似的事情:
apt-get -s dist-upgrade | grep "^Inst" | grep -i security
那个对我来说不起作用。
我正在考虑拆开 apt-check 脚本并重新使用它,但在那之前我想知道是否有现有的工具可以做我想做的事情。
更新
我最终修改了 Python 脚本“/usr/lib/update-notifier/apt-check”,并添加了输出,以便在该脚本使用“isSecurityUpgrade()”函数进行检查时打印软件包详细信息。(有关详细信息,请参阅该脚本)
答案1
编辑:很抱歉没有在评论中询问,但我太新了,没有代表。
如果您只是在寻找那些来自安全存储库的内容,我会使用下面的 cron 从我们未监控的服务器每周给我发送一次电子邮件。
#!/bin/bash
#-------------------------------------------------------------------------------------------------#
#- Name....: checkSecurityupdates.sh
#- Notes...:
#-------------------------------------------------------------------------------------------------#
# create fresh securities file each run
grep "-security" /etc/apt/sources.list | sudo grep -v "#" > /etc/apt/security.sources.list
echo "created security specific source list"
# Create the security file list
echo 'n' | apt-get upgrade -o Dir::Etc::SourceList=/etc/apt/security.sources.list >> /root/securities-to-update.txt
echo "created list of security updates"
# What's the mimetype
get_mimetype(){
# warning: assumes that the passed file exists
file --mime-type "$1" | sed 's/.*: //'
}
# some variables
from="[email protected]"
to="[email protected]"
subject=`hostname`
boundary="ZZ_/afg6432dfgkl.94531q"
body="Please see attached"
declare -a attachments
attachments=( "securities-to-update.txt" )
# Build headers
{
printf '%s\n' "From: $from
To: $to
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=\"$boundary\"
--${boundary}
Content-Type: text/plain; charset=\"US-ASCII\"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
$body
"
# now loop over the attachments, guess the type
# and produce the corresponding part, encoded base64
for file in "${attachments[@]}"; do
[ ! -f "$file" ] && echo "Warning: attachment $file not found, skipping" >&2 && continue
mimetype=$(get_mimetype "$file")
printf '%s\n' "--${boundary}
Content-Type: $mimetype
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$file\"
"
base64 "$file"
echo
done
# print last boundary with closing --
printf '%s\n' "--${boundary}--"
} | sendmail -t -oi
echo "sent security updates list"
# cleanup security files
rm /etc/apt/security.sources.list
rm /root/securities-to-update.txt