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
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:
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!
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 usesnotify-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.