Bash Scripting – TRAP

Many of us might have faced a stiuation where we have started a script, waiting for its outcome and suddenly someone/ourself do a CTRL+C by mistake to terminate the script. Wouldn’t it be nice if our script becomes ‘immune’ to CTRL+C signal. Here comes ‘trap’ command for help. ‘trap’ command basically traps the signal which…

 Script to get the list of services running on system in below format: Protocol – Port – Program Name for LIST in `netstat -nalpe | egrep -i ‘^tcp|^udp’ | grep ‘LISTEN’ | awk ‘{ print $1"|"$4"|"$9 }’`; do PROT=`echo ${LIST} | cut -d"|" -f1`; PORT=`echo ${LIST} | cut -d"|" -f2`; PORT=${PORT##*:}; PROG=`echo ${LIST} | cut…