仅在当天首次登录时运行Linux图形程序

问题描述 投票:-1回答:1

我想设置我的系统在每天第一次登录时运行Thunderbird(需要x11)(所以如果我在同一天重启,它就不会运行)。我该如何设置呢?


为我启动Thunderbird的最简单方法是使用.xinitrc,但我不知道有一种干净的方法将其限制为每天只运行一次。

我这样做的方法是比较今天的日期和最后一次开机时间(在此之前),但我不知道这是一个标准化的方式,所以我问这个问题而不是XY Problem

linux x11 autostart
1个回答
0
投票

我最终没有找到一个惯用的方法来获取最后的启动日期所以我决定将它们存储在自定义文件中,而不是使用/etc/rc.local(在我的系统上启动时执行),如下所示:

# Save boot time
date +%s >> /var/log/bootdate

然后,我可以在.xinitrc中使用此文件,只有在最后一次启动的日期不是今天(即这是当天的第一次启动)时启动Thunderbird:

lastboot="$(date +%D -d@"$(tail -2 </var/log/bootdate | head -1)")"
today="$(date +%D)"
if [ "$today" != "$lastboot" ]; then
    # Run given programs only on the first boot of the day
    thunderbird &
fi
© www.soinside.com 2019 - 2024. All rights reserved.