User Tools

Site Tools


Remote Screen Capture of a Desktop

Scenario: The ship has a linux computer, you want a desktop screen capture that you can view on your own local computer.


  • shipuser@shiplinux
  • landuser@landserver
  • me@mycomputer

## landuser@landserver must be able to ssh into shipuser@shiplinux Set up a ssh key so this is automatic.

## me@mycomputer must be able to ssh (with a key) into landuser@landserver

Step 1: On the Ship

Make a bash script that looks like this:

## begin remote_screenshot.bash ##

## store the image in ~/tmp
## image will be called "screenshotX.png"
cd ~/tmp; DISPLAY=":0.0" import -window root screenshotX.png

## give a clue
echo "on ship: desktop captured in ~/tmp/screenshotX.png"

Make it executable and test:


And view the figure it made: ~/tmp/screenshotX.png

Step 2: On Shore

And on the landside server, make this script to execute screenshotX.png on the ship, and rsync the file back. Call this one remote_shipX_screenshot.bash

## begin script to get the screenshot back to the landserver ##

## works best if there is an ssh key on the remote machine
# - make the remote command for screenshot
# - this example requires a port to log in

ssh  -p ##### shipuser@shipserver /path/to/remote_screenshotX.bash

## bring it back, put it in /tmp
echo "bringing back the screenshot"
rsync -Pv -e 'ssh -p 56565' shipuser@shipserver:tmp/screenshotX.png /tmp

## move it to the location of choice
mv /tmp/screenshotX.png /path/to/server/shipX/shipuser_screenshotX.png

Test it by running


and view the png

Step 3: Wrapping with an HTML

Now if you are on the landserver you can look at the png file. If you want the png served up on a web location, you can look at it directly. If you want an html to wrap it, so it refreshes every so often, put this in the same location as shipuser_screenshotX.png:


##begin html file to display shipuser_screenshtX.png ##

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Refresh" content="300">
<title>ShipX Desktop</title></head>
<img src="./shipuser_screenshotX.png" style="width: 100%"/>

Then you can browse to this page and it will refresh every 5 min: http://shipserver/path/to/shipX/shipuser_screenshotX.html

Step 4: Creating a cronjob

Make the landuser@landserver have a crontab entry to run the program hourly at 10 min past the hour.

NOTE: crontab does not have a good environment so if you need to set your PATH, do so in a bash_env file and source that before running the command. That's how I did it. Or be very explicit about setting your PATH first.This is all one line:

10 */1 * * * (date +\%F\ \%T; cd /path/to/myenv; . ./bash_env; 
/path_to_script/remote_shipX_screenshot.bash) >> /path/to/logfiles/shipXscreenshot.log 2>&1

Another note: I also outputted the stdout to a log file.

Step 5: Running from your laptop

ssh landuser@landserver /path/to/scripts/remote_shipX_screenshot.bash

or make an alias:

alias get_shipX_screenshot='ssh landuser@landserver /path/to/scripts/remote_shipX_screenshot.bash; echo o 
"view this file"; echo "";echo http://shipserver/path/to/shipX/shipuser_screenshotX.html'

*Special thank you to Jules Hummon for providing steps/codes above.

public/remote_screen_capture_of_desktop.txt · Last modified: 2020/10/02 15:04 by rhudak