Tikejhya: Ashish Nepal

Knowledgebase

Month: December 2011

Escape blank line with cat

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Escape blank line with cat

grep -v "^$"

Cat / Grep numeric number delimited by comma values stored in third column only numeric and , seperated. 😀
This would be ideal to get the ID’S or any numeric value from log.

cat filetocat.txt | awk '{print $3}' | grep -v [a-z] | grep -v "^$" | tr ',' 'n' | wc -l

Netstat

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

netstat -tupan | grep -v TIME | awk ‘{print $7}’ | cut -f2 -d’/’

Unzipping bz2

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

bunzip2 file.bz2

Logrotate and move to backup directory

If you wish to backup old logs using olddir in logrotate it may create problem while giving separate partition for backup.

Logrotate and move to backup directory

Firstly i would suggest you to remove /var/log/messages from /etc/logrotate.d/syslog

vi /etc/logrotate.d/syslog

remove line /var/log/messages

vi /etc/logrotate.d/messages

Paste belwo given.

/var/log/messages
{
        daily
        rotate 10
        missingok
        postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
        /var/log/messagesrotate.sh || true
        endscript
}

::::::::::::::::::::: Script to run in Postrotate :::::::::::::::::::::::::::::::

#!/bin/bash
LogDate=$(date +"%s")
mv /var/log/messages.1 /data/logs/local_backup/var/log/messages/messages.$LogDate
gzip /data/logs/messages.$LogDate
exit

Find empty file

Find empty “file” and move to given destination

find path -empty -exec mv '{}' destination -type f ;

Find all type of empty Files and move to given destiation

find path -empty -exec mv '{}' destination ;

Powered by WordPress & Theme by Anders Norén