Quick bash oneliners
The following are a few one liner shell commands I occasionally use: Get the current external ip address: GET checkip.dyndns.org | tr -d ' /:-z'
Quick Postfix MailQ estimate
Get an estimation of postfix mail queue:
mailq|wc -l
Process Running
Find out if a process is running from name:
ps uxa|grep -i processname
disk usage by size
Get a list of directories sorted by size:
du -s -h *|sort -h
Available hosts by ip
ping a list of ips: cat file-of-ips | xargs -n 1 -I ^ -P 50 ping ^
Available hosts by hostname
ping a list of hosts in a file: cat hosts|xargs -n1 ping -c 1
Start All Xen VMs
If you need to start all Xen Hosts on a machine, try the following simple script:
ARRAY=`xe vm-list tags="autostart" | grep uuid | awk '{ print $5 }'`
for f in $ARRAY
do
VM_NAME=`xe vm-param-get uuid=$f param-name=name-label`
echo "Starting $VM_NAME"
/opt/xensource/bin/xe vm-start uuid=$f
done
Scan a subnet
Many tools exist to scan networks such as nmap, *nessus. However, many times you are on a machine where those tools are not available.
Here is a quick script to do just that:
if [ $# -ne 0 ]
then
echo "Subnet provided $1"
subnet=$1
else
subnet=192.168.1
fi
printf "\nPinging network $subnet.1-$subnet.254\n\n"
for addr in $(seq 1 254)
do
( ping -c 1 -t 3 $subnet.$addr > /dev/null 2>&1 && echo - Ping reply: $subnet.$addr ) &
done
sleep 2
printf "\n"