![]() ![]() My exact requirements would be a window titled "TV Show Maker 3.0" and within the window has the instructions "Please select the correct TV Show, then press OK." At the bottom would be cancel button which would cancel the script and close the window, and the OK button that would close the window. While it is possible to do text parsing in AppleScript you have to take into account variances like this.Sure. ![]() How many 'httpd's do you see? I see 5 - one in the grep statement, and two in each of the process lines. The problem with trying to count the number of occurrences of 'httpd' is that, at least on my machine, the ps output looks like:ĩ7275 ? 0:06.35 /usr/sbin/httpd -D FOREGROUND -f /Library/Server/Web/Config/apache2/httpd_server_app.confĩ7278 ? 0:00.63 /usr/sbin/httpd -D FOREGROUND -f /Library/Server/Web/Config/apache2/httpd_server_app.conf In this case, if you're really resigned to using Terminal.app then you can save yourself a lot of grief and use grep's -c (count) switch. There's never a need to copy the result to the clipboard. Note that I've also taken a slightly different approach, which is to have the shell script just grab the process list and use AppleScript logic to determine if httpd is running - that avoids the whole issue with grep's output if the text doesn't exist. If remoteProcessList contains "httpd" then Set remoteProcessList to do shell script "ps -A" Tell application "System Events" of machine "epcc://ip.of.remote.machine" Your best hope here is that the server is a Mac and you can use Remote Apple Events to target the remote system You have to query that tab to find out what content is in its widow, and process that text to find the output of your command. It's not the output of the last command executed in that window - it's a reference to the tab. Note the result is the tab that the command was executed in. Looking at the app's dictionary you see:ĭo script (verb) Runs a UNIX shell script or command. Thirdly, even if you do use ssh there's no absolute requirement to use Terminal.app - you should look at setting up private keys on the server, which will allow you to log in via SSH without needing an interactive password.įourthly, even if you do decide you need to use Terminal.app, your code is wrong □ There's nothing in this command that requires root-level privileges. ![]() Secondly, even if you do need to use SSH, you should shy away from logging in as root. However you still have multiple options.įirst off, is the server a Mac? There are other options for executing commands on a remote Mac. Note the use of grep's -q (quiet) switch to suppress errors and the use of 'echo $?' to return the exit code of the last-executed command (and you still don't need Terminal.app). Set exitCode to do shell script "ps -A | grep -v grep | grep -q httpd echo $?" The other approach, which works if you want to capture the exit code is something like this: Normally do shell script will return stdout (the output of the command) rather than just the error code, but in this case grep's output would be empty since the text doesn't exist Note that this approach is somewhat peculiar to grep, since it returns an exit code that you're trying to respond to. If grep fails (it can't find the text) it returns an exit code that triggers the 'on error' block. If it succeeds (grep finds the text) then it displays the 'HTTPD is running' dialog. i.e., in this case, if grep returns 1 (not found)ĭisplay dialog "Status Is 1 (httpd not running)" we get here if the previous command fails ![]() If you want to catch the error code, the easiest way is via a try statement:ĭo shell script "ps -A | grep -v grep | grep httpd" In do shell script's case, an exit code of 1 is an error, and so it stops the script to report the error. However, grep returns a different status code - 1 if no lines were found. The issue is that do shell script always, always, always expects an exit status of 0 (success). You're dealing with your exit status incorrectly. ![]()
0 Comments
Leave a Reply. |