Getting today’s Errors and Warnings from MySQL log

Quick one!

# Warnings

cat /var/log/mysqld.log |grep `date +%y%m%d` | grep "\[Warning\]"

# Errors

cat /var/log/mysqld.log |grep `date +%y%m%d` | grep "\[ERROR\]"

And a Bonus!
To get entries from X days ago:

cat /var/log/mysqld.log |grep `date --date="46 days ago" +%y%m%d`

Matheus.

AIX: NTP Service Basics

Hi all,
I always forget the command and have to search it again. For further searches, I expect to found in my own posts… 🙂

> To start Service

startsrc -s xntpd

> To stop Service

stopsrc -s xntpd

> Configuration File

/etc/ntpd.conf

Expect it be useful to you too.
See ya!
Matheus.

Linux: Resizing Swap Online

Hi all!
Quick one to resize swap online:

[root@server-db ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/mapper/rootvg-lvswap              partition       5242872 373624  -1
[root@server-db ~]# vgs
VG                #PV #LV #SN Attr   VSize   VFree
[...]
rootvg              1   6   0 wz--n- 135.69G 5.69G
[...]
[root@server-db ~]# lvextend -L +2048M /dev/mapper/rootvg-lvswap
Extending logical volume lvswap to 7.00 GB
Logical volume lvswap successfully resized
[root@server-db ~]# vgs
VG                #PV #LV #SN Attr   VSize   VFree
[...]
rootvg              1   6   0 wz--n- 135.69G 3.69G
[...]
[root@server-db ~]# mkswap /dev/mapper/rootvg-lvswap
Setting up swapspace version 1, size = 7516188 kB
[root@server-db ~]# swapoff /dev/mapper/rootvg-lvswap
[root@server-db ~]# swapon /dev/mapper/rootvg-lvswap
[root@server-db ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/mapper/rootvg-lvswap              partition       7516188 373624  -1

See ya!
Matheus.

Export/Backup directly to Zip using MKNOD!

We all faced that situation when we have to make a logical backup/export and haven’t so much area to do that, right?
We know the export usually compress a lot on zip/gzip… It wouldn’t be great if we can export directly to compressed file?

zip
This situation become much more common because of Datapump, that requires a directory accessible by database server. If you have not possibility to make a mounting point or any other area, this can help…

## BKP with MKNOD
BKP_DEST=/just/example
DATE=`date +%Y%m%d%H%M`
cd $BKP_DEST
mknod bkp_$DATE.dmp p
gzip  bkp_$DATE.dmp.gz &
### Uncomment and Ajust one of:
## MySQL:
#mysqldump -u $user -p$password $database > bkp_$DATE.dmp
## Oracle (Datapump or EXP)
expdp \"/ as sysdba\" dumpfile=bkp_$DATE.dmp full=y directory=DIRECTORY_EXAMPLE logfile=log_bkpzipped.log compress=y
#expdp $user/$password dumpfile=bkp_$DATE.dmp full=y directory=DIRECTORY_EXAMPLE logfile=log_bkpzipped.log
#exp \"/ as sysdba\" file=bkp_$DATE.dmp log=log_bkpzipped.log compress=y [tables=owner.table,..] [owner=schema1,..] [...]

Hugs!
Matheus.

Linux Basic: Creating a Filesystem

From disk to filesystem:

> Rescan on scisi controller to detect the disk (controller id 0, in  this example)

echo "- - -" > /sys/class/scsi_host/host0/scan

– List disks

fdisk -l

> Fdisk choosing options n -> new p->partition 1-> partition number

fdisk /dev/sdm

> Create physcal volume

pvcreate /dev/sdm1

> Create Volume Group

vgcreate oracle /dev/sdb1

> Rename Volume Group

vgrename oracle vgoracle

> Create LV

lvcreate -L 19G -n lvoracle vgoracle

> Extend LV

lvextend -L +990M /dev/vgoracle/lvoracle

> Make FileSystem

mkfs.ext3 -m 0 -v /dev/vgoracle/lvoracle

OBS: m 0 is the journal (for recovery in case of crash).  “0” because I don’t want it now. So, 100% of disco will be available for using on fs.

> Mount filesystem on Directory

mount -t ext3 /dev/vgoracle/lvoracle /oracle/

> Just to check:

$ df -h
/dev/mapper/vgoracle-lvoracle
20G  173M   20G   1% /oracle

 

Have a nice day!
Matheus.

Tip for the Future: Segmentation fault because of LD_LIBRARY_PATH

More than once I forgot to set LD_LIBRARY_PATH in new environments and sometimes I faced awkward errors. The most common is “Segmentation Fault”.
Today a lost almost 15 minutes searching about Segmentation Fault related to Datapump on 11.2, then I realized I forgot the LD_LIBRARY_PATH again…

Other day, in a Upgrade from 11.2.0.3.6 to 11.2.0.4.2 I get stuck in lots of errors on upgrade process. Bullshit again, after a few minutes of errors and searching I founded a post, somewhere, talking about the variables setting.

So, Matheus from the Future: Check if LB_LIBRARY_PATH and other variables are setted for the right Oracle Home.

I expect this post save me from this same pain in the future. 😛
Thanks.

Matheus.

Shellscript: Master Blaster KB!

Hi all!
I frequently have to search about shellscript syntax (things like conditions and comparatives).

Shellscripting is not a daily routine, but sometimes it’s needed and I never remmember from the last time…

For those kind of people, this link/book shall be very helpful 🙂

(it’s in portguese, but everyone will understand…)
http://aurelio.net/shell/canivete/

Thanks for this tools, Aurelio!

Have a nice week guys!

Is My Linux Server Physical or Virtual?

Supposing you are in a server shell and don’t know if you machine is virtualized (a VM)?
One way to check that (supposing VMWare as hypervisioning solution) is:

[root@mydbsrvr ~]# dmidecode | grep -i vmware
Manufacturer: VMware, Inc.
Product Name: VMware Virtual Platform
Serial Number: VMware-xx xx xx xx xx xx xx xx-xx xx xx xx xx xx xx xx
Description: VMware SVGA II

If you had an answer like this, yes, it’s a VM. 🙂

Matheus.

Recursive string change

You want recursive change one string to another, it’s simple, you need a list with full file name path called ‘output_list’, and run command bellow:

cat output_list|while read line;
do
cp -p $line $line.bkp;
cat $line |sed ‘s/SOURCE_STRING/TARGET_STRING/g’ > $line.bkp && mv $line.bkp $line;
done

Keep in mind it’s a DANGEROUS command, double check your file list, and if necessary,  make a full backup from you system.

It will run on UNIX(ES) and Linux.

Maiquel.

Shellscript: Using eval and SQLPlus

I always liked bash programming, and sometimes need to set Bash variables using information from Oracle tables.

To achieve that I’m using below solution, which I explain in details later.

# SQLPlus should return a string with all Bash commands
$ORACLE_HOME/bin/sqlplus -S -L -R 3 / as sysdba > /tmp/sqlplus.log <<-EOF
   SET PAGES 0 FEEDBACK OFF TIMING OFF VERIFY OFF LINES 1000
   SELECT 'OK:DBNAME='||UPPER(D.NAME)||'; INST_NAME='||I.INSTANCE_NAME AS STR
     FROM V\$DATABASE D, V\$INSTANCE I;
EOF

# Now, tests if sqlplus exit fine, and check if result string starts with OK keyword
if [ $? -eq 0 ] && [ "$( cat /tmp/sqlplus.log | head -n 1 | cut -d: -f1 )" == "OK" ]; then
   sed -i 's/OK://g' /tmp/sqlplus.log
   while read r; do eval "$r"; done </tmp/sqlplus.log
else
   echo "Failed to search local instance $ORACLE_SID"
   return 2
fi

In the first part, I call sqlplus, which select should return an string that contains valid bash commands, to set all variables I need. In this example, sqlplus returns Database Name and Instance Name:

      OK:DBNAME=xpto; INST_NAME=xpto_1;

The second part, exists only for consistency checks. It verify if result string starts with “OK” keywork. If all went fine, it execute the result string using the bash command eval.

 

eval – That is where magic happens!

The command eval, can be used to evaluate (and execute) an ordinary string, using the current bash context and environment. That is different than when you put your commands in a subshell.

The below source code, reads sqlplus.log and execute every command using eval:

while read line; do eval "$line"; done </tmp/sqlplus.log

Cassiano.