Wotan31
October 21, 2008, 11:50am
1
I have a script that counts the number of oracle processes running on the system:
if [ `ps -ef | grep ora_ | wc -l` -gt 0 ]
then
and it continues based on whether or not it finds running processes. Now we would like to move oracle to a separate server, but keep the application (and this script) on the old machine.
Is there a way for a script to perform a similar check (count number of running oracle processes) on a remote host?
The systems are all HP-UX 11iv1 and shell is KSH.
TIA!!
danmero
October 21, 2008, 12:28pm
2
if [ `ssh remote 'ps -ef | grep ora_ | wc -l'` -gt 0 ]
then
Note: grep can count!
you need to share ssh keys between the two servers and then you can run your command like so...
if [ `ssh server "ps -ef | grep ora_ | grep -v grep | wc -l"` -gt 0 ]
then
grep will often count and so you can remove it by grep -v grep...
danmero
October 21, 2008, 12:46pm
4
This is a very common mistake, you don't need the second grep and wc
grep -c "[o]ra_"
Or:
ssh host 'pgrep oracle' && ... || ...
It seams that pgrep is not available on HP-UX, so:
ssh host 'grep [o]ra_' && ... || ...
When using "grep -c" to count and you use it to count how many processes are running the "grep" is a process and will get counted... if you are grep'ing to count processes then it is probably best to do "grep -v grep | wc -l" to count.
I think danmero meant this:
$ ps -ef|grep ora_
oracle 3294 1 0 Sep 05 ? 1:10 ora_dbw1_xxx
oracle 11443 11433 0 23:02:34 pts/1 0:00 grep ora_
oracle 3292 1 0 Sep 05 ? 1:18 ora_dbw0_xxx
oracle 3290 1 0 Sep 05 ? 0:00 ora_pmon_xxx
oracle 3302 1 0 Sep 05 ? 0:00 ora_reco_xxx
oracle 3304 1 0 Sep 05 ? 0:00 ora_cjq0_xxx
oracle 3296 1 0 Sep 05 ? 2:35 ora_lgwr_xxx
oracle 3298 1 0 Sep 05 ? 7:08 ora_ckpt_xxx
oracle 3310 1 0 Sep 05 ? 0:02 ora_arc1_xxx
oracle 3300 1 0 Sep 05 ? 1:32 ora_smon_xxx
oracle 3306 1 0 Sep 05 ? 0:11 ora_qmn0_xxx
oracle 3308 1 0 Sep 05 ? 0:05 ora_arc0_xxx
$ ps -ef|grep [o]ra_
oracle 3294 1 0 Sep 05 ? 1:10 ora_dbw1_xxx
oracle 3292 1 0 Sep 05 ? 1:18 ora_dbw0_xxx
oracle 3290 1 0 Sep 05 ? 0:00 ora_pmon_xxx
oracle 3302 1 0 Sep 05 ? 0:00 ora_reco_xxx
oracle 3304 1 0 Sep 05 ? 0:00 ora_cjq0_xxx
oracle 3296 1 0 Sep 05 ? 2:35 ora_lgwr_xxx
oracle 3298 1 0 Sep 05 ? 7:08 ora_ckpt_xxx
oracle 3310 1 0 Sep 05 ? 0:02 ora_arc1_xxx
oracle 3300 1 0 Sep 05 ? 1:32 ora_smon_xxx
oracle 3306 1 0 Sep 05 ? 0:11 ora_qmn0_xxx
oracle 3308 1 0 Sep 05 ? 0:05 ora_arc0_xxx
$
Anyway, the oracle background processes will be running even if the instance is in nomount state (i.e. even if the database is not accessible).
sorry... i failed to acknowledge the brackets around the "o"... i never use the brackets but i might start now..
If you need the PID's pgrep is OK , however when you need the count grep -c do the job.
Some shell's don't like brackets without quotes(csh/tcsh).
Given the OP requirement pgrep (plain grep for HP-UX) should be sufficient: