Ack! Crazy sh and perl scripts...

mailseth

Registered
I am trying to run a bunch of mrtg scripts (mrtg.org) and I am failing pretty thouroughly at it. I used the instructions at stepwise to install mrtg.

At first I would get:
[localhost:/usr/local/mrtg-2] botany% bin/mrtg --user=botany --group=all smple.cfg
WARNING: Running '/Library/MRTG/connections.sh': Permission denied
WARNING: Could not get any data from external command '/Library/MRTG/connections.sh'
Maybe the external command did not even start. (Permission denied)

WARNING: Running '/Library/MRTG/users.pl': Permission denied
WARNING: Could not get any data from external command '/Library/MRTG/users.pl'
Maybe the external command did not even start. (Permission denied)

Then I tried some instructions that I found in this fourm:
[localhost:/usr/local/mrtg-2] botany% chmod 744 /Library/MRTG/connections.sh
[localhost:/usr/local/mrtg-2] botany% chmod 744 /Library/MRTG/users.pl

And now I get:
[localhost:/usr/local/mrtg-2] botany% bin/mrtg --user=botany --group=all smple.cfg
WARNING: Running '/Library/MRTG/connections.sh': No such file or directory
WARNING: Could not get any data from external command '/Library/MRTG/connections.sh'
Maybe the external command did not even start. (No such file or directory)

WARNING: Running '/Library/MRTG/users.pl': No such file or directory
WARNING: Could not get any data from external command '/Library/MRTG/users.pl'
Maybe the external command did not even start. (No such file or directory)

But if I check in the directory, the files are still there:
[localhost:/usr/local/mrtg-2] botany% ls -l /Library/MRTG
total 48
-rwxr--r-- 1 botany wheel 80 Dec 6 10:48 connections.sh
-rw-r--r-- 1 botany wheel 173 Dec 6 09:40 uptime-mrtg.pl
-rwxr--r-- 1 botany wheel 208 Dec 6 09:41 users.pl

This is a tad bit frusterating... any kind soul know what is going on?
 
At the very least you need uptime-mrtg.pl to be executable. If you look at the output of ls -l :

-rwxr--r-- 1 botany wheel 80 Dec 6 10:48 connections.sh
-rw-r--r-- 1 botany wheel 173 Dec 6 09:40 uptime-mrtg.pl
-rwxr--r-- 1 botany wheel 208 Dec 6 09:41 users.pl

you can see that connections.sh and users.pl are executable by their owner (in this case: botany). This is indicated by the 'x' in the forth permission "slot." uptime-mrtg.pl on the other hand is not executable. My guess is that the other scripts are trying to run that one, failing, and then choking and dying. To rectify the problem type:

chmod u+x uptime-mrtg.pl

in the relevant directory. This will add(+) execute permission (x) for the owner or user of the file (u).

I don't know if this is the entirety of your problem, but if I understand how this stuff is trying to work, it definately won't work unless you do this.

BTW, look at 'man ls' and 'man chmod' for a good discussion of how to read and change file permissions.

The other thing that seems to be going on is that the scripts are expecting to live in /Library/MRTG whereas you have them in /usr/local/mrtg-2. You have two choices here, you can either move them to /Library/MRTG, or you can open each script in a text editor and replace all occurances of "/Library/MRTG" with "/usr/local/mrtg-2". If the scripts are well written this should be a total of once per file, usaully at the top... but then again, it seems to be a rare script that is well written... alas.

Good luck...

-alex.
 
Nope, the scripts are very simple ones, just intended to get the results of a few commands so mrtg can graph them over time. They do not use each other (and I got them from seperate sources).

I have specified in the MRTG config file to find the scripts at /Library/MRTG/[script name]. I will try moving them around tho. (but I doubt it will work :-(
 
What does the first line of /Library/MRTG/connections.sh and /Library/MRTG/users.pl say? They probably need to be updated to point to the proper programs. That error message you received is somewhat misleading, as it could also mean the program to run the script is incorrect; ie, if you write a script with (at least on default OS X install)

Code:
#!/bin/bash

so bash is the interpreter, you will receive the error no such file or directory against the script, as opposed to that first line.

The users.pl is a perl script given its extension, so its first line should be

Code:
#!/usr/bin/perl

but it probably points to /usr/local/bin or something.
 
connections.sh is:
#!/bin/sh

netstat -n -A inet | grep tcp | wc -l
netstat -Mn | grep tcp | wc -l

and users.pl is:
#!/usr/bin/perl


# number of user - processes .....

$entry = `w | wc -l`;
chomp($entry);

$user = $entry - 2;
print "$user\n";

$proc = `ps aux | wc -l`;
chomp($proc);
$proc =~ s/\s+//gc;
print "$proc\n";


I believe that it is all correct.
 
Hmm...this is definitely a bit odd; are both /usr/sbin and /bin in your PATH (run echo $PATH)? netstat is in /usr/sbin, so maybe that's why connections.sh is having problems, ps is in /bin, but theoretically that should be in your PATH already.

Also, (it's been awhile since I used MRTG) does bin/mrtg set its own PATH?
 
I cannot run them as regular commands, either:
[localhost:/Library/MRTG] botany% ls
connections.sh uptime-mrtg.pl users.pl
[localhost:/Library/MRTG] botany% ./users.pl
./users.pl: Command not found.
[localhost:/Library/MRTG] botany% ./connections.sh
./connections.sh: Command not found.
[localhost:/Library/MRTG] botany% echo $PATH
/Network/Servers/localhost/Users/botany/bin/powerpc-apple-darwin:/Network/Servers/localhost/Users/botany/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

So I would figure if I can fix that I cant fix the entire situation. (I am just a beginning UNIX user, so it may be something simple) Thx for all the help tho.
 
The reason I was asking was in case you typed them in, using an editor that saved the files in a slightly different format (namely, with different end of line characters). That could have accounted for the #! line not working right, and causing the Command not found errors. But if you simply grabbed them from elsewhere, I'm at a loss...
 
Very strange....

A simple cut and paste of what you entered yields working scripts (give or take a chmod).

Where did you get the MRTG binary program? Does it have any config files? About the only thing i can think of looking over all the posts is that it is interpreting the single quotes (') in the pathname as a literal part of the path. This is a long shot, but this really should be working.

Another thing to check: Do /bin/sh and /usr/bin/perl actually exist on your system? You can cd to the relevant directories and do an ls to check. I seem to recall people mentioning /bin/sh going away after certain software updates. That would explain why you can't run those scripts by hand. Also check the sizes of those files, since I also seem to recall the problem mentioned above involving the files having a size of 0.

Other than that... ???

Hope this helps...

-alex.
 
I can get the damn thing to run now, but it isn't gathering data correctly.

What I did was I just deleted the file, and remade it with the exact same text contents (via copy-paste in ssh). Then it worked fine (ran w/o errors). Hey, go figure, I dunno.

Thx for your help all. I'll get back to you guys if I cannot figure out the problem now :)
 
I've seen problems matching those symptoms before--my guess would be that (as blb suggested) your line-endings are off. If you still have the original scripts around, try running cat users.pl and so on. If my guess is right they'll show up as one collosally strange line.

This is because the BSD side of things and the MacOS side of things still disagree on line endings (or did last I checked, which was a while ago): if you download something with a GUI FTP client, it has Mac line endings ("\r", ASCII 13) instead of Unix ("\n", ASCII 10), which can produce interesting results if you try to use it on the command line (as you've seen). Unfortunately, many editors and pagers (emacs, pico, more, off the top of my head) "nicely" print out what they think you intended the file to look like, which is unfortunately not what the shell sees when interpreting the file. The solution is a one-line perl script:

perl -ple 's/\r/\n/g' -i.bak filename

which should translate the carriage returns to linefeeds, and leave a backup file named filename.bak (assuming the fatigue hasn't hit me too hard yet).
 
Back
Top