• No results found

In addition to its own tasks, Apple Remote Desktop provides a way to easily execute UNIX commands on remote computers. In order to send UNIX commands to the client computers, the client computers must have the BSD subsystem installed. The UNIX commands are shell commands. This means that you can write a script with

conditionals, loops, and other functions of the shell, and not just send one command.

Built-in Command-line Tools

Apple Remote Desktop includes two powerful command-line tools which can be used with Send UNIX Command: networksetup and systemsetup. The tools themselves are embedded within the ARD client software, and will not interfere with existing installations of the software on Mac OS X Server. The tools’ location is added to the default shell PATH, so you can access it through Remote Desktop as if it were installed in one of the standard UNIX tool locations. To change any settings using these tools, you must run them with root permissions (su root, or sudo).

networksetup

The command-line tool networksetup is used to configure a client’s network settings. It can create or modify network locations, change IP addresses, set network service proxies, and much more. You will find the command-line syntax, explanations, and an example in the tool’s help prompt, by entering the following as one line in Terminal:

/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/

networksetup -help

systemsetup

The command-line tool systemsetup is used to configure other non-network system settings. It can query or alter time zones, network time servers, sleep settings, Energy Saver preferences, Remote Login (ssh) preferences, and more. You will find the

command-line syntax, explanations, and example in the tool’s help prompt, by entering the following as one line in the Terminal:

/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/

systemsetup -help

Executing a Single UNIX Command

Using the UNIX Command window, you can send a single command to the selected client computers. The command is executed using the bash shell and root permissions.

To execute a single UNIX command:

1 Select a computer list.

2 Select one or more computers in the Remote Desktop window.

3 Choose Manage > Send UNIX Command.

4 Type or paste the command.

If your command is a multi-line script, enter each command on its own line. If you want to break up a single line command for better readability, use a back slash (“\”) to begin a new visual line.

5 Set the user whose permissions are used to execute the command.

You can choose the currently logged in user, or choose the name of any other user known to exist on the client computers.

6 Click Send.

Executing Scripts Via UNIX Command

There are two kinds of scripts you can execute via the command line. First, and most common with command-lines, is a shell script. A shell script is a file that contains a collection of UNIX commands that are all executed in the sequence in the file. Shell scripts can have normal programming procedures like loops, conditionals, and variables. Shell scripts are text files with UNIX line endings. Shell scripts are interpreted using the bash shell.

Executing Shell Scripts

Shell scripts can be copied, then executed. If a script has any degree of complexity, or cannot be expressed on a single line, you can use Copy Items to copy the script file to the client computers, then execute it using the Send UNIX Command. To send a single-line command you can just use Send UNIX Command.

To copy and execute a script:

1 Prepare and save your script.

Make sure your script is saved with UNIX line endings.

2 Open Remote Desktop.

3 Select a computer list.

4 Select one or more computers in the Remote Desktop window.

5 Use the Copy Items command to copy your script to the client computers.

6 After copying the script, choose Manage > Send UNIX Command.

7 Execute the script by typing:

sh [script path and name]

8 Click Send.

AppleScripts

The second kind of script you can execute, and the most common in the Mac OS X environment, is an AppleScript. AppleScripts are files that contain English-like commands, using the AppleScript programming language, and are created using the Script Editor application. AppleScripts can be executed on client computers in several ways: they can be compiled, saved and executed as an application, or sent at once using the command line.

To learn more about AppleScript, see AppleScript Help in Help Viewer, or go to www.applescript.com.

To send and execute a compiled AppleScript:

1 Save the AppleScript as an application.

2 Open Remote Desktop.

3 Select a computer list.

4 Select one or more computers in the Remote Desktop window.

5 Use the Copy Items command to copy your script to the client machines.

Use the Copy Items command with the Open After Copying option selected in the

To execute an AppleScript using the Send UNIX Command:

This method uses the osascript command. For detailed information on osascript, see the osascript man page.

1 Select a computer list.

2 Select one or more computers in the Remote Desktop window.

3 Use the Copy Items command to copy your script to the client computers.

4 After copying the script, choose Manage > Send UNIX Command.

5 Type or paste the AppleScript in the UNIX Command window, like this:

osascript -e '[First line of script]' -e '[Next line of script]'

For example, a simple script to create a folder and set its label would be entered (all in one line) as:

osascript -e 'tell the application "Finder"' \ -e 'make new folder' \

-e 'set the name of the result to "New Folder"' \ -e 'set the label index of folder "New Folder" to 2' \ -e 'end tell'

6 Click Send.

The client computer executes the script.

Related documents