MacTalk Forums > Mac Stuff > Mac OS X
Mac OS X Discussion and support on Mac OS X. If you have an issue with an application (e.g: Safari, or iPhoto, or Adium), it goes in the Applications forum.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12th June 2009, 12:21 AM
adamd's Avatar
BAM and the dirt is gone.
 
Join Date: Dec 2007
Location: Perth, Western Australia
Posts: 1,424
Send a message via AIM to adamd Send a message via MSN to adamd Send a message via Yahoo to adamd Send a message via Skype™ to adamd
View adamd's Twitter Page View adamd's Flickr Page View adamd's Last.fm Playlist
Default Remote control with Terminal+SSH

Ok, long story short, there is a bit of a friendly war going on between my friend and myself... Various things have been done to each others computers; nothing harmful.

My mission (that I came up with) is to remotely control his computer via Terminal and SSH to do the following...
  • play a song through iTunes or by loading a file (rickroll)
  • use "say" to speak random text
That's my list so far...

The reason for SSH. He doesn't know about it. It doesn't show up anywhere that I'm connecting with it, and I can control my scripts with PHP using it's exec() functions.

So, here's where I'm stuck...

I can log into SSH through terminal, and can run commands one by one, but this way, I have to type them in when I want to run them. What I would like to do, is have a single one-liner that I can execute. If it will work through terminal, I can get it to work with PHP.

This command needs to log in with SSH (with a password), then allow me to run a series of commands after it. Only ever 2 or 3 at max (eg: volume up, play song; or; volume up, say "hello", volume down).

If I can get this to work, he wont know what hit him... and it should teach him not to touch my computer when I'm not around...

Anyone got any ideas?
__________________
i3network.net | Email/AIM: adamd(at)i3network.net | msn: i3network(at)hotmail.com | Follow me on TUMBLR
my tech collection
stalk me on the interwebs.
Reply With Quote
  #2 (permalink)  
Old 12th June 2009, 12:26 AM
Lutze's Avatar
Yatta!
 
Join Date: Mar 2007
Location: Ellenbrook, WA
Posts: 4,227
View Lutze's Twitter Page View Lutze's Flickr Page
Default

<< No expert:

You need to have the script on his system in his profile to be really effective.

Is this going to be done over the net or locally - on a network? Do you know his username / password?

Perhaps, and don't take this wrong, you should maybe learn to lock your computer when you leave it. That's one that most reputable employers would rather their staff had.
__________________
 iPhone & iPhone 3GS, Macbook Pro 17" C2D 2.8ghz. iMac alu. 20" C2D 2ghz. iMac 20" CD 2ghz & Cube 450mhz. Website
Reply With Quote
  #3 (permalink)  
Old 12th June 2009, 12:34 AM
adamd's Avatar
BAM and the dirt is gone.
 
Join Date: Dec 2007
Location: Perth, Western Australia
Posts: 1,424
Send a message via AIM to adamd Send a message via MSN to adamd Send a message via Yahoo to adamd Send a message via Skype™ to adamd
View adamd's Twitter Page View adamd's Flickr Page View adamd's Last.fm Playlist
Default

This will be done locally, over a network. I already have an admin account on his computer, with a password that I know.

By script, you mean batch script?
__________________
i3network.net | Email/AIM: adamd(at)i3network.net | msn: i3network(at)hotmail.com | Follow me on TUMBLR
my tech collection
stalk me on the interwebs.
Reply With Quote
  #4 (permalink)  
Old 12th June 2009, 01:26 AM
Lutze's Avatar
Yatta!
 
Join Date: Mar 2007
Location: Ellenbrook, WA
Posts: 4,227
View Lutze's Twitter Page View Lutze's Flickr Page
Default

Quote:
Originally Posted by adamd View Post
This will be done locally, over a network. I already have an admin account on his computer, with a password that I know.

By script, you mean batch script?
Personally? I'd use an applescript. I don't know if it's possible to have an applescript sit in the background and wait for a rule to happen... but if it is then it would surely be better to have it activate whenever he types www or th then perform an action (use speech to say "I'm looking at pr0n") for example.
__________________
 iPhone & iPhone 3GS, Macbook Pro 17" C2D 2.8ghz. iMac alu. 20" C2D 2ghz. iMac 20" CD 2ghz & Cube 450mhz. Website
Reply With Quote
  #5 (permalink)  
Old 6th August 2009, 01:08 AM
 
Join Date: Aug 2004
Posts: 191
View teej's Twitter Page View teej's Last.fm Playlist
Default

Rather than typing in a password I think you'd be better off setting up an SSH key to handle authentication as it'll make automation a lot easier. Google will find a stack of guides to get you going with that.

Command execution can be done a number of ways. PHP is not one I'd consider because I find PHP clumsy as a general purpose scripting language.

The simplest thing you could do that (once you have keys in place), it just to send a series of commands when you invoke SSH, eg:
Code:
ssh -l username hostname.local. "say Hello ; sleep 2; say oi!"
If you want to do something that logic-wise isn't any more complicated but is lengthier, I'd just dump all the commands into a text file and just use back ticks to dump it into the SSH command. Text file:
Code:
say Hello
sleep 2
say oi
Command:
Code:
ssh -l username hostname.local -p 22 "`cat /pathto/textfilename`"
For something more complicated I'd look at writing a proper shell script (bash or expect) or if you know some Python or Ruby, Fabric or Capistrano respectively.
Reply With Quote
  #6 (permalink)  
Old 6th August 2009, 12:56 PM
BiRDBRAiN's Avatar  
Join Date: Jan 2005
Location: Smirnoff county
Posts: 1,121
View BiRDBRAiN's Twitter Page
Default

You need to setup a certificate/key on the target machine so that it authenticates you without requiring a password.

For an example of how to set this up have a look at this:
SSH login without password

That way you can send shell commands via SSH.

I use this to do remote SCP backups via shell scripts. Very easy once you get it going.
Reply With Quote
Reply

Bookmarks

Tags
control, remote, ssh, terminal


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On