Thursday, April 26, 2018

List all the Filesystems which are more than 80% used in linux with awk command


Monitoring file system utilization on linux production server is a very important thing.  We can automate the file system utilization monitoring and schedule it in crontab.  So that script will run at the scheduled time and send out the alert messages.

It's always a good idea to have multiple threshold set for file system and we can make sure it won't reach 100% and the file system crashes on the server.

Below are the few examples of monitoring the file system threshold with powerful awk command.

[santhosh@localhost ~]# df -hP | tr -d "%" | sed 1d | awk '$5 >80'
/dev/mapper/vg00-mysql   30G   25G  3.7G  87 /u01
/dev/mapper/vg00-yumrepo  30G   24G  5.8G  81 /yumrepsitory


[santhosh@localhost ~]# df -hP | tr -d "%" | sed 1d | awk '{if($5>80) print}'
/dev/mapper/vg00-mysql   30G   25G  3.7G  87 /u01
/dev/mapper/vg00-yumrepo  30G   24G  5.8G  81 /yumrepsitory


[santhosh@localhost ~]# df -hP | tr -d "%" | sed 1d | awk 'int($5) > 80 { print $0 }'
/dev/mapper/vg00-mysql   30G   25G  3.7G  87 /u01
/dev/mapper/vg00-yumrepo  30G   24G  5.8G  81 /yumrepsitory

Monday, April 16, 2018

How to convert string to Uppercase and Lower case in Linux using awk and tr commands.



Lowercase to Uppercase:

Using awk command.
root@linuxserver:/root> echo santhosh | awk '{ print toupper($0)}'
SANTHOSH

Using tr command.
root@linuxserver:/root> echo santhosh | tr '[a-z]' '[A-Z]'
SANTHOSH


Uppercase to Lowercase:

Using awk command.
root@linuxserver:/root> echo SANTHOSH | awk '{ print tolower($0)}'
santhosh

Using tr command.
root@linuxserver:/root> echo SANTHOSH | tr '[A-Z]' '[a-z]'
santhosh