Category Archives: Uncategorized

Bash scripts based on running processes

At work, our ERP system is built on Oracle running on a clustered Linux (Red Hat Enterprise) environment. Since this is a high availability/failover setup the processes running our development databases can be on either server for any number of reasons. I wanted to make installing code a bit easier on the server so I made some bash scripts to partially automate the install for me. Not wanting to get errors when it tries to install code on the wrong server, I found this little command to determine if the database is running on a server and thus let the script go on with the install.

ps -U oracle -u oracle u | grep -q pmon_dev2

Lets break this down into each part. The first part, ps -U oracle -u oracle u, gets the currently running processes running as “oracle” (first “-U” for real and second “-u” for effective ID) in a user-oriented format (last “u”). This is similar to an example in the MAN page for PS and I just replaced the usernames to fit my case. The pipe (“|”) takes the output from the left side, the PS command in this case, and uses it as input for the right side. The second part, grep -q pmon_dev2, searches for “pmon_dev2” in the output from PS, the “-q” option suppresses output and exits successfully if any match is found.

So I just put this at the beginning of my script:

if ! ps -U oracle -u oracle u |grep -q pmon_dev2
then
echo "DEV2 not running"
exit 1
fi

This exits the script right away if the database isn’t running on the server. If it is, then the script goes on to get the latest code from source control run the code install and exit. If you can do this with no user input, then you can setup a CRON job to run the script to automatically get any updates.

[googleplusauthor]

Change of Direction

I’ve decided I’m going to take this site in a new direction. Instead of trying to strictly work on write ups for here I’m going to use this more as a kind of status report for my many ongoing projects that I always seem to be working on. I’m thinking that this will hopefully motivate me to work on them more often and maybe even bring some of them to completion. Doing status reports at work usually gets me to work on tasks more often, so I’m hoping that blog posts here will have the same affects on my personal projects. I still haven’t decided on a file structure of what I’m going to do specifically; break everything down by pages, use just posts, or a combination of the two. I also might do another more personal site with another of my domains I have I’ll have to wait and see.

DH