Operating System - HP-UX
1833924 Members
3243 Online
110063 Solutions
New Discussion

Script help, parsing files

 
SOLVED
Go to solution
Brendan Newport_2
Frequent Advisor

Script help, parsing files

I have a little suite of scripts that perform the system alerting on my HP-UX, Solaris & AIX servers.

Although the scripts work fine (they create an XML file that is ftp'd to a Wndows-hosted Web server for an alarm console) I'm struggling to get the system easily distributable. I'm finding that I'm customising some of the individual alert scripts on each host, whilst others are generic in nature and can be safely shipped-out to each platform (using rdist).

Here's an example of what I mean. In one script I have the file systems checked, and an array is initialised with a list of the file systems to check;

set -A FS / /stand /var /var/spool /var/opt /var/adm /usr /opt /home /logs /apps /data/psdata04 /data/psdata03 /data/psdata02 /reports/psreports01 /backup/psbackup01

The obvious downside is I am hard-coding this list into each example of the alert script, and near enough each of my servers are different.

What I'd like to do is have a global configuration text file I could send out to each server, containing all of the parameters that the scripts could check, with a tag to indicate the server name. i.e.

serverA / /var/ /usr /opt /u00 /u01
serverB / /stand /etc/ /var /usr /data /home
serverC / /var /usr /etc /var/spool

So the question is; does anyone have any pointers or examples of initialising ksh arrays from the contents of text files with a unique identifier (even a line number)?


Regards


Brendan
2 REPLIES 2
Ollie R
Respected Contributor
Solution

Re: Script help, parsing files

Hi Brendan,

Try something like:
for FS in `grep "^$( hostname )" hosts.cfg | cut -f2-`
do
process_host
done

Ollie.
To err is human but to not award points is unforgivable
Brendan Newport_2
Frequent Advisor

Re: Script help, parsing files

Nice one Ollie!

I'd made my script a little too complex with the use of the array (at the time it fitted the bill).

Now I have a distributable text file with all the values for all the servers I want to monitor.