Terminal script to telnet/shutdown Windows server

Hi all,

I’m new to Mac/OSX and I’m looking for a bit of guidance. In brief I have a program (Poweroff) which runs as a service on several Windows machines on my network which I can use to remotely standby/poweroff/run programs etc. Previously I used the same program on my Windows laptop to send commands to the servers, but the program doesn’t exist (yet) for the Mac. Fortunately the server side exposes a telnet interface, so I thought I could just create an Applescript for each machine to connect via telnet and issue commands.

I’m basically looking for the following:

Launch a terminal session
Telnet to {server} {port}
Send command ‘Password {password}’
Send command ‘Action Standby’
Send command ‘Wait 10’
Send command ‘Doit’
Send command ‘Quit’
Close the telnet session
Quit terminal

It would be even better if the script could prompt me for the ‘Action’ (standby, shutdown, etc.) and substitute this in the script.

So far I’ve managed to launch terminal and issue the telnet command. Unfortunately I can’t figure how to issue multiple commands each as a separate entry.

I’m sure this is pretty basic stuff for most of you, but any advice much appreciated.

Thanks in advance,

Tom

Heres two ways you could go about it.


set result to display dialog "What Action ?" buttons {"Standby", "Shutdown", "cancel"}
set theButton to button returned of the result

tell application "Terminal"
	do script "telnet 
			Password {password}
			" & theButton & "
			quit"
end tell

This next way may work but im not sure i don’t really want to turn on the windows machine in the corner, but this one should work without opening a terminal window.

set result to display dialog "What Action ?" buttons {"Standby", "Shutdown", "cancel"}
set theButton to button returned of the result

do shell script "telnet 
			Password {password}
			" & theButton & "
			quit"

Thanks for the response. Since posting I’ve learned that you can’t pass multiple commands to the same telnet session. Apparently you have to send the commands to a terminal session. I’ve ended up with the following:

tell application "Terminal"
	activate
	do script "telnet server port" in front window
	do script "password password" in front window
	do script "action standby" in front window
	do script "seconds 5" in front window
	do script "doit" in front window
	do script "quit" in front window
	say "media center instructed to stand by"
	quit
end tell

Your suggestions should allow me to enable the same script to perform multiple actions though. Unless of course anyone knows otherwise regarding telnet.

Thanks,

Tom

you can post mulipule commands if you looked at my post and tried it you would see that. you have put line returns inside the brackets of the script.

tell application "Terminal"
	activate
	set nill to do script "telnet server port
	password password
	action standby
	seconds 5
		doit
	quit"
	say "media center instructed to stand by"
	quit
end tell

Thanks Kim,

I’m sure I had tried that method but I’ll try it again tonight.

Cheers,

Tom