Re: new guy ksh scripting questions




FNG2007 wrote:
I've been given the task of writing the following procedure into a
script to be called from the crontab of the Oracle user.

I'm a Windows Admin, newly minted into an AIX sysadmin - and I'm a bit
bewildered by ksh scripting.

I've got one of the O'Reilly books and I'm hacking my way through it -
but I'm still having problems with some of the basics like

a) on step 4 below, how would I verify that I've got 4 processes that
all return the ALIVE status. My thought is to pipe the output of the
command into a grep command looking for ALIVE, pipe that into a wc -l
command and have it return an error if the output from that is less
than 4. But I'm sure there's got to be a smarter way to do that.


ANyway, as I said, I'm slogging through it on my own - I thought I'd
throw the problem up here to see if anyone had any sage advice or
warnings about pitfalls to avoid

thanks in advance




=========================

1. While logged in as Oracle, stop the LDAP services by executing the
following commands:
. ./.profile_as
cd bin
./Shutdown.sh

2. Verify that the services are not running:

opmnctl status

The result of this command should look like this:

[oracle@hostname1/home/oracle]$ opmnctl status
Unable to connect to opmn.
Opmn may not be up.

ps -ef |grep ldap

This command should not return any running ldap processes.

ps -ef |grep oid

This command should not return any running oid processes.


3. Start the services executing the following command:

./Startup.sh

4. Verify that the services are running:

opmnctl status

The result of this command should look like this:

Processes in Instance: infra.hostname.acme.corp
-------------------+--------------------+--------+---------
ias-component | process-type | pid | status
-------------------+--------------------+--------+---------
OID | OID | 581734 | Alive
OC4J | ldapapp | 966658 | Alive
OC4J | OC4J_SECURITY | 561208 | Alive
HTTP_Server | HTTP_Server | 10118~ | Alive
dcm-daemon | dcm-daemon | N/A | Down
LogLoader | logloaderd | N/A | Down

5. Verify that ldap demons are running on SSL and non-SSL ports:

netstat -an | grep 389 | grep LISTEN

tcp4 0 0 172.50.1.104.389 *.*
LISTEN
and:
netstat -an | grep 636 | grep LISTEN
tcp4 0 0 172.50.1.104.636 *.*
LISTEN

What you're doing is fine.
You can use "netstat -an | grep -q '\.389 .*LISTEN' " which will
quietly grep for ".389" followed by a space, any number of any
character, and "LISTEN". If this matches the grep will exit with
success, otherwise with failure. That can be used in your script, eg
if netstat | grep
then echo good
else echo bad
fi

With your step 2 problem an optimisation is to use grep -c, which will
count the number of matching lines and print that number on stdout.
if [ `opmnctl status | grep -c ALIVE` = 4 ]
then echo good
else echo bad
fi

HTH and hang in there - Unix is grotesque but powerful.
Jeffrey

.



Relevant Pages

  • Re: csccmd not running in script
    ... I moved the code around a little so that csccmd runs before anything else ... and I get no echo. ... command to complete so we can retrieve the return code. ... you may need to use "Run as Administrator" when you run the script. ...
    (microsoft.public.scripting.vbscript)
  • Re: Referencing Korn Shell Array Names as a Variable
    ... Your idea worked for displaying the output from the command. ... $ echo $ ... # Attempt to use variable array name and index to reference array value ... The issue is with this line of the script ...
    (comp.unix.shell)
  • [opensuse] Add variables to standard output for
    ... output - the finger command) ... I want to take the standard output from a grep ... My script: ... The views expressed in this e-mail are the views of the individual sender and should in no way be construed as the views of the Company. ...
    (SuSE)
  • Re: redirect for stdout in ${command_line}
    ... echo "Command line is shown below:" ... # END OF SCRIPT# ... I would accept a variable and build a command line while ... echo "Temp file contents are shown below:" ...
    (comp.unix.aix)
  • Re: Shell scripts: variable assignment within read loops
    ... things) to obtain information from a command, ... echo $foo ... echo "NICs: $nics" ... the script is to be used to gather ...
    (freebsd-questions)