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

Ter*_*nce 3 firefox dbus

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

操作系统信息:

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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我运行一个脚本,该脚本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" mynumber@tmomail.net
        echo "It's ${HM}. Time to clock ${inorout}." | mail -s "Time clock" myemail@gmail.com 
        xdotool mousemove --sync 677 1011
        $apppath/firefox --new-tab https://workforcenow.adp.com/workforcenow/login.html &
        $PWD/clock_in_out.bsh
        wait
fi
Run Code Online (Sandbox Code Playgroud)

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

raj*_*raj 7

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

  • 对我也有用。我更改了这个 crontab 命令:`32 11 13-20 12 * export DISPLAY=:0 && firefox --new-window "/home/rob/Documents/crontab/Happy-Birthday-Paulette.htm" > /dev/null 2 >&1`。我在终端中运行了 `printenv` 并从输出的末尾得到了这个: `DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus` 我将其添加到 crontab 命令中: `32 11 13-20 12 *导出 DISPLAY=:0 && DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus firefox --new-window "/home/rob/Documents/crontab/Paulette's-Birthday.htm" > /dev/null 2>&1 ` 并且它有效。 (3认同)

归档时间:

查看次数:

640 次

最近记录:

4 年,7 月 前