Scripting

Debug a bash shell script

Shell scripting debugging can be boring job (read as not easy). There are various ways to debug a shell script. Method # 1: Use -x option Run a shell script with -x option. $ bash -x script-name $ bash -x domains.sh Method # 2: Use of set builtin command Bash shell offers debugging options which […]

Read More
Linux

Mass setting user passwords

Every need to change (or set) passwords for a large number of users? Something like this code snippet may help. # find all the usernames with bash logins usernames=$(cat /etc/passwd | grep bash | sed ‘s/:.*//g) for i in $usernames; do echo “somepassword” | passwd –stdin $i done

Read More
Linux

nslookup-scan of IP-range/subnet

#!/bin/bash # nslookup-scan of IP-range # It’s possible to add more networks separated with space NETS=”192.168.0″ IPRange=”1 254″ for NET in $NETS; do for n in $(seq $IPRange); do ADDR=${NET}.${n} echo “${ADDR},`nslookup ${ADDR} | awk -F “=” ‘{ print $2 }’|sed ‘s/^[ t]*//’ | sed ‘/^$/d’ | |sed ‘s/.$//’`” done done Result 192.168.0.1,cba.infra.no 192.168.0.2,bca.infra.no 192.168.0.3,abc.infra.no […]

Read More
Linux

Hints and Tips for general shell script programming

WARNING: this will fail if the user is playing with $0 For example using a symbolic or hard link with a unexpected name. # Simplest… # PROGNAME=`type $0 | awk ‘{print $3}’` # search for executable on path PROGNAME=`basename $PROGNAME` # base name of program # Advanced… # Script name, in what directory, and in […]

Read More
Network

Verifying DNS mappings

An improperly configured DNS setup can be really annoying. You want to make sure that your mappings work both ways: Each hostname should resolve to an address, and that address ought to resolve back to the proper hostname. If an address on your subnet(s) has been assigned a reverse pointer to a hostname, that hostname […]

Read More