Showing posts with label cli. Show all posts
Showing posts with label cli. Show all posts

1.3.14

Switched from Console.app to multitail

With Console.app I had the problem that when I switched to output /var/log/apache2/error_log I didn't see
/var/log/system.log and yesterday I read http://kkovacs.eu/cool-but-obscure-unix-tools and found multitail so I played with it.

I'm currently running the following setup on OSX Mountain Lion

mike@mikembp:~$ cat bin/multitail-log.sh
#!/bin/bash

multitail -s 2 /tmp/lsof-net.log \
    /var/log/apache2/error_log \
    /var/log/system.log -I /var/log/wifi.log -I /var/log/mail.log \
    /var/log/mysql.log

I had to make a crontab to get /tmp/lsof-net.log file, because multitail -R 2 -l "lsof lsof -RPi4 +c15" was crashing with "Operation not permitted". I think the problem is that lsofon Mac is in /usr/sbin. Crons minimal execution is every minute so I had to call the desired command 29 times with 2 second sleep.

mike@mikembp:~$ cat bin/cron-netlog.sh
#!/bin/bash

# crontab -e
# * * * * * /Users/mike/bin/cron-netlog.sh

LOGFILE=/tmp/lsof-net.log

for (( i=1; i <= 29; i++ ))
do
    /usr/sbin/lsof -RPi4 +c15 | grep -v -e rtorrent -e Mail -e Last | awk '{print $1,$2,$3,$4,$9,$10}' | column -t >> $LOGFILE
    sleep 2
done

mike@mikembp:~$ cat .crontab
# ~/.crontab
#
# Run:
# crontab ~/.crontab

MAILTO=user@example.com

* * * * * ~/bin/cron-netlog.sh

mike@mikembp:~$ crontab .crontab

16.2.14

Linux special case listing options, tricks

To list only files beginning with the specified character:

mike@jarvis:/media/sdb1/jpg$ ls -1 [A]*.jpg
A-AM11-GGD_icon01_s_1.jpg
A-AM11-GGD_icon01_s.jpg
A-AM13-GGD_icon02_s_1.jpg
A-AM13-GGD_icon02_s.jpg

mike@jarvis:/media/sdb1/jpg$ ls -1 [a]*.jpg
a001_1.jpg
a001.jpg
a002_1.jpg
a002.jpg
a003_1.jpg
a003.jpg
a004_1.jpg
a004.jpg
a005_1.jpg
a005.jpg
Finding PNG images greater than 800 pixels:
for f in *.png;do if [ `file $f | cut -f5 -d\ ` -gt 800 ] ; then echo $f;fi;done
Finding JPG images greater than 800 pixels (requires installed imagemagick, to have identify command):
for f in *.jpg;do if [ `identify "$f" | cut -f3 -d ' ' | cut -f1 -d x` -gt 800 ] ; then echo "$f";fi;done

Resources that can also help:
http://www.codecoffee.com/tipsforlinux/articles/26-1.html http://www.thegeekstuff.com/2009/07/linux-ls-command-examples/ http://www.cyberciti.biz/faq/linux-list-just-directories-or-directory-names/