我如何以非交互方式更新 FreeBSD 系统(和端口)?

obe*_*tet 7 freebsd

本质上,我正在寻找一个完全无声的、非交互式版本的

freebsd-update fetch
freebsd-update install
Run Code Online (Sandbox Code Playgroud)

portsnap fetch update
Run Code Online (Sandbox Code Playgroud)

小智 9

在 FreeBSD-10.2 上,有一个新选项允许这样做:

freebsd-update fetch --not-running-from-cron

从联机帮助页

 --not-running-from-cron
        Force freebsd-update fetch to proceed when there is no
        controlling tty.  This is for use by automated scripts and
        orchestration tools.  Please do not run freebsd-update
        fetch from crontab or similar using this flag, see:
        freebsd-update cron
Run Code Online (Sandbox Code Playgroud)


uch*_*ida 8

在 FreeBSD 10.0R 及更高版本上,在 freebsd-update 上设置 PAGER 环境变量

env PAGER=cat freebsd-update fetch
freebsd-update install
Run Code Online (Sandbox Code Playgroud)

对于FreeBSD 10.0R 和更高版本上的portsnap(8),默认行为,即没有--interactive选项,是非交互式的。

portsnap fetch update
Run Code Online (Sandbox Code Playgroud)


obe*_*tet 4

对于 FreeBSD < 10,以下工作有效:

允许在不连接到终端的情况freebsd-update下运行 fetch :stdin

sed 's/\[ ! -t 0 \]/false/' /usr/sbin/freebsd-update > /tmp/freebsd-update
chmod +x /tmp/freebsd-update
Run Code Online (Sandbox Code Playgroud)

允许在不连接到终端的情况portsnap下运行 fetch :stdin

sed 's/\[ ! -t 0 \]/false/' /usr/sbin/portsnap > /tmp/portsnap
chmod +x /tmp/portsnap
Run Code Online (Sandbox Code Playgroud)

学分:维维


对于 FreeBSD 10+,@uchida 下面的答案中的解决方案应该是首选!