root@testing:~# for i in `ls /var/log/syslog/syslog*`;do zgrep 'port 1099' $i | sed -n '1p;$p'; done;
Jun 25 08:18:01 testing sshd[33286]: error: connect_to x.y.z.c port 1099: failed.
Jun 25 11:30:52 testing sshd[45831]: error: connect_to x.y.z.d port 1099: failed.
Jun 24 07:55:04 testing sshd[64527]: error: connect_to x.y.z.d port 1099: failed.
Jun 24 11:53:13 testing sshd[64527]: error: connect_to x.y.z.c port 1099: failed.
Jun 23 08:59:52 testing sshd[34130]: error: connect_to x.y.z.c port 1099: failed.
Jun 23 15:28:38 testing sshd[34130]: error: connect_to x.y.z.d port 1099: failed.
Jun 20 08:24:51 testing sshd[64526]: error: connect_to x.y.z.c port 1099: failed.
Jun 20 10:55:46 testing sshd[7805]: error: connect_to x.y.z.c port 1099: failed.
środa, 25 czerwca 2014
Grep - get first and last line
Last time I had to search my logs for certain message. I needed to connect this with user login/logout time.
I needed estimated time of "start" and "end " occurences in logs ( logs which contains huge messages with different time and same message).
I used sed and grep to this:
poniedziałek, 16 czerwca 2014
czwartek, 12 czerwca 2014
Check SSL expiration date
Recently I needed to check out my domains due to SSL expiration date.
I used script below - it frees up time.
How does it work ?
I need file which contains domeins in form : address:port
In loop I check every domain with parameter "-enddate" (certificate expiration date) using openssl.
I change dates to timestamp and subtract expiration date from date "now+30days".
If result timestamp is lower than daystimestamp (which is number of days in seconds) it warnings me that certificate will expire soon.
shamrock@alucard:~$ cat check_ssl_expiration.sh
days=30
daystimestamp=`expr $days \* 86400`
for domain in `cat domeny.txt`
do
expire=`echo | openssl s_client -connect $domain 2>/dev/null | openssl x509 -noout -enddate | awk -F \= '{print $2}'`
out=`date -d "$expire" "+%s"`
in=`date --date="$days days" "+%s"`
res=`expr $out - $in`
if [ $res -lt 0 ]; then
echo "ALARM !!! DOMAIN $domain EXPIRED ON $expire"
elif [ $res -lt $daystimestamp ]; then
echo "ALARM !!! DOMAIN $domain WILL EXPIRE ON $expire"
else
echo "$domain WILL EXPIRE ON $expire"
fi
done
Usage:
shamrock@alucard:~$ bash check_ssl_expiration.sh
poczta.onet.pl:443 WILL EXPIRE ON Oct 14 06:10:33 2014 GMT
ALARM !!! DOMAIN some.kind.of.mons.tr:443 EXPIRE ON Jul 3 13:19:18 2013 GMT
File contains domains:
shamrock@alucard:~$ cat domeny.txt
poczta.onet.pl:443
some.kind.of.mons.tr:443
Etykiety:
bash,
expiration date,
openssl,
openssl verify,
script,
ssl,
validation ssl certificate
Subskrybuj:
Posty (Atom)