Hi all,

I'm attempting my first foray into AppleScript and shell scripting, and I'm having a bit of trouble.

I have a problem on my network where my switches decide (for some reason) that a device has moved to a different port. While this condition lasts, of course, I can't talk to that device. As soon as the device sends out a packet, the switch relearns where it is and connectivity is restored. I want to regularly query a number of switches for the port that a particular server is on and log the response to a file. I also want InterMapper to log the same information when this server goes down.

It turns out that you can construct an OID that returns the switch port number that a particular MAC address is plugged into.

(For those that are interested, the OID is .1.3.6.1.2.1.17.4.3.1.2, followed by the MAC address in dotted-decimal format. For example, my server has MAC address 00-08-c7-bf-6d-be, so the OID would be .1.3.6.1.2.1.17.4.3.1.2.0.8.199.191.109.190.)

This can be used to make a Basic OID probe that pulls this information from within InterMapper, which, when plotted on a strip chart, gives me a log file containing the date, time, and switch port number that's updated every map poll interval.

But before I thought of that, I duplicated this with cron (well, CronniX), snmpget from the net-snmp package, and a crude shell script, reproduced below:

#!/bin/sh

# Find a MAC address on a particular network switch.
# Output a logfile-style single line

echo -n `date +%c`
echo -n " "
echo -n $1
echo -n " "
/usr/local/bin/snmpget $1 public 17.4.3.1.2.$2

I'm sure this is really lame, but it's my first shell script so I don't know any better :)

The crontab has the command
/Users/Shared/findmac 129.0.91.1 0.8.199.191.109.190 >> /Users/Shared/scmc_anc.log
which runs every ten minutes. (The switch I'm querying is at 129.0.91.1.) This seems to work fine.

I then created an AppleScript that basically does the same thing, for three different switches. It's reproduced below:

do shell script "/Users/Shared/findmac 129.0.91.1 0.8.199.191.109.190 >> /Users/Shared/scmc_anc.log"
do shell script "/Users/Shared/findmac 129.0.100.1 0.8.199.191.109.190 >> /Users/Shared/scmc_anc.log"
do shell script "/Users/Shared/findmac 129.0.90.100 0.8.199.191.109.190 >> /Users/Shared/scmc_anc.log"

Again, this seems to work fine when I launch it manually. The log file gets properly updated every time.

Finally we get to my problem. When I create an AppleScript notification in InterMapper and attach this AppleScript to it, it doesn't update the log file when I click on the "Test Notification" button. I see the AppleScript launching in the Dock, and it looks just like it's doing the same thing as it does when I launch it manually, but the log file doesn't change. If I delete the log file beforehand, it doesn't get recreated.

It looks like a permissions issue, but I can't think how. I've placed everything in /Users/Shared, and believe I've chmodded everything correctly. Here's the directory listing:

[localhost:/Users/Shared] admin% ls -l
total 128
-rwxr-xr-x 1 admin wheel 9116 Dec 20 15:47 Log SCMC_ANC switch ports*
-rwxrwxrwx 1 admin staff 205 Dec 20 12:12 findmac*
-rw-rw-rw- 1 admin wheel 64 Dec 20 15:50 scmc_anc.log
[localhost:/Users/Shared] admin%

I'm using InterMapper 3.6 on OS X 10.1.

Can anyone tell me what I'm doing wrong? Any feedback would be welcome, up to and including snotty remarks about my scripting skills and general lack of Unix knowledge :) Alternative approaches are also welcomed. I'm reading up on syslog now, for instance...

Thanks for reading!

Doug


--
Doug Weathers, Network Administrator
St. Charles Medical Center
http://www.scmc.org


____________________________________________________________________
Note: To unsubscribe from this mailing list, please send email to:
<mailto:[EMAIL PROTECTED]> Thanks!

Reply via email to