LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-28-2006, 01:38 AM   #1
Infernal211283
Member
 
Registered: Nov 2004
Location: Mid. East / Israel
Distribution: Slackware 10.2, Gentoo
Posts: 157

Rep: Reputation: 30
Question Commanding The X server to take a .png screenshot through ssh?


Hello,

I have a program that runs on my X server which i'd like to monitor, i did that for some time now using vnc but that's just a waste of bandwidth for the program i'm monitoring and i just want to see it's progress so i figured that a snapshot image from time to time would be good enough.

I'm using fedora core 5, kde, it has ksnapshot which, besides requiring a key press locally in the X server, is good enough. (Pressing 'q' saves the image instantly after ksnapshot is called.)

Well that's what i researched but i need help to go further with that, like a script or something.

Thank you for reading this.
 
Old 06-28-2006, 02:19 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
xwd might be what you need. Grabs a specified screen, optionally to an image file. The screen may be on a remote X server.

--- rod.
 
Old 06-28-2006, 03:16 AM   #3
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,962

Rep: Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341
You can use import (from imagemagick) through a script that runs from cron to capture the screen. Something like:
Code:
#!/bin/sh
/usr/bin/import -window root screenshot.png
For more info:
Code:
import -help
 
Old 06-28-2006, 08:53 AM   #4
Infernal211283
Member
 
Registered: Nov 2004
Location: Mid. East / Israel
Distribution: Slackware 10.2, Gentoo
Posts: 157

Original Poster
Rep: Reputation: 30
Thanks for replying.

I tried both of the commands and both gave the same result:

They work well locally (i personally liked "import" better) but when i try to execute the same command when i connect remotly to the machine through ssh i get this message:

[infernal@infernal ~]$ /usr/bin/import -window "add account" screen.png
import: unable to open X server `'.


What should i do to make it work?
 
Old 06-28-2006, 09:20 AM   #5
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,962

Rep: Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341
Verify that you have enabled X forwarding on your ssh server, i.e. check sshd_config for:
Code:
X11Forwarding yes
Then after connecting to the server and before running import, run:
Code:
export DISPLAY=localhost:0.0
 
Old 06-28-2006, 10:21 AM   #6
Infernal211283
Member
 
Registered: Nov 2004
Location: Mid. East / Israel
Distribution: Slackware 10.2, Gentoo
Posts: 157

Original Poster
Rep: Reputation: 30
Thank you for replying.

I tried that, The X11Forwarding was already set to 'yes', i exported DISPLAY=localhost:0.0 when i connected to the server but i got that message again only this time with DISPLAY's content:

[infernal@fedora30 ssh]$ import -window "add account" screen1.png
import: unable to open X server `localhost:0.0'.
 
Old 06-28-2006, 01:06 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
infernal & bathory:

As I interpret the question, the problem is that there is a running application, 'Y', using an X server, both on host 'A', and that infernal211283 wants to monitor it's progress from a remote host 'B' (which may or may not be hosting an X server). If I've interpretted the question correctly, then X forwarding will not solve the problem, because the application of interest is already bound to the X server running on host 'A'. If I've misinterpretted the problem, then just disregard my words below.

A solution is to grab snapshots of the application's X window(s), either on a regular periodic basis, or on demand, and then display &/or archive them as image files. How this can be done is to first get the identity of the window(s) used by application 'Y' on X server at 'A'. The tool xwininfo can be used to do this. Knowing the identity of the window, one can then use xwd to grab the specified window to an image file (one would have to use a conversion tool, such as Imagemagick, to convert the image to the diseored format). The 'specified window' can exist on any X server that is reachable, and is allowing connections from the host 'B'. Note that the xwd tool runs on host 'B', but communicates with the X server on host 'A' in this scenario. The X server at 'A' would need to allow this communication (man xhost, xauth). There are numerous details to this that have been left as the proverbial exercise for the reader.

--- rod.
 
Old 06-28-2006, 02:33 PM   #8
Infernal211283
Member
 
Registered: Nov 2004
Location: Mid. East / Israel
Distribution: Slackware 10.2, Gentoo
Posts: 157

Original Poster
Rep: Reputation: 30
That's great!
You got the question right and your answer was very useful,
I managed to take an image snapshot remotely and i'll get imagemagick to convert the file to something i can view, hopefully i won't be asking for help at this one

Thanks a lot for that one.


Quote: "Note that the xwd tool runs on host 'B', but communicates with the X server on host 'A' in this scenario."

^ The case was actually that i run xwd after i'm already connected to the ssh server (the 'A' host).. will i be mistaken if i'll think that xwd actually runs on 'A' host and not on 'B' host?
 
Old 06-28-2006, 02:44 PM   #9
Infernal211283
Member
 
Registered: Nov 2004
Location: Mid. East / Israel
Distribution: Slackware 10.2, Gentoo
Posts: 157

Original Poster
Rep: Reputation: 30
Thumbs up

Just one more thing..

You can also use GIMP to view the file created with xwd, then save it as a regular image.

Thanks all for your replies.
 
Old 06-28-2006, 02:58 PM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by Infernal211283
That's great!

Quote: "Note that the xwd tool runs on host 'B', but communicates with the X server on host 'A' in this scenario."

^ The case was actually that i run xwd after i'm already connected to the ssh server (the 'A' host).. will i be mistaken if i'll think that xwd actually runs on 'A' host and not on 'B' host?
Now that you've posed the question, I realize that it can be done either way. Probably much simpler to run it on the same host as the X server host (ie on 'A'). Gets around any complications arising from X security. However, if it runs on 'A', you still have to transport the image(s) back over to 'B'. xwd does that silently for you in my original scenario.

I suggested Imagemagick, bcause it sounded like you were chasing a scheme that could run in some automated fashion, and Imagemagick is tailor-made for that sort of thing.

--- rod.
 
Old 06-28-2006, 03:55 PM   #11
Infernal211283
Member
 
Registered: Nov 2004
Location: Mid. East / Israel
Distribution: Slackware 10.2, Gentoo
Posts: 157

Original Poster
Rep: Reputation: 30
Got that, thanks theNbomr.
 
Old 06-27-2008, 10:51 PM   #12
brettalton
LQ Newbie
 
Registered: Dec 2006
Posts: 5

Rep: Reputation: 0
What you are looking for is:
Code:
xwd -out screenshot.xwd -root -display :0.0 | xwdtopnm | pnmtopng > screenshot.png
You can keep it in .xwd format and opening it in GIMP by simply using:
Code:
xwd -out screenshot.xwd -root -display :0.0
 
  


Reply

Tags
fc5


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
commanding screen from elsewhere jedihawk Linux - Software 6 07-20-2005 12:08 PM
commanding from another computer jaakkop Slackware 10 01-31-2005 12:10 PM
Webalizer: configure: error: png library not found... please install png. mikeshn Linux - Software 5 01-10-2005 03:28 PM
Screenshot through SSH help EnVoy Linux - General 5 04-05-2003 07:02 PM
Where is trashcan_full/empty.png and kmenu.png??? d33pdream Linux - General 2 02-26-2003 12:13 AM


All times are GMT -5. The time now is 05:14 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration