• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1379
  • Last Modified:

AppleScript to run termninal commands

Sorry, this may be painfully simple, but I have no idea where to start. I want to create an applescript to ssh into another machine and run a command. Here's what I have been doing:

ssh user@machine.local
password
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent
password again
exit

Can I put all of this into a script? Not concerned about the safety of the password. I would also like to be able to do this 4 times to 4 different machines.

If not applescript, is there something I can use to do this?
0
bhilgenkamp
Asked:
bhilgenkamp
  • 5
  • 3
2 Solutions
 
gileze33Commented:
This would be easiest by putting all of that into a shell script (.sh) and putting the password into the actual shell file.

Then, in applescript, you put in:

do shell script "/my-command-file-path"

Gileze33
0
 
bhilgenkampAuthor Commented:
Sorry.... How would I format that for the .sh file? I'm very new to this
0
 
gileze33Commented:
Hi.

Before I actually get round to giving you some decent advice (sorry about the delay), is the password the same for each computer? Or different for each?

Gileze33.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bhilgenkampAuthor Commented:
Quite alright, it was a welcome surprise.... Yes, the username and password are the same for all the comptuers.
0
 
slyongCommented:
Hi

Actually you can't do something like:

> ssh user@machine.local
> password
> sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent
> password again
> exit

To do something like that with ssh, you need to have public key authentication (http://www.bombich.com/mactips/rsync.html look at the Create authentication keys part).  Then you should be able to do:

do shell scirpt "ssh root@machine.local '/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resource/kickstart -restart -agent'"
0
 
gileze33Commented:
Hi.

I've had another think about this, and have thought of an alternative method.

You can use something like Expect.

To download expect, you need to get Darwin Ports, then go to the terminal and type "sudo port install expect".

If this isn't too much hassle, I'll write you a quick Expect script if thats ok with you.

Gileze33.
0
 
gileze33Commented:
Hi.

I have also been thinking of yet another, even easier method - I could spend five minutes of my time making a little REALbasic app that does it for you :)

I could then make a text file which holds the command to be run.

Is this still wanted?

Gileze33.
0
 
bhilgenkampAuthor Commented:
Please. That would be great
0
 
gileze33Commented:
Hi.

Sorry about the delays, have been really busy.

Just wondering, is this the sort of thing you were looking for, or something more automated?

http://macenterprise.org/content/view/113/118/

Gileze33.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now