Link to home
Start Free TrialLog in
Avatar of bhilgenkamp
bhilgenkampFlag for United States of America

asked on

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?
Avatar of gileze33
gileze33

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
Avatar of bhilgenkamp

ASKER

Sorry.... How would I format that for the .sh file? I'm very new to this
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.
Quite alright, it was a welcome surprise.... Yes, the username and password are the same for all the comptuers.
ASKER CERTIFIED SOLUTION
Avatar of slyong
slyong

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
Please. That would be great
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial