Archive

Posts Tagged ‘sed’

Checking SSL certificate expiry dates

June 1st, 2011 No comments

This is just a quick note to save this useful bit of information. I may make in to a script one day or use it in something else.

1
echo ''|openssl s_client -connect localhost:636 2>/dev/null | openssl x509 -noout -enddate | sed 's/^not.*\=//'

Delete single line from file

January 18th, 2010 No comments

I quite often need to remove a single line from a file by its line number. The most common use case for me is the known_hosts file when I have reinstalled a system, I have in the past used vim and navigated to the line then removed it. This is all well and good but it gets to be a pain having to do it repeatedly, especially when you manage around 1000 servers and the get rebuilt frequently. Finally today I had had enough so wrote a little script to do this task easily. Hopefully someone else finds this useful

Its usage is : delline LINE FILE

#!/bin/bash
LINE=$1
FILE=$2
if [ ! -f $FILE ] ; then
    echo "can't read $FILE: No such file or directory"
    exit 1
fi
if [ `expr $LINE + 1 2> /dev/null` ] ; then
    sed -i "${LINE}d" $FILE 
else
    echo $LINE is not numeric 
    exit 1
fi
Categories: Linux, Sysadmin Tags: ,