How to flush linux buffer cache

sync && echo 3 > /proc/sys/vm/drop_caches
Posted in Linux | Comments Off

How to redirect output to a file as well as display it out

To redirect standard output to a file is easy, you just need to use the redirection symbol, for example:

echo "hello world" > test.txt

But what if I want to display it out as well as store into a file?
Answer: tee

echo "hello world" | tee test.txt

Okay it seems very easy, how about append?

To append the standard output to a file, you do this:

echo "hello world" >> test.txt

Append to file and display it out as well?

echo"hello world" | tee -a test.txt

Okay, how about dealing with standard output(stdout) and standard error(stderr)?
There are two different output stream, one is stdout and another one is stderr. Normal print usually goes to stdout and error related message will goes to stderr. Lets make a simple python script to print 1 line to stdout and 1 line to stderr.

#!/usr/bin/env python import sys sys.stdout.write("I am stdout\n") sys.stderr.write("I am stderr\n") 

Ok, lets save the python script as sout.py and try to redirect the output to a file.

$ ./sout.py > test.txt I am stderr 

Standard output is redirect to test.txt but stderr is print out.

What if I want stderr to be redirect and display the stdout?

 ./sout.py 2> test.txt

I want both stored into the file.

 ./sout.py 2&> test.txt

At last, I want both display and redirect to a file:

 ./sout.py 2>&1 | tee test.txt
Posted in Linux | Comments Off

PHP XML Element Dump

$reader = new XMLReader();
$reader->xml($xml);

while ($reader->read()) {

print($reader->name . ” ” . $reader->value; . “\n”);

}

Posted in PHP | Comments Off

Problem creating ASM disks with EMC PowerPath

If you encounter a problem creating ASM disks using EMC PowerPath psuedo devices do the following.

put in a file ‘/tmp/file’ the devices and the names you want to give for the ASM disk and run the script:

cat /tmp/file | while read DEV NAME
do
asmtool -C -l /dev/oracleasm -n $NAME -s $DEV -a force=yes
done
Posted in EMC, Linux, Oracle | Comments Off

Adding a new disk to RedHat Cluster

  1. Create a new lun and map it to the members of the cluster.
  2. mkfs the new disk.
  3. Create the mount point on both servers.
  4. Add the new disk the /etc/cluster/cluster.conf under the resources and service.
  5. Dont forget to raise the config_version.
  6. Update the cluster by running: ccs_tool update /etc/cluster/cluster.conf
  7. Check that the mount point is up on the active node, and that the configuration has been distributed to the other nodes.
Posted in Linux | Comments Off

Linux LVM – pvmove multiple pv`s into one pv

Recently i stumbled upon a problem where i had to migrate a volume group which had 2 pv`s, in this example /dev/sdb and /dev/sdc, the migration took place from one storage machine to another.

So i added a new disk to the system called /dev/sdd, pvcreated it, vgextended the VG with the new /dev/sdd and now the question that came into mind is how to migrate the PE`s into the new PV.

Its actually too simple under linux with LVM2… all that is needed to be done is:

pvmove /dev/sdb /dev/sdd

and once thats finished

pvmove /dev/sdc /dev/sdd

and thats all, now all the PE`s are at the new PV, both /dev/sdb and /dev/sdc are free so i could vgreduce them out and disconnect the old storage.

The fun part is that its all being done online without any disruptions to the DB working on thos disks.

Posted in Linux | Comments Off

Shell script array join

FOO=( a b c )
SAVE_IFS=$IFS
IFS=","
FOOJOIN="${FOO[*]}"
IFS=$SAVE_IFS
echo $FOOJOIN
Posted in Shell Script | Comments Off

I hate group policy…

As Unix Sys Admin i am on the user side of the active directory domain, such as it is, i suffer at the hands of the System NT guys and their group policy… this post is all about bypasses for group policy and how to make my day a bit brighter :)

1. How to enable a disabled PST usage:

Open regedit, search for DisablePST key (Ctrl+F, F3), change it to 0 (There might be more than one key, usually it might be under LOCAL MACHINE or USER policies).

 

more to come soon under this post …

Posted in Microsoft, Office | Comments Off

How to replicate and recover oracle database`s

This quick procedure will discuss what the commands needed to run on oracle in cases you might be using a script to create a snapshoted database and start the oracle instance on a different server.

In this case you need to put the source database in backup mode, take a snapshot, take it out of backup mode, copy the archive files to the target database, recover and open the database.

1. Put source database in backup mode:

 ALTER SYSTEM ARCHIVE LOG CURRENT;
 SELECT NEXT_CHANGE#-1 FROM V$ARCHIVED_LOG WHERE SEQUENCE#=(SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG);
 ALTER DATABASE BEGIN BACKUP;

Please notice that in the second line i keep the sequence number for later use in determining which archive files i will need.

2. Check that the entire database is in backup mode:

SELECT STATUS FROM V$BACKUP;

3. Now that the database is in backup mode we can take the snapshot and take the database out of backup mode:

 ALTER DATABASE END BACKUP;
 ALTER SYSTEM ARCHIVE LOG CURRENT;
 ALTER DATABASE BACKUP CONTROLFILE TO '/tmp/backup.ctl';
 ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS '/tmp/backup_trace.ctl';
 SELECT NEXT_CHANGE#-1 FROM V$ARCHIVED_LOG WHERE SEQUENCE#=(SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG);

Please notice that here i also take backup for the control file to be used in the recovery process, and also i keep now another sequence number, the one of the end of the backup.

4. Now i mount the target database`s mount points and i need to find which archive files i have to copy to the target database:

SELECT NAME FROM V$ARCHIVED_LOG WHERE DEST_ID=1 AND NEXT_CHANGE# BETWEEN $S_BEGIN_SEQ AND (SELECT MAX(NEXT_CHANGE#) FROM V$ARCHIVED_LOG);

Also dont forget to copy the backedup control file over the target databases own control files!

5. Now lets do the recover itself:

 STARTUP MOUNT;
 RECOVER AUTOMATIC DATABASE UNTIL CHANGE <last sequence number> USING BACKUP CONTROLFILE;

 ALTER DATABASE OPEN RESETLOGS;

At this point the database has gone a recovery and is ready to open.

It is important to remember that the database was copied in backup mode and therefore is in backup mode in the target database, the recovery process will take out the database from backup mode right after it will open the database and reset the logs.

Posted in Oracle | Comments Off

How to enable archivelog mode in Oracle 11g database

First lets check the current log mode:
SQL*Plus: Release 11.1.0.6.0 – Production on Fri Mar 20 14:33:05 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 – Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options

SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 165
Current log sequence 167

SQL> select name, log_mode from v$database;

NAME LOG_MODE
——— ————
TEST NOARCHIVELOG

SQL> show parameter spfile

NAME TYPE VALUE
———————————— ———– ——————————
spfile string /home/oracle/product/11g/db/db
s/spfiletest.ora
Now lets try to set the archive log destination:

SQL> alter system set log_archive_dest_1=’/home/oracle/archivelog’ scope=spfile;
alter system set log_archive_dest_1=’/home/oracle/archivelog’ scope=spfile
*
ERROR at line 1:
ORA-32017: failure in updating SPFILE
ORA-16179: incremental changes to “log_archive_dest_1″ not allowed with SPFILE

I faced the above error, thought need to enable archiving first:

SQL> alter system set log_archive_start=TRUE
2 scope=spfile;

System altered.

But I received the error again.

SQL> alter system set log_archive_dest_1=’/home/oracle/archivelog’ scope=spfile;
alter system set log_archive_dest_1=’/home/oracle/archivelog’ scope=spfile
*
ERROR at line 1:
ORA-32017: failure in updating SPFILE
ORA-16179: incremental changes to “log_archive_dest_1″ not allowed with SPFILE

Checked the error description:
SQL> !oerr ora 16179
16179, 00000, “incremental changes to \”%s\” not allowed with SPFILE”
// *Cause: Incremental changes to a log_archive_dest_n parameter cannot
// be made when using an SPFILE.
// *Action: Specify either LOCATION or SERVICE plus all other attributes
// to be set in one ALTER SYSTEM/SESSION SET command.

So I did some research and found that when using spfile and trying to set a parameter like log_archive_dest_1, we need to give
complete format of the parameter like:

SQL> alter system set log_archive_dest_1=’location=/home/oracle/archivelog’ scope=spfile;

System altered.
(Optionally we can also give other parameters in this statement like optional, reopen etc.)

Now let shutdown the database and do a startup mount:

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 422670336 bytes
Fixed Size 1300352 bytes
Variable Size 310380672 bytes
Database Buffers 104857600 bytes
Redo Buffers 6131712 bytes
Database mounted.

Enabling archivelog mode

SQL> alter database archivelog;

Database altered.

Open the database:

SQL> alter database open;

Database altered.

Test if archivelog is set properly:

SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/archivelog
Oldest online log sequence 165
Next log sequence to archive 167
Current log sequence 167
SQL> select name, log_mode from v$database;

NAME LOG_MODE
——— ————
TEST ARCHIVELOG

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> !ls -lrt /home/oracle/archivelog
total 44496
-rw-r—– 1 oracle oracle 45509632 2009-03-20 14:43 1_167_677948664.dbf
-rw-r—– 1 oracle oracle 1024 2009-03-20 14:43 1_168_677948664.dbf

So now we have enabled archivelog mode and have some archivelog file also!!!

Posted in Oracle | Comments Off