The sql_check_rw file contents in the last post

sqlplus -s “/ as sysdba” <<EOF

set heading off feedback off termout off

select OPEN_MODE from v\$database;

exit

EOF

Tagged | Leave a comment

Monitoring Oracle DB in a HACMP Active/Passive Cluster

The following script is one that I developed to be executed by HACMP every 10 seconds to make sure that the database is up and running:

#!/usr/bin/bash

DATE=`date +%d%m%y` # Record the time to add a time stamp to the log
LOG=/home/hacmp/logs/sblmon_${DATE}.log # Write the time stamp

if [ -f /home/hacmp/lock ]; then # If a file named “lock” exists, then disable the scripts
echo `date` >> $LOG
echo “==================================================” >> $LOG
echo “Oracle Monitoring Script Disabled” >> $LOG
exit 0
fi

export smon=`ps -ef | grep -v grep | grep -c ora_smon_db`
export lsnr=`ps -ef | grep -v grep | grep -c LISTENER`
export pmon=`ps -ef | grep -v grep | grep -c ora_pmon_db`
export lgwr=`ps -ef | grep -v grep | grep -c ora_lgwr_db`
export dbw0=`ps -ef | grep -v grep | grep -c ora_dbw0_db`

# The below statement is to execute the sql_check_rw file (inside /oracle which is the home directory of user oracle) which contains the SQL statement needed to check the DB OPEN_MODE

export dbstatus=`su – oracle <<EOF
. .profile
./sql_check_rw
EOF`

dbstatus=$(echo ${dbstatus:1}) # To remove the first character (as the string is preceded by an extra special character)

echo `date` >> $LOG
echo “==================================================” >> $LOG

if [ $dbw0 -eq 0 ]; then
echo “dbw0 failed” >> $LOG
exit 1 # Process doesn’t exist
elif [ $lsnr -eq 0 ]; then
echo “lsnr failed” >> $LOG
exit 1
elif [ $pmon -eq 0 ]; then
echo “pmon failed” >> $LOG
exit 1
elif [ $lgwr -eq 0 ]; then
echo “lgwr failed” >> $LOG
exit 1
elif [ $smon -eq 0 ]; then
echo “smon failed” >> $LOG
exit 1
elif [ “$dbstatus” != “READ WRITE” ]; then
echo “DB OPEN_MODE is not READ WRITE” >> $LOG
exit 1
else
echo “Success” >> $LOG
exit 0 # All monitored processes are running and database is in “READ WRITE” OPEN_MODE
fi

Tagged , , | Leave a comment

Remove the first character in a string in bash script

export variable= “anything_you_want” # populate the variable, this is just an example of course

variable=$(echo ${variable:1}) # remove the first character in the variable

echo $variable # show the new value of the variable to make sure the operation is completed successfully

nything_you_want

As simple as this 🙂

Tagged | Leave a comment

Import and Edit PDF Files For Free

I couldn’t believe myself at first, but it’s true!! I’ve been searching since a very long time ago for a decent (and free) PDF editor, especially on my Linux box (but it’s available for Windows and many other platforms as well) and I found this very nice plugin for Open Office that lets you very easily open and edit PDF files, they said it’s not for very big changes, but I tried editing 2 random PDF files on my laptop and it worked pretty fine, here is the link:

http://extensions.services.openoffice.org/project/pdfimport

Enjoooooooooy!!

Note: This only works with Open Office 3 and above, and to install an extension just click Tools -> Extension Manager -> Add, then choose your file and I think you’ll have to restart the Open Office.

Tagged , | Leave a comment

Allowing other system users to run commands as user "root" without having to authenticate as root

I have an application (created by IBM Linux team) that controls all the buttons on my thinkpad and shows the changes visually (raise/lower the speaker volume, increase/decrease brightness …etc). This application is called “tpb” and I found out that it cannot be run except by user root :(. Of course when I tried to put it in the session startup in my Ubuntu box – without adding sudo or gksudo before it – it never ran as expected and I really didn’t want to enter the root password each time I run this nice app.

Anyway, I searched and found a method to allow me to run this tool using another user, but with the privileges of the owner (which is root in this case), you can simply do the following:

“chmod 6555 tpb”

This made me able to run it as any other application using my system user instead of root, and it ran like a charm :))

Source: http://www.unix.com/tips-tutorials/19060-unix-file-permissions.html

Tagged , | Leave a comment