Firefox 94 从 crontab 运行时声称“已经在运行,但没有响应”。

Firefox 94 从 crontab 运行时声称“已经在运行,但没有响应”。

我知道这里有或可能有类似的问题,但这个问题与 Firefox 启动时无关,firejail也没有任何延迟。

操作系统信息:

Xubuntu 20.04
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
VERSION_ID="20.04"
$ uname -a
Linux terrance-ubuntu 5.11.0-40-generic #44~20.04.2-Ubuntu SMP Tue Oct 26 18:07:44 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

在此处输入图片描述

我运行了一个脚本crontab,它将启动我的 ADP 登录页面并在一天中的特定时间对我进行打卡。在 Firefox 94 发布之前,它一直运行良好。现在,我明白了,对于远程,Mozilla 决定不再使用 X11,而是改用 D-Bus。就我而言,我无法理解使用 D-Bus 而不是 X11 是什么意思,除了他们声称它更易于使用。我猜这可能是由于我不使用的 Wayland。

如果我在特定时间从命令行终端运行以下脚本,它可以完美运行,但如果我从运行脚本,crontab我会收到以下消息:

在此处输入图片描述

剧本 (仍在进行中):

#!/bin/bash

#This function checks the path of the app on a Mac.
realpath1() {
        [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

#This function matches the day of the week and returns 0 if match, 1 if weekend.
function dowcheck(){
case " ${daysofweek[@]} " in
    *\ ${DOW}\ *)
        return 0;;
    *)
        return 1;;
esac
}

#This function matches if the clock in or out time is a match with 0 or 1 if not.
function timecheck(){
case " ${timesofday[@]} " in
    *\ ${HM}\ *)
        return 0;;
    *)
        return 1;;
esac
}

#This function matches days off to today.  If a match return 0 meaning day off, 1 means not a day off.
function daysoffcheck(){
case " ${daysoff[@]} " in
    *\ ${daymdy}\ *)
        return 0;;
    *)
        return 1;;
esac
}

#Check the OS type.
OS_TYPE=$(uname -a | awk '{print $1}')
if [[ ${OS_TYPE} == "Linux" ]]; then
        OS=$(grep -i ^name= /etc/*release | awk -F= '{print $2}' | sed 's/\"//g')
else
        OS=$(system_profiler SPSoftwareDataType | awk '/System Version:/ {print $3}')
fi
if [ "${OS}" = "CentOS Linux" ]; then
        OS=Fedora
fi

#Set working directories and set Display for running in a CRONJOB.
case $OS in
        macOS) apppath=/Applications/Firefox.app/Contents/MacOS
        export DISPLAY="/private/tmp/com.apple.launchd.*/org.macosforge.xquartz:0"
                PWD=$(dirname $(realpath1 $(which $0)));;
        *) apppath=/usr/bin
        DM=$(/usr/bin/basename $(/bin/cat /etc/X11/default-display-manager))
        case $DM in
            lightdm)
                export DISPLAY=:0;;
            gdm3)
                grep -E "# AutomaticLogin|AutomaticLoginEnable = false" /etc/$DM/*.conf >/dev/null && export DISPLAY=:1 || export DISPLAY=:0;;
            *);;
        esac
                PWD=$(dirname $(realpath $(which $0)));;
esac

#Set variables for matching functions.
DOW=$(date +%a)
HM=$(date +%H:%M)
daymdy=$(date +%m-%d-%Y)
#If today is newer than day off remove last day off.
if [[ "${daymdy}" > "$(head -1 $PWD/daysoff.txt)" ]]; then
    sed -i '1d' $PWD/daysoff.txt
fi

#Declare arrays.
declare -a daysofweek=('Mon' 'Tue' 'Wed' 'Thu' 'Fri')
declare -a timesofday=('08:00' '12:00' '12:30' '16:30')
declare -a inout=('in' 'out for lunch' 'in from lunch' 'out for the day')
declare -a daysoff=($(cat $PWD/daysoff.txt))

#Get in or out.
for i in "${!timesofday[@]}"; do
    if [[ "${timesofday[$i]}" == "${HM}" ]]; then
        inorout="${inout[$i]}";
    fi;
done

#Run functions and return 0 or 1.
daysoffcheck
doff=$?
dowcheck
dow=$?
timecheck
time=$?

#Finish up and send information or launch Firefox if need be.
if [[ $doff != "1" ]]; then
        echo "Today is a day off!  Why are you trying to clock in?"
        exit 1
elif [[ $dow != "0" ]]; then
        echo "It's the weekend!  Why are you trying to clock in?"
        exit 1
elif [[ $time != "0" ]]; then
        echo "It is $DOW at $HM.  It is not time to clock in or out."
        exit 1
else
        echo "It's ${HM}. Time to clock ${inorout}." | mail -s "Time clock" [email protected]
        echo "It's ${HM}. Time to clock ${inorout}." | mail -s "Time clock" [email protected] 
        xdotool mousemove --sync 677 1011
        $apppath/firefox --new-tab https://workforcenow.adp.com/workforcenow/login.html &
        $PWD/clock_in_out.bsh
        wait
fi

如果有人能让我让 Firefox 与 D-Bus 一起工作,就像 94 版之前的 X11 一样,我将不胜感激!

答案1

您的 crontab 脚本需要DBUS_SESSION_BUS_ADDRESS正确设置环境变量,即设置为桌面会话中使用的相同值。我自己将此方法用于notify-send在屏幕上显示通知的 crontab 脚本。此值通常对于每个用户都是静态的,即它不会在会话之间更改,仅取决于用户 ID,因此您可以简单地将其从桌面会话复制到脚本中。或者,为了始终确保使用正确的值,您可以将一个脚本放入会话启动程序中,将该值写入临时文件,然后您的 crontab 脚本从此文件中读取它。

相关内容