Can Cron Works Use Gnome-Open?

I am running Ubuntu 11.10 (Unity interface) and I have created a Bash script that uses "gnome-open" to open a series of web pages that I use every morning. When I manually execute the script in the terminal, the Bash script works fine. Here's a sample script (this is all the same, so I shortened it):

#!/bin/bash gnome-open 'https://docs.google.com'; gnome-open 'https://mail.google.com'; 

Since it seemed to work well, I added work to my crontab (mine, not root) to execute every weekday at a specific time.

Here's the crontab entry:

 30 10 * * 1,2,3,4,5 ~/bin/webcheck.sh 

The problem is that this error is returned for every gnome-open command in the Bash script:

GConf-WARNING **: client could not connect to the D-BUS daemon: Failed to start the dbus daemon without $ DISPLAY for X11 GConf-error: no D-BUS daemon Error: no display specified

I tried to figure it out. The first thing I tried was to restart the daemon using SIGHUP:

 killall -s SIGHUP gconfd-2 

This did not work, so I tried to start the dbus daemon using this code from the man page to start dbus:

 ## test for an existing bus daemon, just to be safe if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then ## if not found, launch a new one eval `dbus-launch --sh-syntax --exit-with-session` echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS" fi 

But it did nothing.

I tried adding just "dbus-launch" at the top of my Bash script, and that didn't work either.

I also tried editing crontab to include the path to Bash, because I saw this sentence in a different thread, but that didn't work.

Any ideas on how I can run this and run it?

+4
source share
2 answers

This is how the problem was resolved. It turns out that the problem was mainly caused by the fact that Bash did not have access to the X window session (or at least as I understood it). Therefore, my problem was resolved by editing my crontab as follows:

 30 10 * * 1,2,3,4,5 export DISPLAY=:0 && ~/bin/webcheck.sh 

The export DISPLAY =: 0 statement told cron to be used for display. I found the answer in this archived Ubuntu forum after searching "no display" or something similar:

http://ubuntuforums.org/archive/index.php/t-105250.html

So, every time I logged in, at exactly 10:30, my system automatically starts a series of web pages that I need to watch every day. Saves me the opportunity to go through the difficult process of entering my three-letter alias every time :)

+3
source

Glad you asked!

It depends on when it is running.

If Gnome GDM Greeter is active, you can use the DBUS session from the login dialog if you want. You can, for example, use this to send notifications to the login screen if no one is logged in:

 function do_notification { for pid in $(pgrep gnome-session); do unset COOKIE COOKIE="$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ|cut -d= -f2-)" GNUSER="$(ps --no-heading -o uname $pid)" echo "Notifying user $GNUSER (gnome-session $pid) with ' $@ '" sudo -u "$GNUSER" DBUS_SESSION_BUS_ADDRESS="$COOKIE" /usr/bin/notify-send -c "From CRON:" " $@ " done unset COOKIE } 

As you can see, the above code just runs the same command ( notify-send ) in all available gnome sessions when called as:

 do_notification "I wanted to let you guys know" 

You can select it separately and use it for your own purposes.

+2
source

Source: https://habr.com/ru/post/1382386/


All Articles