Bash test if port is open no external tools

Assume you do not have curl/telnet/netcat (or nc does not support -z as in later versions ?? why did they remove it ?? ) the following will work on any recent Bash version. (echo > /dev/tcp/skinner/22) >/dev/null 2>&1 && echo “Port is open” || echo “Port is closed” nJoy 😉

Run a local script on remote machine with parameters

So you have a script on the local machine and you want to run it remotely and pass arguments to it : ssh user@remote ‘cat | bash /dev/stdin param1 param2 .. paramN’ < /usr/scripts/localscript.sh 😉 nJoy  

Progress bar in bash

a=0; for i in `cat $FOLDERLIST` do ((a++)) percentage=`awk -v a=$a -v b=$NUMBEROFFOLDERS 'BEGIN {printf "%3.0f", a / b * 100; exit } '` arrow=`printf '=%.0s' $(seq 1 $percentage)` headed=`printf '%s%s' $arrow '>'` paddedarrow=`printf '%-102s' $headed` echo -ne "$paddedarrow $a/$NUMBEROFFOLDERS [$percentage] \r " done echo njoy  😉

Kernel: e1000e 0000:02:00.0: eth0: Error reading PHY register

In recent CentOS version 6.3 is an unresolved bug, which causes the network card to freeze the server. Following message appears in /var/log/messages kernel To work around the problem you will need to turn off Active-State Power Management (ASPM) (Feature that saves power in the Peripheral Component Interconnect Express (PCI Express or PCIe) subsystem by…

UDP send and listen for passing messages and test connectivity

Setting up a listener in UDP : Install socat Jist here (Centos 6.6 : http://jist.sudoall.com/socat/setup install curl “http://jist.sudoall.com/socat/setup” | bash – socat -u udp-recv:8888 – To send the datagram : nc -u 127.0.0.1 8888 njoy 😉

Magic SysRq key

The “magic SysRq key” provides a way to send commands directly to the kernel through the /proc filesystem. It is enabled via a kernel compile time option, CONFIG_MAGIC_SYSRQ, which seems to be standard on most distributions. First you must activate the magic SysRq option: echo 1 > /proc/sys/kernel/sysrq When you are ready to reboot the…