Automating screencapture using SSH

Discussion in 'Mac Programming' started by ac-mac, May 27, 2007.

  1. ac-mac macrumors member

    Joined:
    Apr 9, 2007
    Location:
    England
    #1
    OK... so I am a newb programmer, I mean I just started yesterday (although I did some Basic before switching) and this is what I need to do.

    1) Log on to a network computer using SSH
    2) Take a screenshot of that computer every 10 seconds and copy it to my computer

    and then after I have taken enough screenshots (which will vary depending on user activity)

    3) Delete the file myusername@myIP in the network computer's Home folder
    4) Delete the screenshot file
    5) Empty the trash

    I would like all these things to be done without the user knowing their happening - ie no dialog boxes, no alert sounds etc

    I know that most programmers don't like to help someone who hasn't done their homework. So... I am able to log on to the network computer via Terminal using ssh targetuser@targetIP and I am also able to take the screenshot and copy it to my computer (but not every 10 seconds) using screencapture -x ~/screen.jpg followed by scp ~/screen.jpg myusername@myIP: However, I have to do these manually every 10 seconds which is really not very practical or possible. I have no idea how to delete the files remotely or empty the trash. Please any help with automating the tasks or remotely emptying the trash would be appreciated.
     
  2. Super Macho Man macrumors 6502a

    Super Macho Man

    Joined:
    Jul 24, 2006
    Location:
    Hollywood, CA
    #2
    Why not write a simple shell script that puts the below commands in an infinite loop. Try this, save it as whatever.sh, then 'chmod 700 whatever.sh' in Terminal, then './whatever.sh' to run it. (It will take over your command line though, so './whatever.sh &' to run it in the background)

    Code:
    #!/bin/sh
    
    for ((i=1; i>0; i+=1)); do
        screencapture -x ~/screen.jpg
        scp ~/screen.jpg myusername@myIP
        rm ~/screen.jpg
        sleep 10
    done
    
    rm will will delete the file without trashing it. Things only end up in the trash when they are deleted from the Finder, not the command line. And the '10' in 'sleep 10' should really be 10 minus however many seconds it takes to execute the above steps.
     
  3. cruzrojas macrumors member

    cruzrojas

    Joined:
    Mar 26, 2007
    Location:
    USA
    #3
    If you want to store all the screenshots in your computer you can modify the code to;

    Code:
    #!/bin/sh
    
    for ((i=1; i>0; i+=1)); do
        screencapture -x ~/screen$i.jpg
        scp ~/screen$i.jpg myusername@myIP
        rm ~/screen$i.jpg
        sleep 10
    done
    
    Best Regards
     
  4. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #4
    I'm not experienced with shell scripts but some languages will allow you to an infinite loop like:

    Code:
    for(;;) {
    **Loop infinitely over this stuff.**
    }
    
    Will help you clean it up a bit...
     
  5. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #5
    Hi

    I think you may have problems with the screen capture as you will probably have to ssh with the same username/password as the person running the Finder session. If you think about it, it would be a big security risk if you could simply ssh into somebody's Mac and then see what they were typing simply by doing a screen grab!

    b e n
     

Share This Page