Score:2

Firefox 94 when ran from a crontab claims "is already running, but is not responding."

id flag

I understand that there are or may be similar questions on here, but this one does not pertain to firejail nor does Firefox have any delays when starting.

OS Info:

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

enter image description here

I run a script from a crontab that will launch my ADP login page and clock me in and out at specific times of the day. This used to work flawlessly until Firefox 94 was released. Now, I understand that for remote Mozilla decided to no longer go with X11 but D-Bus instead. For the life of me, I cannot figure out what is meant by using D-Bus instead of X11, other than they claim that it is simpler to use. I am assuming that this may be due to Wayland which I do not use.

If I run the following script from a command line terminal at the specific times it works perfect, but if I run the script from the crontab I get the following message:

enter image description here

The script (still a work in progress):

#!/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

If anyone has any ideas that I could make Firefox work with D-Bus like it was with X11 before version 94 I would greatly appreciate it!

Terrance avatar
id flag
P.S. It will work fine with Waterfox, but there is a refresh page issue with Waterfox that kind of annoys me. :)
raj avatar
cn flag
raj
You probably have to pass the correct value of `DBUS_SESSION_BUS_ADDRESS` environment variable from your desktop session to your crontab script. I do it for my crontab script that uses `notify-send` to display notifications on the screen (these also use D-Bus). I have a script in my GNOME session startup programs that writes value of this variable to a temporary file on login, and the crontab script reads from this file.
Terrance avatar
id flag
@raj Yep, that was it! I did the `printenv` and grabbed the line of `DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus` and exported it right before the `firefox` command in the script and now it works great! You wanna write that up as an answer? Thanks again!
Score:6
cn flag
raj

Your crontab script needs to have the environment variable DBUS_SESSION_BUS_ADDRESS correctly set, ie. to the same value that is used in your desktop session. Myself I use this method for a crontab script that uses notify-send to display notifications on screen. This value is usually static per user, ie. it does not change between sessions, depends only on the user ID, so you may simple copy it from your desktop session to your script. Or to be always sure that you use the correct value, you may put a script into your session startup programs, that writes out this value to a temporary file, and your crontab script reads it from this file.

Rob avatar
vn flag
Rob
Works for me too. I changed this crontab command: `32 11 13-20 12 * export DISPLAY=:0 && firefox --new-window "/home/rob/Documents/crontab/Happy-Birthday-Paulette.htm" > /dev/null 2>&1`. I ran `printenv` in the terminal and got this from the end of the output: `DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus` I added it to the crontab command: `32 11 13-20 12 * export 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` and it works.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.