Introduction: How to Get a Screenshot Through SSH

Picture of How to Get a Screenshot Through SSH

I needed a quick and easy way to have a screenshot with a simple command from SSH console.
This is the result of 10 minutes of work that uses only freeware and is easly usable onder all windows that can run a SSH server.

Step 1: For This to Work You Need the Folowing Applications :

- sleep.exe (from WAIK KIT)
  http://www.microsoft.com/download/en/details.aspx?id=10333

- tiny.exe (a very small and simple web server)
  http://en.kioskea.net/faq/2568-tinyweb-server-on-windows

- topng.exe (a good utility for converting files)
  http://www.bcheck.net/apps/
  http://www.bcheck.net/apps/topng.htm

- CmdCaptureWin.exe
  http://www.ducklink.com/free-command-line-screen-capture.php
 
- FreeSSHd (a nice SSH and Telenet server, if you dont already have one)
  http://www.freesshd.com/

All of them are freeware and easy to download from the internet.
But i add them to this instructable too.

Step 2: The Scripts Aka Cmd Files

We gonna write 5 cmd files (3 for screensot and 2 for the webserver logs) and one html file, all with the help of the old and trusty notepad.

cap.cmd  - it makes a png screenshot with the help of scheduled task job
pic.cmd   - it converts the png screenshot in a nice smaller jpg called bild.jpg
web.cmd - it starts the web server on port 8000 for 30 seconds to serve
                    the screenshot jpg, it accepts 2 command line arguments, first
                    argument, changes the runtime of the webserver to the seconds inputed
                    and the second argument is the port number.
                    web 120 - runs the webserver for 120 seconds on default port 8000
                    web 120 6000 - runs the webserver for 120 seconds on port 6000


log2html.cmd  - it converts the webserver logs in html form
clearlogs.cmd - it delets the html logs and empty the log files
You need to run the server a second time to read the logs from the first
session.

OBSERVATION: PUT ALL YOUR FILES IN A SINGLE FOLDER THAT IS EASLY ACCESIBLE FROM SSH. (My are in C:\Bild)

Step 3: Setup : Schedulded Task Job

Picture of Setup : Schedulded Task Job

First you need to setup the scheduled task like in the step by step picture tutorial that folows. We need to run the screenshot application troght scheduled task then SSH dont offer session interactivity, that results in a black screenshot or a 'stuck' screenshot program. But we can run a program that is part of windows that IS SESSION INTERACTIVE.

In the pictures from 1 to 11 it is described how to creat a schedulde task job that is with the following settings :

Name: CmdCap
Type: Run Once
Time: 06.00
Data: 01.01.1980
what to run is CmdCaptureWin.exe

Follow the pictures and make all settings as in the pictures.
if you get the error message as shown ignore it and at advanced settings that opens when complet type your username.

Step 4: Cap.cmd

Save this in cap.cmd

-------COPY UNDER THIS LINE-------
@ECHO OFF
schtasks /run /tn CmdCap
-----END COPY OVER THIS LINE -----

What dose this:

Run the scheduled tasks job called "CmdCap" (we made this job)

Step 5: Pic.cmd

Save this in pic.cmd

-------COPY UNDER THIS LINE-------
@ECHO OFF
ECHO Y | ren Snap*.png bild.png
topng bild.png jpg
ECHO Y | del bild*.png
-----END COPY OVER THIS LINE -----

What dose this:

rename the file Snap(time stamp).png to bild.png
convert bild.png to bild.jpg
delete bild.png

Step 6: Web.cmd

Save this in web.cmd

-------COPY UNDER THIS LINE-------
@ECHO OFF
Echo.
Echo web.cmd [Timeout in seconds] [Port]
Echo.
SET Timeout=%1
SET Port=%2
IF [%1]==[] SET Timeout=30
IF [%2]==[] SET Port=8000
start TINY.EXE "%CD%" %Port% /nowait
Echo Webserver at port %Port% for %Timeout% seconds.
"%cd%\sleep.exe" %Timeout%
taskkill /F /IM TINY.EXE /T
-----END COPY OVER THIS LINE -----

What dose this:

define to default variables with default values 30 and 8000
run server on port %Port%
wait for %Timeout% seconds
closes the server process

Step 7: Log2html.cmd

Save this in log2html.cmd

-------COPY UNDER THIS LINE-------
@ECHO OFF
ECHO Y | del access_log.htm
ECHO Y | del agent_log.htm
ECHO Y | del error_log.htm
ECHO Y | del referer_log.htm
ECHO Y | ren access_log access_log.htm
ECHO Y | ren agent_log agent_log.htm
ECHO Y | ren error_log error_log.htm
ECHO Y | ren referer_log referer_log.htm
-----END COPY OVER THIS LINE -----

What dose this:

delete html converted log files created before
convert log files to html files

Step 8: Clearlogs.cmd

Save this in clearlogs.cmd

-------COPY UNDER THIS LINE-------
@ECHO OFF
echo. >access_log
echo. >agent_log
echo. >error_log
echo. >referer_log
ECHO Y | del access_log.htm
ECHO Y | del agent_log.htm
ECHO Y | del error_log.htm
ECHO Y | del referer_log.htm
-----END COPY OVER THIS LINE -----

What dose this:

empty the content of the log files
delete converted html log files

Step 9: How to Use All This ?

Connect with putty or your SSH client to the server.
First run cap.cmd
Second run pic.cmd
Third run web.cmd

How to access the image ?
Open your web browser (Google Chrome, Firefox, Internet Explorer, ...) and type
http://125.125.125.125:8000
Where 125.125.125.125 is the hosts IP and 8000 the port number.
The IP is the same you typed in putty.

Hope you enjoy all this and helps you too.

PS
Yes, i know that exists VNC servers and that you can grab only a picture but VNC is not encrypted and if you need only a screenshot, my method is faster.

Comments

Computothought (author)2012-01-14

Tnx but i already know how to run different services through a SSH, aka tunneling, im useing SSH tunnel for my subsonic mediacenter at my home. I use this to see a report that is updated every 30 minutes and the machine is a box in the basement. All runs from alone and we dont need a VNC for that, is just to be over 100% shure that all is ok. :D

About This Instructable

3,249views

2favorites

License:

More by neumanngregor:Web Scraping With RubyConvert a HG658 Huawei Router to a RepeaterHow to repair Windows 10 recovery loop error without a reinstall
Add instructable to: