0

I have a computer in remote location that I prefer to use as a server. I always keep the lid closed, and it is set to always keep running while the screen is off. Because I use this server to run software. I want to take screenshots to stay up to date of my apps that are running. I am wondering if there is a way to save an image, of an active window, when X server is not running.

Update: ps -e | grep X outputs PID: 581 for Xorg. So my Xserver is running.

Update: I am not using X11 forwarding.

Update: I need, if possible, to take a screenshot of the active window (firefox) on my remote machine. Save that screenshot on my remote machine then get it with scp host1:/path/to/screenshot/ localhost:/destinationfile

  • 2
    Hello and welcome to the Unix and Linux stack exchange site! Please review the Help Center for more information on how to best use this site. Do you mean like you want to be able to take screenshots when there is no graphical environment running or you want a "snapshot" of what processes/services/etc are currently running on your computer at a given moment? Please update your post to clarify on these details. Thank you! – kemotep Sep 19 at 20:11
  • 1
    How do you have an X window, without an X server? – ctrl-alt-delor Sep 19 at 21:18
  • @kemotep I want to take a screenshot when there is no graphical environment running. I just updated my post, stating that Xorg is in fact running. Thank you – Kornee Sep 20 at 6:00
  • @Kornee So are you using x11 forwarding when you ssh in? I just want to know if it would be easier to take screenshots of your remote desktop screen on your host vs if the screenshots need to originate or be saved on the remote laptop. Please edit your post to include where you want the screenshots saved (host/remote) and how you specifically connect to your remote device (what remote desktop software you are using). Thank you. – kemotep Sep 20 at 12:15
  • @kemotep I just updated my post. Citing that I am not using x11 forwarding, that I need to save the screenshot on my remote machine. Then I will get my screenshot with scp remote_host:/path/to/screenshot localhost:/destinationfile The reason I am doing this is that I use my iPhone to ssh to my remote machine. So x11 forwarding will be of no use. I think. – Kornee Sep 20 at 17:06
0

If you have things running in X, then X is still running. Killing X would kill most programs that are using it.

So, you can do a few things(remember you will need to set your DISPLAY variable on a remote term like DISPLAY=:0):

  1. Imagemagick has a utility called 'import' and running import -window root screenshot.png will give you a screenshot.
  2. scrot can take a screenshot, but I don't know the command line
  3. x11vnc can give you vnc access to a running X display
  • I already have an active window (firefox to be precise) on my server. I just updated my post stating that Xorg is in fact running. What I want to do, is be able to take a screenshot of firefox window on my server. Thank you – Kornee Sep 20 at 6:08
0

You want to use a utility like scrot.

Once you ssh into your remote computer you can run the following:

scrot '%Y-%m-%d_$wx$h.png' -e 'mv $f /home/user/shots/' 

This command will take a screenshot of your current screen with the filename of YEAR-MONTH-DAY_SCREENWIDTH_SCREENHEIGHT.png and move the file to your /shots directory (if you have one). If you need to run this at regular intervals without your input you could create a cronjob.

Create a bash script with the command you want to run. If you wanted to run the command every hour it would look like this:

#!/bin/bash
scrot '%Y-%m-%d-%H.png' -e 'mv $f /home/user/screenshots/'

And save this file in an appropriate location like /home/user/scripts and make it executable (chmod +x screenshot.sh)

Your user's crontab should contain this line if you want it to run every hour (run crontab -e to edit your user's crontab):

1 * * * * /home/user/scripts/screenshot.sh >/dev/null 2>&1

This will execute screenshot.sh at the first minute of every hour.

Alternatively you can save your script into /etc/cron.hourly to have it run hourly.

Here is a relevant post about working with crontab that you should check out.

Test to make sure that scrot works acceptably for your needs and also that your cronjob works correctly. You can then further automate the process to automatically email you the picture or push the picture to your computer with scp.

Best of Luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.