AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1376845
Accepted
Terrance
Terrance
Asked: 2021-11-22 10:14:11 +0800 CST2021-11-22 10:14:11 +0800 CST 2021-11-22 10:14:11 +0800 CST

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

  • 772

我知道这里有或可能有类似的问题,但这个问题与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

在此处输入图像描述

我运行一个脚本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 像在 94 版之前的 X11 一样与 D-Bus 一起工作,我将不胜感激!

firefox
  • 1 1 个回答
  • 296 Views

1 个回答

  • Voted
  1. Best Answer
    raj
    2021-11-25T02:58:00+08:002021-11-25T02:58:00+08:00

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

    • 7

相关问题

  • Flash 在 Firefox 中无法正常工作。不会响应某些点击[关闭]

  • Firefox 鼠标中键滚动

  • 如何解决 Firefox 中的字体问题?

  • 使用突触或通过 Firefox 的插件菜单安装 adblock?

  • Firefox 的 Ubuntu Firefox 修改扩展有什么作用?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve