Commanding The X server to take a .png screenshot through ssh?
Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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 `'.
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'.
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.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.