One-liner: how to convert CheckPoint netconf.C routes to Gaia/Clish commands

Provided all route metrics are zeroes:

cat /etc/sysconfig/netconf.C | tr '(' ' '| tr ')' ' ' | tr '"' ' '| tr ':' ' ' | tr '\t' ' '| tr -s ' '| sed -e 's/^ //' | sed 's/routes//' | awk '/route/ {printf("set static-route ");} /dest/ {printf("%s ",$2);} /via/ {printf("nexthop gateway address %s ",$2);} /metric/ {print "on"}'

The result:

set static-route 10.13.198.160/27 nexthop gateway address 10.12.12.1 on
set static-route 10.13.198.192/27 nexthop gateway address 10.12.12.1 on
set static-route 192.168.112.0/24 nexthop gateway address 10.12.12.1 on
set static-route 192.168.113.0/24 nexthop gateway address 10.12.12.1 on
set static-route 192.168.114.0/24 nexthop gateway address 10.12.12.1 on
set static-route 192.168.115.0/24 nexthop gateway address 10.12.12.1 on
set static-route default nexthop gateway address 10.0.0.1 on

One-liner: how to check file growth in real time

Not quite a one-liner, but it can be copy&pasted in a terminal window πŸ˜‰

bash
TIME=10
FILE=file.log
function fsize {
	SIZE=`ls -l $FILE | awk '{print $5}'`
}
fsize
S1=$SIZE
while true
do
	sleep $TIME
	fsize
	S2=$SIZE
	(( DIFF=($S2-$S1)/$TIME ))
	echo "($S2-$S1)/$TIME = $DIFF"
	S1=$S2
done

The script above will check the “file.log” size every 10 seconds and output the previous size, the new size and bytes per second:

(30117062-30085517)/10 = 3154
(30148404-30117062)/10 = 3134
(30179199-30148404)/10 = 3079
^C
^D

Python on Solaris: Wrong ELF class: ELFCLASS64

If “pip” installed 64-bit libraries, while python is a 32-bit binary, “pkg” might stop working with the following error messages:

ImportError: ld.so.1: bootadm: fatal: /usr/lib/python2.7/site-packages/lxml/etree.so: wrong ELF class: ELFCLASS64
ImportError: ld.so.1: python2.7: fatal: /usr/lib/python2.7/site-packages/_cffi_backend.so: wrong ELF class: ELFCLASS64
$ file `which python`
/usr/bin/python:	ELF 32-bit LSB executable 80386 Version 1 [SSE], dynamically linked, not stripped

The workaround is to remove the corresponding python packages (in this case cffi and lxml), download and recompile them manually with “-m32”:

$ export CFLAGS="-m32"

One-liner: how to generate group-url for all remote-access tunnel-groups (Cisco ASA)

This one-liner takes Cisco ASA config, checks for “tunnel-group … remote-access” and generates the following two lines:

tunnel-group GROUPNAME webvpn-attributes
 group-url https://CISCO_ASA_FW_FQDN/GROUPNAME enable
for i in `fgrep tunnel-group CISCO_ASA.conf | fgrep remote-access | awk '{print $2}'`
do
echo "tunnel-group $i webvpn-attributes"
echo " group-url https://CISCO_ASA_FW_FQDN/$i enable"
done

One-liner: how to get image URLs from Google Image search

Let’s search for “red apple”:

For Solaris (use gsed instead of sed):

curl -A "Mozilla/5.0 (X11; SunOS i86pc; rv:52.0) Gecko/20100101 Firefox/52.0" \
'https://www.google.nl/search?q=red+apple&tbm=isch' 2>/dev/null | \ 
tail -1 | gsed -e 's/,"ow":/*/g' -e 's/,"ou":/*Image:/g' | \ 
tr '*' '\n' | grep "^Image" | sed -e 's/^Image:"//' -e 's/"$//' 

For Linux:

curl -A "Mozilla/5.0 (X11; SunOS i86pc; rv:52.0) Gecko/20100101 Firefox/52.0" \
'https://www.google.nl/search?q=red+apple&tbm=isch' 2>/dev/null | \ 
tail -1 | sed -e 's/,"ow":/*/g' -e 's/,"ou":/*Image:/g' | \ 
tr '*' '\n' | grep "^Image" | sed -e 's/^Image:"//' -e 's/"$//' 

Empty set vs empty string vs nothing and Zen

From my explanations of the set theory to my daughter yesterday.

A set is a container, an empty string (Ξ΅ or nothing) is an element. A set with nothing inside is not empty, because there is nothing inside. A set is empty (βˆ…) if it does not have anything inside.

In python:

$ python
>>> nothing=''
>>> set=[nothing]
>>> set
['']
>>> set.append('')
>>> set
['', '']
>>> set.remove('')
>>> set
['']
>>> set.remove(nothing)
>>> set
[]
>>> emptyset=[]
>>> emptyset
[]

Doing nothing and not doing anything are two different things.

One-liner: how to check the SSL certificate expiration of several servers

for i in cnn.com bbc.co.uk
do
  exp=`echo | openssl s_client -connect $i:443  2>/dev/null | 
  openssl x509 -noout -dates | fgrep notAfter | sed -e 's/^.*=//'`
  echo "$i        $exp"
done

cnn.com	    Feb  6 12:00:00 2018 GMT
bbc.co.uk   Apr 20 10:01:10 2017 GMT