Thursday, March 24, 2016

Open Linux ports on firewall


One important firewall setting that every NIX admin should learn is about the ports and firewall security. As these are the heart of any server. An invalid or miss-configuration can lead to many threats to organizations data.

It is a good practice to close enable firewall settings on. Always open only those ports in firewall that are required for access. Close unnecessarily open ports immediately when not needed.

You can only set/see these settings when logged in as root user. Once logged in as root, firewall settings are part of administration under system. Clicking on firewall will give you below screen.



In this below screen i wan to open up port 1521 for my oracle database to be accessed from other machines. Clicking on Other ports >> Add >> user defined.

Will give you ability to allow this port via firewall settings. This is just a high level config. You can also set advanced settings selecting other options but that's out of scope for this tutorial. That's it port 1521 is available for outside world now on your host IP.



Tuesday, March 15, 2016

Uppercase to lowercase or vice versa in BASH

Uppercase to lowercase or vice versa

The bash version 4.x+ got some interesting new features. Type the following commands to convert $VAR into uppercase:


VAR="All THIS will be in UppER Case"
echo "${VAR^^}"

Sample outputs:

ALL THIS WILL BE IN UPPER CASE

Type the following commands to convert $VAR into lowercase:


VAR="All THIS will be in lOWer Case"
echo "${VAR,,}"

Sample outputs:

all this will be in lower case

Script to Check log file for errors and alert

#!/bin/bash
# Purpose: Detecting ORACLE Errors from any log file and send email
# Author: Arvind Toorpu
# Note : The script must run as a cron-job.
# Last updated on : 15-Feb-2016
## edit FILE to log file u want to check for errors
# -----------------------------------------------

# Store path to commands
FILE=/u01/app/oracle/admin/bin/test_error.txt

# Store email settings

AEMAIL="abcd@anyorg.com"
SUBJ="ORACLE Error - $(hostname)"
AMESS="Warning - ORACLE errors found on $(hostname) @ $(date). See log file for the details /u01/app/oracle/admin/bin/test_error.txt"
OK_MESS="OK: NO ORACLE Error Found."
WARN_MESS="ERROR: ORACLE Error Found."


# Check if $FILE exists or not
if test ! -f "$FILE"
then
        echo "Error - $FILE not found or mcelog is not configured for 64 bit Linux systems."
        exit 1
fi

# okay search for errors in file
error_log=$(grep -c -i "ORACLE error" $FILE)

# error found or not?
if [ $error_log -gt 0 ]
then    # yes error(s) found, let send an email
        echo "$AMESS" | mailx -s "$SUBJ" $AEMAIL <<-EOF
### Below line can be removed if you dont want to receive last few lines of that alert log
        `tail -n -50 /u01/app/oracle/admin/bin/test_error.txt`
        EOF
else    # naa, everything looks okay
        echo "$OK_MESS"
fi

change hostname on a linux machine -centos

I want to change my Linux hostname from Linux01 to Linux03

[root@Linux01 Desktop]# vi /etc/sysconfig/network

[root@Linux01 Desktop]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=Linux03

RESTART THE SERVER NOW. AFTER REBOOT

[oracle@Linux03 Desktop]$ hostname
Linux03

[oracle@Linux03 Desktop]$

Linux os level backup and cleanup cmds

REMOVE ALL FILES OLDER THAN 15 DAYS:

[oracle@Linux01 dpump]$
find /u01/app/oracle/dpump/*.dmp -mtime +15 -exec rm {} \;


GZIP ALL FILES OLDER THAN 15 DAYS: (This will make individual GZIP files)

[oracle@Linux01 dpump]$
find /u01/app/oracle/dpump/*.dmp -mtime +90 -exec gzip {} \;


MOVE FILES OLDER THAN 15DAYS

find /home/arvind -maxdepth 1 -iname "*.txt" -mtime -15 -exec mv {} /home/arvind/test1/ \;


COUNT FILES OLDER THAN 90 DAYS

find /u01/app/oracle/admin/adump/*.aud -mtime +90 | exec wc -l {} \;


TAR ALL FILES OLDER THAN 15 DAYS: 
(This will make 1 TAR FILE With date format at end)

[oracle@Linux01 dpump]$

find /u01/app/oracle/admin/ORCL/adump/*.aud -mtime +90 | xargs  tar -czvPf  /u01/app/oracle/admin/ORCL/adump/ARCH_AUD_$(date +%F).tar.gz