case $a in
1) b=$c ;;
*) b=$d ;;
esac
[[ $a=1 ]] && b=$c || b=$d
# At this case, 3rd part can be executed in case 2nd part fails
[[ $a=1 ]] && { b=$c; true; } || b=$d
# to avoid executing 3rd part by accident when 2nd part fails
## semicolon(;) is needed in {}
2013-08-27
Ternary operator(?:) in bash
Ternary operator is a short form of if/then/else
2013-08-23
Count number of visitors(IP addresses) with IIS log files
* Instruction
- Mount IIS log directory into Linux box
$ sudo mount -t cifs -o ro,username=USER,password=PASSWD //HOST_IP/SHARE /MOUNT_POINT
- Run
#!/bin/bash site_num=(1 2 7 8) site_addr=("AAA.com" "BBB.com" "CCC.com" "DDD.com") echo "SITE_NAME DATE WEEK TRAFFIC DB_CONN VISITOR" for ix in ${!site_num[*]} do d=${site_num[$ix]} for f in $(ls W3SVC$d) do if [[ ${f:4:6} -ge $(date -d 'last monday' +"%y%m%d") && ${f:4:6} -lt $(date +"%y%m%d") ]] then visitors=$(cat W3SVC$d/$f | grep ^[0-9] | awk '{if(!match($9, /^192.168./) && !match($9, /^10.10./)) print $9}' | sort | uniq | wc -l) sendbytes=$(cat W3SVC$d/$f | grep ^[0-9] | awk '{print $16}' | awk '{total=total+$1}END{printf "%.f", total}') dbconns=$(cat W3SVC$d/$f | awk '{if(match($5,/^\/$/) || match($5,/asp/)) print $9}' | wc -l) weeknum=$(date -dyesterday +%V) [ $(date -d yesterday +%u) -eq 1 ] && {mon=$(date -d yesterday +%m.%d); true} || mon=$(date -d last-monday +%m.%d) [ $(date -d yesterday +%u) -eq 7 ] && {sun=$(date -d yesterday +%m.%d); true} || sun=$(date -d sunday +%m.%d) printf "%s 20%s-%s-%s %s(%s-%s) %s %s %s\n" ${site_addr[$ix]} ${f:4:2} ${f:6:2} ${f:8:2} $weeknum %mon %sun $sendbytes $dbconns $visitors fi done done
- * Sample result
SITE_NAME DATE WEEK TRAFFIC DB_CONN VISITOR AAA.com 2013-08-25 34(08.19-08.25) 12329500782 54908 7335 BBB.com 2013-08-25 34(08.19-08.25) 13074318914 66700 6442 CCC.com 2013-08-25 34(08.19-08.25) 23734108053 140609 12877 DDD.com 2013-08-25 34(08.19-08.25) 8913154535 58417 5172
How to run NginX/PHP/MySQL on Mac
Needed to run DRUPAL on Mac
- Install XCode
- Install XCode Command Line Tools
- Install Homebrew - Similar to MacPorts but better
- Install MySQL
- Install NginX
- Install PHP
XCode > Preferences > Downloads > Command Line Tools
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
$ brew doctor
$ brew tap josegonzalez/homebrew-php
$ brew tap homebrew/dupes
$ brew install mysql
$ unset TMPDIR
$ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
$ sudo mv /usr/local/opt/mysql/my-new.cnf /usr/local/opt/mysql/my.cnf
$ cp `brew --prefix mysql`/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
$ brew install nginx
$ sudo cp `brew --prefix nginx`/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/
$ sudo sed -i -e 's/`whoami`/root/g' `brew --prefix nginx`/homebrew.mxcl.nginx.plist
$ sudo mkdir /var/log/nginx/
$ brew install --without-apache --with-fpm --with-mysql php54
$ sudo cp `brew --prefix php54`/homebrew-php.josegonzalez.php54.plist /Library/LaunchAgents/
$ sudo launchctl load -w /Library/LaunchAgents/homebrew-php.josegonzalez.php54.plist
2013-08-09
How to extract MP3 audio from ASF in Linux environment
COMMAND :
for files in $(ls); do avconv -i $(files) -vn -acodec wmav2 -f asf ${files:0:2}".mp3"; done
If FILES are
01.asf
02.asf
03.asf
Subscribe to:
Posts (Atom)