Shell Script to Ping Hostnames and Send SMS if Host is not Available

We use the below procedure to ping hosts and based on availability send SMS to our team. The SMS is send by calling a web service from the BASH Shell script using curl 

The hosts are defined in a file called hosts.txt

— Shell Script —

#!/bin/bash
current_time=$(date “+%Y%m%d%H%M%S%3N”)
#### Above Date Format is in MilliSeconds Accuracy ###
cd /home/online
rm -rf /home/online/SMSHOST.TXT
date
#### Below Code Will Loop the Hosts.TXT file for the Ping Probes ####
cat /home/online/hosts.txt | while read output
do
ping -w 30 -c 1 $output > /dev/null
if [ $? -ne 0 ]
then
SMSTEXT=’The+Host+’$output’+is+not+reachable.+Please+Contact+the+Database+Team.’
echo “Host $output is Down”
curl “http://192.168.10.100:8080/SMSConnect/SendServlet?application=http_gw2&password=http_gw2&content=$SMSTEXT&destination=9998887190&source=97249&mask=COMPANY”
else
echo “Host $output is Up”
fi
done

 

— hosts.txt file containing list of hostnames —

proddb01

proddb02

proddb03

drdb01

drdb02

drdb03

Advertisements

Shell Script to Add Date to Filenames

Below Shell Script will append Date to all FileNames in Directory with extension .TXT. Also it will create a folder with the Date and move the files to it.

#!/bin/bash
FILE=”$(date +%Y%m%d)”
cd /bi_dataload
mkdir -p /bi_dataload/BI_$FILE
for f in *.TXT
do
mv -n “$f” /bi_dataload/BI_$FILE/”${f%%.*}”_”$FILE”.TXT
done

Linux Matrix Effects Shell Script

Sometimes to have a funky time on the BASH shell you can run the below shell script

#!/bin/bash
clear
virtcent=$((`tput lines`/2))
horcent=$((`tput cols`/2-10))
tput setf 6
tput cup $virtcent $horcent && echo "entering the matrix"
sleep 1
tput cup $virtcent $horcent && echo " "
sleep 1
tput cup $virtcent $horcent && echo "entering the matrix"
sleep 1
tput cup $virtcent $horcent && echo " "
sleep 1
tput cup $virtcent $horcent && echo "connecting. "
sleep .1
tput cup $virtcent $horcent && echo "connecting.. "
sleep .1
tput cup $virtcent $horcent && echo "connecting... "
sleep .1
tput cup $virtcent $horcent && echo "connecting.... "
sleep .1
tput cup $virtcent $horcent && echo "connecting..... "
sleep .1
tput cup $virtcent $horcent && echo "connecting...... "
sleep .1
tput cup $virtcent $horcent && echo "connecting....... "
sleep .1
tput cup $virtcent $horcent && echo "connecting....... "
sleep .1
tput cup $virtcent $horcent && echo "connecting....... "
sleep .1
tput cup $virtcent $horcent && echo "connecting........ "
sleep .1
tput cup $virtcent $horcent && echo "connecting........."
sleep 1
tput cup $virtcent $horcent && echo " CONNECTED "
sleep 1
clear

echo -e "\033[2J\033[?25l"; R=`tput lines` C=`tput cols`;: $[R--] ; while true
do ( e=echo\ -e s=sleep j=$[RANDOM%C] d=$[RANDOM%R];for i in `eval $e {1..$R}`;
do c=`printf '\\\\0%o' $[RANDOM%57+33]` ### http://easyoradba.com ###
$e "\033[$[i-1];${j}H\033[32m$c\033[$i;${j}H\033[37m"$c; $s 0.1;if [ $i -ge $d ]
then $e "\033[$[i-d];${j}H ";fi;done;for i in `eval $e {$[i-d]..$R}`; #[mat!rix]
do echo -e "\033[$i;${j}f ";$s 0.1;done)& sleep 0.05;done #(c) 2016 -- [ ShadabMohammad ]

Just chmod 750 on the script and execute

$ vi matrix.sh
$ chmod 750 matrix.sh
$ matrix.sh

This is a re-worked version of the shell script available below.

http://bruxy.regnet.cz/web/linux/EN/matrix-sh/

Create ACFS Filesystem Oracle 12c Linux 12.1.0.2

— Create ACFS filesystem on 12c Linux Exadata —
1. Create a volume in ASM

ASMCMD [+] > volcreate -G datac1 -s 500G ACFS_VOL

If you get like below error

ORA-15032: not all alterations performed
ORA-15479: ASM diskgroup does not support volumes
ORA-15221: ASM operation requires compatible.asm of 12.1.0.2.0 or higher (DBD ERROR: OCIStmtExecute

Check the Current Compatibility for the Diskgroup

select group_number, name,compatibility, database_compatibility from v$asm_diskgroup
GROUP_NUMBER NAME COMPATIBILITY DATABASE_COMPATIBILITY
———— —————————— ———————————————————— ————————————————————
1 DATAC1 12.1.0.1.0 11.2.0.2.0
2 DBFS_DG 12.1.0.0.0 11.2.0.2.0
3 RECOC1 12.1.0.1.0 11.2.0.2.0
SQL> alter diskgroup DATAC1 set attribute ‘compatible.asm’=’12.1.0.2.0’;

Diskgroup altered.

SQL> alter diskgroup RECOC1 set attribute ‘compatible.asm’=’12.1.0.2.0’;

Diskgroup altered.

SQL> alter diskgroup DBFS_DG set attribute ‘compatible.asm’=’12.1.0.2.0′;

Diskgroup altered.

SQL> select group_number, name,compatibility, database_compatibility from v$asm_diskgroup;

GROUP_NUMBER NAME COMPATIBILITY DATABASE_COMPATIBILITY
———— —————————— ———————————————————— ————————————————————
1 DATAC1 12.1.0.2.0 11.2.0.2.0
2 DBFS_DG 12.1.0.2.0 11.2.0.2.0
3 RECOC1 12.1.0.2.0 11.2.0.2.0

Run again the volcreate command
ASMCMD [+] > volcreate -G datac1 -s 500G ACFS_VOL
2. Check the volume information
ASMCMD [+] > volinfo -G datac1 ACFS_VOL

Diskgroup Name: DATAC1

Volume Name: ACFS_VOL
Volume Device: /dev/asm/acfs_vol-45
State: ENABLED
Size (MB): 512000
Resize Unit (MB): 64
Redundancy: MIRROR
Stripe Columns: 8
Stripe Width (K): 1024
Usage:
Mountpath:
sqlplus “/as sysasm”

SELECT volume_name, volume_device FROM V$ASM_VOLUME
WHERE volume_name =’ACFS_VOL’;

VOLUME_NAME
——————————
VOLUME_DEVICE
——————————————————————————–
ACFS_VOL
/dev/asm/acfs_vol-45

3. Create a file system with the Oracle ACFS mkfs command using output of above command

With root user run below command

/sbin/mkfs -t acfs /dev/asm/acfs_vol-45
mkfs.acfs: version = 12.1.0.2.0
mkfs.acfs: on-disk version = 39.0
mkfs.acfs: volume = /dev/asm/acfs_vol-45
mkfs.acfs: volume size = 536870912000 ( 500.00 GB )
mkfs.acfs: Format complete.
4. Register the file system with the acfsutil registry command.

Create a directory called ACFS

cd /
mkdir /ACFS

/sbin/acfsutil registry -a /dev/asm/acfs_vol-45 /ACFS

acfsutil registry: mount point /ACFS successfully added to Oracle Registry
Imp Note 1: Registering an Oracle ACFS file system also causes the file system to be mounted automatically whenever Oracle Clusterware or the system is restarted.
Imp Note 2: Oracle ACFS registration (acfsutil registry) is not supported in an Oracle Restart (standalone) configuration, which is a single-instance (non-clustered) environment.
5. Verify if ACFS filesystem mounted automatically

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VGExaDb-LVDbSys1
30G 17G 12G 59% /
tmpfs 252G 22G 231G 9% /dev/shm
/dev/sda1 496M 54M 418M 12% /boot
/dev/mapper/VGExaDb-LVDbOra1
99G 57G 37G 61% /u01
/dev/mapper/VGExaDb-LVDbOra2
197G 68G 119G 37% /u02
/dev/mapper/VGExaDb-LVBkp1
985G 288G 648G 31% /u03
/dev/asm/acfs_vol-45 500G 1.1G 499G 1% /ACFS
As you can see from above output the ACFS filesystem moutned automatically after registration
6. If you did not register the ACFS filesystem it will not mount automatically, you can mount the ACFS filesystem manually using below command

As root user

/bin/mount -t acfs /dev/asm/acfs_vol-45 /ACFS

7. Give appropriate permissions to the filesystem required by Oracle users
chown -R oracle:dba /ACFS

su – oracle

cd /ACFS

touch abc.txt

Add a Disk and Extend FileSystem on RHEL7 on VMware Fusion 8 for Mac (El- Capitan)

Below is the Filesystem on our VM

Filesystem           Size  Used Avail Use% Mounted on

/dev/mapper/ol-root   18G   11G  7.0G  61% /

devtmpfs             476M     0  476M   0% /dev

tmpfs                491M  144K  491M   1% /dev/shm

tmpfs                491M  7.2M  484M   2% /run

tmpfs                491M     0  491M   0% /sys/fs/cgroup

/dev/sda1            497M  177M  320M  36% /boot

tmpfs                 99M   12K   99M   1% /run/user/0

Our aim is to grow the Filesystem /dev/mapper/ol-root

Filesystems in Linux are extended using the following steps

  1. Add a Physical Disk —> Needs a Shutdown
  2. Create a Physical Volume, using pvcreate —> Online
  3. Grow the Volume Group, using vgextend —> Online
  4. Grow the Logical Volume, using extend—> Online
  5. Extend the Filesystem(XFS) , using xfs_growfs—> Online

Let us continue and see each step in details now…

  1. Shutdown your VM and ddd the disk from option Virtual Machine—> Hard Disk (SCSI)
  2. Check from Disk Utility if the new Disk AppearsScreen Shot 2016-05-14 at 5.27.55 PM

$ pvdisplay

3. Create Physical Volume

root@localhost ~]# pvcreate /dev/sdc

WARNING: xfs signature detected on /dev/sdc at offset 0. Wipe it? [y/n]: y

  Wiping xfs signature on /dev/sdc.

  Physical volume “/dev/sdc” successfully created

4. Extend the Volume Group

$ vgdisplay

[root@localhost ~]# vgextend ol /dev/sdc

  Volume group “ol” successfully extended

5. Extend the Logical Volume

[root@localhost ~]# lvdisplay

  — Logical volume —

  LV Path                /dev/ol/root

  LV Name                root

  VG Name                ol

  LV UUID                nfBnYo-iJhh-fC0y-dWqD-A5Nf-SVHX-lBwioW

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2016-05-13 14:49:36 +0300

  LV Status              available

  # open                 1

  LV Size                17.47 GiB

  Current LE             4472

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  – currently set to     8192

  Block device           252:0

[root@localhost ~]# lvextend –size 35G /dev/ol/root

  Size of logical volume ol/root changed from 17.47 GiB (4472 extents) to 35.00 GiB (8960 extents).

  Logical volume root successfully resized.

[root@localhost ~]# lvdisplay

  — Logical volume —

  LV Path                /dev/ol/root

  LV Name                root

  VG Name                ol

  LV UUID                nfBnYo-iJhh-fC0y-dWqD-A5Nf-SVHX-lBwioW

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2016-05-13 14:49:36 +0300

  LV Status              available

  # open                 1

  LV Size                35.00 GiB

  Current LE             8960

  Segments               2

  Allocation             inherit

  Read ahead sectors     auto

  – currently set to     8192

  Block device           252:0

Now the logical volume is extended

6. Resize the Filesystem

Since this is RHEL7 and the default FS for root is XFS, if we try to grow the FS using resize2fs like we did earlier on ext3 and ext4, it will give below error

[root@localhost ~]# resize2fs /dev/ol/root 35G

resize2fs 1.42.9 (28-Dec-2013)

resize2fs: Bad magic number in super-block while trying to open /dev/ol/root

Couldn’t find valid filesystem superblock

If you were using RHEL6 and ext4, you could use resize2fs, but we will continue with xfs_growfs

To grow the XFS filesystem we have to use command xfs_growfs

[root@localhost ~]# xfs_growfs /dev/ol/root

meta-data=/dev/mapper/ol-root    isize=256    agcount=4, agsize=1144832 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0        finobt=0

data     =                       bsize=4096   blocks=4579328, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal               bsize=4096   blocks=2560, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

data blocks changed from 4579328 to 9175040

Check to confirm

Filesystem           Size  Used Avail Use% Mounted on

/dev/mapper/ol-root   35G   11G   25G  31% /

devtmpfs             476M     0  476M   0% /dev

tmpfs                491M  144K  491M   1% /dev/shm

tmpfs                491M  7.2M  484M   2% /run

tmpfs                491M     0  491M   0% /sys/fs/cgroup

/dev/sda1            497M  177M  320M  36% /boot

tmpfs                 99M   16K   99M   1% /run/user/0

Resize Filesystem, Logical Volume in Linux for Virtual Machine using ext4

Often when you have a Linux up and running you run out of space. I use VMware Fusion on my Macbook Pro 13 inch to do a lot of testing. To increase the diskspace you can follow the below simple steps

  1. Shutdown the VM and Increase the Diskspace
  2. Go to Disk Utility and the device /dev/sda will show the additional space as empty
  3. Right click and say create partition, once partition created it will have a device name eg:  /dev/sda3
  4. $ vgdisplay
  5. $ lvdisplay
  6. $ lvextend /dev/VolGroup/lv_root /dev/sda3
  7. The logical volume is extended now resize the filesystem to reflect the new change
  8. $ resize2fs /dev/VolGroup/lv_root
  9. $ df -h

    There is thus a new partition /dev/sda3 created and the logical volume is extended to include this partition. And finally the filesystem has been resized to reflect the disk size