Linux – Bash Scripts to help monitoring your system

This week, i was working on Automation Project related to Zabbix, which is fix the issues automatically without human interaction, so in case for example; the file system alert reach 85% it will be delete specific folder and send an email to system administrator.

or for example the Cache has been filled and you need to clear, so need for example for someone to access the server and take an action to do this.

I wrote scripts where it’s integrate it with Zabbix and once the threshold will fire, the scripts will run automatically.

This github repository will be updated since the project is not complete yet, still has to do a lot of scripting and integration but i would like to share it with you guys.

The scripts uploaded to my Github here

Enjoy

Osama

Shell Scripting for begginers

Bash Scripting is one of the skills that any system adminsitrator or DBA’s should knows, why ? because it’s making your life much easier, for example, imagine you are about to change the persimisson of files for example under one directory, and inside it you have 10 files (i know it’s that much), Will you do it one by one, it will be a good idea, maybe you are fast typer but what if it will be more than 10 ?
Shell Scripting is the solution for this.

Bash is comamnd language and it’s widely available on various operating system, the name it’s self came from Bourne-Again SHell

Shell which is allows you for interactive or non-interactive execution.

Finally; which is scripting, the commands that will be executed one by one.

One of the simplest example which is “Hello World”, Save it as hello.sh

 

#!/bin/sh
echo “Hello, World”

if we need to modify this script to read name of the user; it will be like this :-

#!/bin/sh
echo “What is your name?”
read MY_NAME
echo “Hello, $MY_NAME”

Mathamtics examples :-

Shell Scripting can be used also in mathamtics operations such as the below:-

#!/bin/bash
((sum=25+35))
echo $sum
#!/bin/bash
((area =2*2))
echo $area

Looping :-

If you want to repeat something, then you should use either for or while which will make your life easier:-

The following example, will print the counter number each time, as you see the counter start from 5 and it will out once it will be 0

#!/bin/bash
for (( counter=5; counter>0; counter– ))
do
echo -n “$counter ”
done
printf “\n”

Using While but once it will be 5 the loop will be terminated.

#!/bin/bash
Bol_value=true
count=1
while [ $Bol_value ]
do
echo $count
if [ $count -eq 5 ];
then
break
fi
((count++))
done

 

Operator Description
-eq Checks if the value of two operands are equal or not; if yes, then the condition becomes true.
-ne Checks if the value of two operands are equal or not; if values are not equal, then the condition becomes true.
-gt Checks if the value of left operand is greater than the value of right operand; if yes, then the condition becomes true.
-lt Checks if the value of left operand is less than the value of right operand; if yes, then the condition becomes true.
-ge Checks if the value of left operand is greater than or equal to the value of right operand; if yes, then the condition becomes true
le Checks if the value of left operand is less than or equal to the value of right operand; if yes, then the condition becomes true.

 

If you want to learn more from here

Summary:-

  • Shell is a program which interprets user commands through CLI like Terminal.
  • Shell scripting is writing a series of command to execute.
  • Shell scripting can help you create complex programs

 

Cheers

Osama

Change Hostname in Oracle Solaris 11.3

In this post i will share how to change hostname in Solaris 11.3 , i never test this way on other version but regarding to Oracle it will be working without any issue.

  • as root user, list the current hostname using the below command :-

# svccfg -s system/identity:node listprop config

config                                                         application
config/enable_mapping            boolean     true
config/ignore_dhcp_hostname boolean     false
config/loopback                        astring
config/nodename                      astring       solarisdb1

  • change hostname to new one

# svccfg -s system/identity:node setprop config/nodename=”solarisdbnew1″

  • Refresh and restart

# svcadm refresh system/identity:node

# svcadm restart system/identity:node

  •  Check the configuration

# svccfg -s system/identity:node listprop config

 Thank you

Osama

Out Of memory , Not Enough Space Solaris 11

SQL> startup mount ;
ORA-27102: out of memory
SVR4 Error: 12: Not enough space
Additional information: 1671
Additional information: 16106127360
Additional information: 64424509440

The Above error appeared When trying to start Oracle 12c on Solaris 11.3, this is published bug 
Bug:20635316 – 12C DATABASE INSTANCE STARTUP FAILS WITH ORA-27102: OUT OF MEMORY
Solaris using something called OSM , Optimized Shared memory You can know more about it here 
To avoid this error as workaround just set the parameter

_use_osm=FALSE

Thanks
Osama

Create new swap file to Linux

to add new swap file to Linux just follow the below steps , in my case i will add 32GB and i am not using LVM :-

  • just create file by the below command :-
    • touch /new.swap
  • Write on the file :-
    •  dd if=/dev/zero of=/new.swap bs=1024 count=33554432
  • Format the file :-
    • mkswap /new.swap
  • Add the file to the system as a swap file.
    • swapon /new.swap
  • finally add it to fstab :-
    • /new.swap none swap sw 0 0
Thanks
Osama

Direct NFS: please check that oradism is setuid

The above error appeared in Database Alertlog  and it’s related to permission, i am using DNFS as file system for Database :-

 ls -ltr  $ORACLE_HOME/bin/oradism

-rwxrwxr-x 1 sorabill oinstall 109247 Jul  7  2014 /u01/app/oracle/product/12.1.0/dbhome_1//bin/oradism

as you see from the above the permission for this file is wrong 
  • Change to root user
  • Run the following command :-
    • cd /u01/app/oracle/product/12.1.0/dbhome_1//bin
    • chmod 750 oradism
    • chmod u+s oradism
  • Restart DB.
Check again.
Cheers
Osama

Result: Clock synchronization check using Network Time Protocol(NTP) failed RAC

When trying to Run the Runcluvfy command to check RAC pre requsiites the NTP failed , but at the same time it’s gives you the solution to solve it  :-

in the following file :- /etc/sysconfig/ntpd open it and edit it, add the following :-

[root@prddb2 .ssh]# cat /etc/sysconfig/ntpd
# Drop root to id ‘ntp:ntp’ by default.
OPTIONS=”-x -u ntp:ntp -p /var/run/ntpd.pid -g”

Add the above letter in RED color only.

Thanks
Osama

Skip DNS reslov.conf check during RAC configuration

Before start reading this post you should know that Oracle is highly recommended using DNS while configure Oracle RAC include to this it will make your life easier in case any one wants to change the IP’s.

However today i was working on EBS installation using startCD51 and this is allow me to install EBS directly on RAC but the customer database RAC not configured to use DNS so everytime i was trying to install EBS

The following Error shown up in my face :-

INFO: Verification Result for Node:RAC1,RAC2WARNING: Result values are not available for this verification taskINFO: *********************************************INFO: Task resolv.conf Integrity: This task checks consistency of file /etc/resolv.conf file across nodesINFO: Severity:CRITICALINFO: OverallStatus:OPERATION_FAILEDINFO: ———————————————–

and there is nothing i can do to skip this error,

i choose to do the following ;-

Rename resolv.conf to resolv.conf.old for example

and re run the installation again .

perfect worked for me

Thanks
Osama

Maximum locked memory check Oracle

INFO: Maximum locked memory check: Check maximum locked memory setting on the system
INFO: Severity:IGNORABLE
INFO: OverallStatus:VERIFICATION_FAILED

To solve this issue just add the following to /etc/security/limits.conf

*                soft   memlock         unlimited
*               hard    memlock         unlimited

Thank you
Osama mustafa

Error : Cannot export Display Linux

There are different tools to do X11 forwarding on Windows one of them Xming it’s small software and very easy to use no need to do any special configuration only run the installation file.

But sometimes you are using this application and try to run the GUI on your desktop or laptop it’s working like you excepted, one simple solution to solve it.

I am using as ssh client Putty, before put the server ip from putty left panel

  • Connection > SSH > X11
  • Check X11 forwarding: [x] Enable X11 forwarding
  • Add to the “X display location” field: localhost:0.0
Cheers
Osama