5

I set up a automated kickstart-installation for a "digital-signage-client" based on Fedora 30 (soon 32), and I need to get an actual visual feedback what is on the screen right now. I tried to enable the Gnome-Remote-Desktop via commandline (see Enable Gnome Screen Sharing via Commandline?) but unfortunately I'm not able to.

So the new approach is, to take a screenshot (and copy it via scp). While I'm able to take a screenshot directly on the client via a gnome-terminal with gnome-screenshot, I don't know how I can do this from remote. I also tried other tools like KDE Spectacle or Shutter but also without luck.

An Idea was to set a cronjob to take the screenshot:

$> crontab -e

1 * * * * gnome-screenshot

but this doesn't work eighter. journalctl _COMM=cron says -- No entries --

Has someone an idea how I can take a screenshot from a Gnome-Wayland-Fedora Desktop? Should this work via crontab?

1 Answer 1

7

For Wayland

Based on information from n-tchen, Flameshot (in the Fedora repos) works well:

flameshot screen -p ~/

If you are connected via ssh, add WAYLAND_DISPLAY=wayland-0 at the beginning of the above line.

You can also use gnome-screenshot instead of Flameshot, but you'll still need the above addition for ssh.

Additional information (source):

The cross-platform way to take screenshots on Wayland is via xdg-desktop-portal (which also works outside of Flatpak). See https://github.com/flatpak/xdg-desktop-portal/blob/master/data/org.freedesktop.portal.Screenshot.xml

Finally, Pyscreenshot supports Wayland; see the GitHub README

For X11

The import command from ImageMagick does a great job of screenshots:

import -silent -window root /tmp/screenshot.jpg

If you are connected via ssh, add DISPLAY=:0.0 at the beginning of the above line, and you'll need to be logged in as the same user that is logged in locally.

If you want to run this in crontab, here is how to set it up. This will take a screenshot every 6 minutes and store it with a date-time-encoded filename in /root/monitor/. It has been tested on Ubuntu 16.04 and 18.04.

echo -n "/bin/bash -c '"                                                                  >cronexec
echo -n   'export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && ' >>cronexec
echo -n   'export HOME=/root && '                                                        >>cronexec
echo -n   'export D1=/tmp/gneemp && '                                                    >>cronexec
echo -n   'export F2=`date --utc +/root/monitor/%Y-%m-%dT%H:%M.jpg` && '                 >>cronexec
echo -n   'mkdir -p $D1 && '                                                             >>cronexec
echo -n   'chmod 643 $D1 && '                                                            >>cronexec
echo -n   'DISPLAY=:0.0 sudo -u `who --users |head -1 |grep -o "^\S*"` import -quiet -silent -window root $D1/tmp.jpg && '  >>cronexec
echo -n   'mkdir -p /root/monitor && '                                                   >>cronexec
echo -n   'mv $D1/tmp.jpg $F2 && '                                                       >>cronexec
echo -n   'rmdir $D1 '                                                                   >>cronexec
echo    "'"                                                                              >>cronexec
perl -p -i -e 's|\%|\\\%|g;' cronexec # from the manpage:  "Percent-signs (%) in the command, unless escaped with backslash (\) ..."
(sudo crontab -l 2>/dev/null; echo -n "*/6 * * * * "; cat cronexec) |sudo crontab - && rm cronexec
6
  • Hello bitinerant, thanks for your answer. I tried this, but I get an X-Error: $ export DISPLAY=:0.0 $ import -silent -window root /tmp/screenshot.jpg import: unable to read X window image root: Resource temporarily unavailable @ error/xwindow.c/XImportImage/4972. import: missing an image filename /tmp/screenshot.jpg @ error/import.c/ImportImageCommand/1289. I guess it is also wayland on Ubuntu?
    – n-tchen
    May 11, 2020 at 11:14
  • 1
    @n-tchen - Sorry, the $DISPLAY variable is for X11. If you're on Wayland, check the value of $WAYLAND_DISPLAY (details) while seated at the computer and use that via ssh instead.
    – bitinerant
    May 11, 2020 at 11:20
  • Thanks once more. I set $WAYLAND_DISPLAY=wayland-0 like on the client directly (this should also be the fallback), now I get an different X-Error: import -silent -window root /tmp/screenshot.jpg import: unable to open X server ' @ error/import.c/ImportImageCommand/359.` The manual of import says: saves any visible window on an X server and outputs it as an image file. But this should also work with wayland?
    – n-tchen
    May 11, 2020 at 12:15
  • 1
    @n-tchen - I have updated my answer with information about Wayland
    – bitinerant
    May 11, 2020 at 13:26
  • Thanks again. I just installed flameshot from the Fedora repos, at first I couldn't get it to work (wrong options). BUT because of your first comment I got the idea to try gnome-screenshot again with export WAYLAND_DISPLAY=wayland-0 - and this did work! So I tried it again with flameshot, also with set WAYLAND_DISPLAY, and flameshot screen -p ~/ also worked! Do you want the flameshot and the gnome-screenshot commands at the top of your answer, so I can mark it as solution? Thanks once more!
    – n-tchen
    May 11, 2020 at 15:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .