Author Archives: Radu N.

Creating script with arguments and options

  while getopts ":pq:" optname
    do
      case "$optname" in
        "p")
          echo "Option $optname is specified"
          ;;
        "q")
          echo "Option $optname has value $OPTARG"
          ;;
        "?")
          echo "Unknown option $OPTARG"
          ;;
        ":")
          echo "No argument value for option $OPTARG"
          ;;
        *)
        # Should not occur
          echo "Unknown error while processing options"
          ;;
      esac
    done

Start/Stop/Reset/Reboot ESX 5x VM from command line

To power on a virtual machine from the command line:

  1. Get VM ID with the command:
    1
    
    vim-cmd vmsvc/getallvms
  2. Check the power state of the virtual machine with the command:
    1
    
    vim-cmd vmsvc/power.getstate <vmid>
  3. Power-on/Restart/Reset/Poweroff using:
    1
    2
    3
    4
    
    vim-cmd vmsvc/power.on <vmid>
    vim-cmd vmsvc/power.off <vmid>
    vim-cmd vmsvc/power.reset <vmid>
    vim-cmd vmsvc/power.reboot <vmid>

Center NextGen Gallery

If you need to center a NextGen Gallery (I don’t know why there isn’t a feature in there somewhere about this) go to NextGen Gallery -> Other Options -> Styles -> Show Customization Options and add the text below:

1
2
3
4
5
6
7
.ngg-galleryoverview {
text-align:center;
}
.ngg-gallery-thumbnail-box {
float:none !important;
display:inline-block;
}

df: `/root/.gvfs’: Permission denied

When you run the df command as a non root user, you can sometimes get the following error:

df: `/root/.gvfs': Permission denied

When you ran the df command you can pass the file system types which you would like to exclude from it, in this case it is ‘fuse.gvfs-fuse-daemon’ just as follows:

df -x fuse.gvfs-fuse-daemon

Changing weblogic password in OBIEE environment

If you want to change the weblogic password in an OBIEE environment you have to be very careful so that both the Weblogic and Managed Server are running when you change the password. If only the Weblogic is started when you change the password then the Managed Server won’t start with any password (old or new). The error it throws is:

<BEA-090403> <Authentication for user weblogic denied>
<BEA-000386> <Server subsystem failed. Reason: weblogic.security.SecurityInitializationException: Authentication for user weblogic denied
   weblogic.security.SecurityInitializationException: Authentication for user weblogic denied
   at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.doBootAuthorization(CommonSecurityServiceManagerDelegateImpl.java:965)
   at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.initialize(CommonSecurityServiceManagerDelegateImpl.java:1050)
   at weblogic.security.service.SecurityServiceManager.initialize(SecurityServiceManager.java:873)
   at weblogic.security.SecurityService.start(SecurityService.java:141)
   at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
   at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
   at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)

It took me a while to figure this out, maybe it will save somebody some debugging time.

Email alert for low disk space v2

A while back I wrote a post about a simple low disk space script that will email you if a specific partition on your system has free space lower than a percentage you specified. Now I improved that script, adding some more features:

– excluding some partitions (be careful here not too exclude to much)

– sending email to many recipients

– check if emails were already sent, then it would spam the users with emails

The script is below:

#!/bin/sh 
EXCLUDE_PARTITIONS="partition1\|partition2" 
WARNING=85 
RECIPIENTS="user1@domain.com user2@domain.com" 
DF=( `df -h | grep % | tail -n +2 | awk '{print $(NF-2)" "$(NF-1)" "$(NF)}' | sed 's/%//g' | sed 's#/\(.*\)#/\1 slash-\1#g' ` ) 
for ((i=1;i<${#DF[@]};i=i+4)) 
do 
  if [[ ${DF[i]} -gt $WARNING ]] 
  then 
    if [ ! -f /tmp/disk-warning-for-${DF[i+2]} ] 
    then 
      touch /tmp/disk-warning-for-${DF[i+2]} 
      echo "" | mail -s "SH Alert: Critical: `hostname` - ${DF[i+1]} has only ${DF[i]}% (${DF[i-1]}) free space" $RECIPIENTS 
    fi 
  else 
    if [ -f /tmp/disk-warning-for-${DF[i+2]} ] 
    then 
      echo "" | mail -s "SH Alert: Clear: `hostname` - ${DF[i+1]} has only ${DF[i]}% (${DF[i-1]}) free space" $RECIPIENTS 
      rm /tmp/disk-warning-for-${DF[i+2]} 
    fi 
  fi 
done

As in the previous post, you need to make the script executable:

chmod +x /path/to/script

And add it to the cronjob using “cronjob -e”:

# Minute   Hour   Day of Month       Month          Day of Week        Command
# (0-59)  (0-23)     (1-31)    (1-12 or Jan-Dec)  (0-6 or Sun-Sat)
*/10 * * * * /path/to/script

Note: This was tested on Oracle Linux 5/6 and is working great. For other distro’s you might need to change the email syntax, the order of the df columns, etc.

Fast method for finding differences between two unsorted files

At work I had two files: one with 13 000 records (filea) and one with 300 000 records (fileb). Every record was on a new line in the file. I was looking for a method of finding which records from filea are not in fileb. Because of the huge number of records per file, the “grep -v -f filea fileb” was taking forever and also I would need the files to be sorted before executing the grep.

After a few searches on the world wide web, I found a very quick way of doing this with awk:

1
awk 'NR == FNR { A[$0]=1; next } !A[$0]' fileb filea

If you want to find out more about this fast and easy solution (no need to presort the files) I found a similar example with an explanation here.

GNU utilities native in windows

For all you Linux fans out there, that use a lot of linux commands (sed,ls,awk,etc) and would like to have this also on linux, you can give UnxUtils a try. The big differences between UnxUtils and Cygwin is that UnxUtils uses executables that are only dependent to Microsoft C-runtime (msvcrt.dll).

All you have to do is:

1. Download the zip file from owners site

2. Unzip the file in any location (preferably C:\Program Files (x86)\UnxUtils )

3. Add the path C:\Program Files (x86)\UnxUtils\usr\local\wbin to the System Variables PATH (Start – Control Panel – System – Advanced system settings – Advanced – Environment Variables – System variables – PATH – edit)

You can find a complete list of programs that are ported on the UnxUtils site.

Delete old S_NQ_ACCT/S_NQ_DB_ACCT partitions

In the previous post I’ve described how to partition the S_NQ_ACCT and S_NQ_DB_ACCT tables used by OBIEE for Usage Tracking. Now I’m gonna describe how to delete partitions that are X days old.

When we partitioned the table, we configured it to be done daily. Now if we are going to issue the following command:

conn DEV_BIPLATFORM;
SELECT * FROM user_tab_partitions;

we are gonna notice that Oracle Database created the HIGH_VALUE as “TO_DATE(‘ 2013-11-09 00:00:00’, ‘SYYYY-MM-DD HH24:MI:SS’, ‘NLS_CALENDAR=GREGORIAN’)”. If you want to delete all partitions that are 32 days old, I’ve used the following sql script:

SET serveroutput ON
SET feedback off
variable v_days_to_keep NUMBER;
exec :v_days_to_keep := 32;
 
DECLARE
    v_statement VARCHAR2(4000);
BEGIN
    FOR x IN (SELECT TABLE_NAME,PARTITION_NAME,HIGH_VALUE FROM user_tab_partitions WHERE TABLE_NAME = 'S_NQ_DB_ACCT') LOOP
      IF x.PARTITION_NAME != 'PART1'
        THEN
          v_statement := '
BEGIN
    IF SYSDATE - ' || x.HIGH_VALUE || ' > '|| :v_days_to_keep || '
      THEN
        EXECUTE IMMEDIATE ''ALTER TABLE "' || x.TABLE_NAME || '" DROP PARTITION "' || x.PARTITION_NAME || '" UPDATE GLOBAL INDEXES'';
    END IF;
END;';
          EXECUTE IMMEDIATE v_statement;
      END IF;
    END LOOP;
    EXECUTE IMMEDIATE 'alter table S_NQ_DB_ACCT disable CONSTRAINT "FK_S_NQ_DB_ACCT"';
    FOR x IN (SELECT TABLE_NAME,PARTITION_NAME,HIGH_VALUE FROM user_tab_partitions WHERE TABLE_NAME = 'S_NQ_ACCT') LOOP
      IF x.PARTITION_NAME != 'PART1'
        THEN
          v_statement := '
BEGIN
    IF SYSDATE - ' || x.HIGH_VALUE || ' > '|| :v_days_to_keep || '
      THEN
        EXECUTE IMMEDIATE ''ALTER TABLE "' || x.TABLE_NAME || '" DROP PARTITION "' || x.PARTITION_NAME || '" UPDATE GLOBAL INDEXES'';
    END IF;
END;';
          EXECUTE IMMEDIATE v_statement;
      END IF;
    END LOOP;
    EXECUTE IMMEDIATE 'alter table S_NQ_DB_ACCT enable novalidate CONSTRAINT "FK_S_NQ_DB_ACCT"';
END;
/

I’ve tested this and it’s working perfectly on OBIEE 11.1.1.7.1 with DB 11.2.0.3. All you have to do now is set a job in the DB or sh script in the OS to run daily. I’ve went with the second option, because it’s simpler for me to receive email alerts if anything goes wrong with the script. I’ve also added some output to the script so I know when something is deleted. The sh script is below. Please change the password and tns_entry accordingly to you environment.

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin/:${PATH}
export TNS_ADMIN=$ORACLE_HOME/network/admin
 
before=`sqlplus -s DEV_BIPLATFORM/pass@tnsentry << EOFSQL
set heading off
set pages 0
select count(1) from user_tab_partitions;
exit;
EOFSQL`
 
sqlplus -s DEV_BIPLATFORM/pass@tnsentry << EOFSQL
Set serveroutput on
set feedback off
variable v_days_to_keep number;
exec :v_days_to_keep := 32;
 
declare
    v_statement varchar2(600);
begin
    for x in (select TABLE_NAME,PARTITION_NAME,HIGH_VALUE from user_tab_partitions where TABLE_NAME = 'S_NQ_DB_ACCT') loop
      if x.PARTITION_NAME != 'PART1'
        then
          v_statement := '
BEGIN
    IF SYSDATE - ' || x.HIGH_VALUE || ' > '|| :v_days_to_keep || '
      THEN
        EXECUTE IMMEDIATE ''ALTER TABLE "' || x.TABLE_NAME || '" DROP PARTITION "' || x.PARTITION_NAME || '" UPDATE GLOBAL INDEXES'';
    END IF;
END;';
          execute immediate v_statement;
      end if;
    end loop;
    EXECUTE IMMEDIATE 'alter table S_NQ_DB_ACCT disable CONSTRAINT "FK_S_NQ_DB_ACCT"';
    for x in (select TABLE_NAME,PARTITION_NAME,HIGH_VALUE from user_tab_partitions where TABLE_NAME = 'S_NQ_ACCT') loop
      if x.PARTITION_NAME != 'PART1'
        then
          v_statement := '
BEGIN
    IF SYSDATE - ' || x.HIGH_VALUE || ' > '|| :v_days_to_keep || '
      THEN
        EXECUTE IMMEDIATE ''ALTER TABLE "' || x.TABLE_NAME || '" DROP PARTITION "' || x.PARTITION_NAME || '" UPDATE GLOBAL INDEXES'';
    END IF;
END;';
          execute immediate v_statement;
      end if;
    end loop;
    EXECUTE IMMEDIATE 'alter table S_NQ_DB_ACCT enable novalidate CONSTRAINT "FK_S_NQ_DB_ACCT"';
end;
/
exit;
EOFSQL
 
after=`sqlplus -s DEV_BIPLATFORM/pass@tns_entry << EOFSQL
set heading off
set pages 0
select count(1) from user_tab_partitions;
exit;
EOFSQL`
 
deleted=`expr $before - $after`
[[ ! $deleted -eq 0 ]] && echo "$deleted paritions deleted."