Get interface name of ip address using bash

The following command will return the interface name of a particular ip address (x).

ip addr show | grep xxx.xxx.xxx.xxx | cut -f2 | awk '{ print $7 }' | head

Fetching MySQL query result in bash

Quick bash script I did for getting result from a MySQL query. It gets a number value from a database and if the number is less than (-lt) it executes another command. You can substitute -lt for -gt (greater than) as required. There are two versions the first executes a command on both pass and fail the second only reports on fail.

Version 1

#!/bin/bash
connections=$(mysql database -se "select count from nodes where status='1';")
if [ $connections -lt 200 ];
then echo "ERROR"
else echo "OK"

fi

Version 2

#!/bin/bash
connections=$(mysql database -se "select count from nodes where status='1';") if [ $connections -lt 200 ];
then echo "ERROR"
fi