Journal sootman's Journal: Changes in 'screencapture' from Tiger to Leopard 8
OS X ships with a great little command-line utility called 'screencapture.' It is a command-line interface to OS X's screen capture tool, which is activated from the desktop by pressing shift-command-3. If you want to monitor a computer you're not sitting at (10.4 or earlier--see below) just ssh in and say something like
screencapture -x screen.png
and then view the file--scp it to the computer you're sitting at, or use FTP, or whatever. It's a standard unix-style command, simple as can be--'screencapture' does just what you'd expect it to, the '-x' means "don't play the 'click' sound" and then you specify the output file, 'screen.png' in this example. (This worked in earlier versions of OS X with some changes. 10.3, for example, saved screen caps as PDFs so you'd say 'screen.pdf' instead.)
You have to run that as the logged-in user or as root. One of the things I used it for was to monitor some conference rooms that I'm in charge of by running this script and saving the file to a web-viewable directory. To do this on a stock 10.4 machine, just create a file called 'screen.pl' in
#!/usr/bin/perl
use CGI;
$cgi = CGI->new();
print $cgi->header;
print qq~<html>\n<head>\n<title>View Screen</title>\n</head>\n<body>\n~;
my $step1 = qx!screencapture -x/Library/WebServer/Documents/screen.png!;
print qq~<img src='/screen.png' border='1'>\n~;
print qq~</body>\n</html>\n~;
1;
It's a Perl script, so 'chmod 755' it, and there should be a blank line at the end, IIRC. Make sure the user this script will be running as can write to
User www
Group www
to
User conference
Group conference
(Remember to restart the webserver for these changes to take effect. (sudo apachectl graceful) Also note that dpending on various things, the group name may or may not be the same as the user name. ls
So everything was going along fine until 10.5 came out. They seem to have slammed the door on running screencapture in any way remote way. Even if you ssh in as the user who is currently logged in it won't let you. But you can then log in locally, press 'up' one time to call the same command out of
Rootkit potential must have killed it (Score:2)
fix straight from the man page (Score:1, Informative)
SECURITY CONSIDERATIONS
To capture screen content while logged in via ssh, you must launch screencapture in the same mach bootstrap hierarchy as loginwindow:
PID=pid of loginwindow
sudo launchctl bsexec $PID screencapture [options]
So as a user with adminstrator rights, something like this does well enough:
sudo launchctl bsexec `ps ax | grep "[l]oginwindow" | awk '{ print $1 }'`
Re: (Score:2)
Thanks for the example, it worked perfectly. The only downside is that this w
Re: (Score:1, Informative)
Also, to set up a repetitive task under OS X I think you should rather set up a LaunchAgent than use an old school cronjob. I'm more of a Linux/BSD person myself and still learning about OS X
Re: (Score:1)
"# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# Runas alias specification
# User privilege specification
root ALL=(ALL) ALL
%admin ALL=(ALL) ALL
www ALL=(ALL) NOPASSWD: ALL
# Uncomment to
Re: (Score:2)
and all I knew was that it was one way to run commands and that it worked. :-) Actually, the full script that I'm using still does have stuff like that--above the screenshot it shows the date, uptime, who's logged in, etc. I just stripped out everything non-essential for
pty problem? (Score:2)
My best guess is that they are looking are your pseudo-tty. If that's the case, you may be able to create a creative chroot jail for the screen cap program, which rejigs the label your pty is every time you log in from remote.
If it's a deeper check, you may need to start wrapping some dylibs in a very creative way.