How can I take a screenshot from all monitors with screencapture or other tools? I wanted to use screencapture to take a screenshot of all monitors from within a script, but this only seems to capture the main monitor. How can I use screencapture or any other tool callable from the command line to capture all monitors?
It's poorly documented, but it is indeed possible with the screencapture command.

screencapture ~/Desktop/screen1.png ~/Desktop/screen2.png [...]


Here's the relevant section from man screencapture:

 files   where to save the screen capture, 1 file per screen


Of course, if you're calling it programmatically, you might not know how many monitors there are, so you'll have to parse the output of system_profiler SPDisplaysDataType or defaults read /Library/Preferences/com.apple.windowserver.plist to determine how many filename arguments to pass to screencapture. For example:

$ system_profiler SPDisplaysDataType | grep "Online: Yes" | wc -l
       2


References  

https://stackoverflow.com/questions/20099333/terminal-command-to-show-connected-displays-monitors-resolutions
http://hintsforums.macworld.com/showthread.php?p=695603