Author: rpaco

  • Compare two files and show the differences only using shell command

    awk ‘BEGIN { while ( getline < "file1.txt" ) { arr[$0]++ } } { if (!( $0 in arr ) ) { print } }' file2.txt

  • Sample Ping Script

    It’s just a simple ping script. #!/bin/bash # Program name: test.sh date cat /root/listping.txt | while read output do ping -c 1 “$output” > /dev/null if [ $? -eq 0 ]; then echo “node $output is up” else echo “node $output is down” fi done

  • Crontab which run on every 1st Monday of the month

    30 11 1-7 * * [[ $(date +\%a) = Mon ]] && mailx -s “Test cron script” test@test.com< /root/myfile

  • Add restricted user in linux manually.

    The code below will only allow the following commands. ping ssh telnet traceroute ifconfig route Add_Restricted_User.sh #!/bin/sh # Add restricted user in linux manually. # August 13, 2015 # Created by Rodel for a in `cat /opt/scripts/Add_Restricted_User/serverlist.txt`; do for b in `cat /opt/scripts/Add_Restricted_User/usernames.txt`; do echo $a $b; ssh $a “useradd -s /bin/rbash ‘$b’; echo -e…

  • Allow incoming/outgoing SNMP traffic in IPTables

    Allow outgoing SNMP traffic in IPTables iptables -A INPUT -i eth0 -p udp -s–sport 161:162 -d –dport 1024:65535 -m state –state ESTABLISHED -j ACCEPT iptables -A OUTPUT -p udp -s –sport 1024:65535 -d –dport 161:162 -m state –state NEW,ESTABLISHED -j ACCEPT Allow incoming SNMP traffic in IPTables iptables -A INPUT -i eth0 -p udp -s…

  • Allow Incoming/Outgoing ICMP traffic in IPTables

    Enable or allow ICMP ping incoming client request. iptables -A INPUT -i eth0 -p icmp –icmp-type 8 -s-d -m state –state NEW,ESTABLISHED,RELATED -j ACCEPT iptables -A OUTPUT -p icmp –icmp-type 0 -s -d -m state –state ESTABLISHED,RELATED -j ACCEPT Allow or enable outgoing ping request. iptables -A INPUT -i eth0 -p icmp –icmp-type 0 -s-d…

  • NRPE Installation and Configuration on the client machine

    1) Install the required packages in preparation to install NRPE. [root@MACHINE1 ~]# yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel 2) Add nagios username and update the password. [root@MACHINE1 ~]# useradd nagios [root@MACHINE1 ~]# passwd nagios Changing password for user nagios. New password: mypassword Retype new password: mypassword passwd: all authentication tokens…

  • Nagios Installation

    1) Install Required Dependencies #yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp 2) Create Nagios User and Group #useradd nagios #groupadd nagcmd 3) Next, add both the nagios user and the apache user to the nagcmd group. #usermod -G nagcmd Nagios #usermod -G nagcmd apache 4) Create Nagios directory. #mkdir /root/nagios…

  • How to list/sort all the RPM packages installed in your Linux server.

    Below is the command I use to list or sort all the packages installed in my linux system. rpm -qa –queryformat “%{GROUP} %{NAME}-%{VERSION}\n” | sort  Sample Output: Applications/Archiving cpio-2.10 Applications/Archiving pax-3.4 Applications/Archiving tar-1.23 Applications/Archiving unzip-6.0 Applications/Archiving zip-3.0 Applications/Databases db4-utils-4.7.25 Applications/Databases mysql-5.1.71 Applications/Databases mysql-libs-5.1.71 Applications/Databases mysql-server-5.1.71 Applications/Databases ntteam-MySQL-shared-5.5.28 Applications/Databases postgresql-8.4.13 Applications/Databases postgresql-libs-8.4.13 Applications/Databases postgresql-odbc-08.04.0200 Applications/Databases PyGreSQL-3.8.1…

  • Check MySQL database size

    This is an example on how to check mysql database size of cacti database. mysql> show databases; +——————–+ | Database           | +——————–+ | information_schema | | cacti              | | mysql              | | test               | +——————–+ 6 rows in set (0.00 sec) The the command below. mysql> SELECT table_schema cacti, sum( data_length + index_length ) /…