Bash Quick Reference

Advanced Bash-Scripting Guide sed awk Internal Variables #current parent pid $$ #last background process pid $! #last exit status $? #current instance pid, Bash 4.x above. $BASHPID Arithmetic Expansion a=12 b=$(($a + 10)) b=`expr $a + 1` b=$(expr $a + 1) let b=$a+3 #let b=$a + 3 #incorrect let "b = $a + 3" declare -i b=$a+$a Manipulating Strings String is a number if [[ $var =~ ^-?[0-9]+$ ]]; then echo "$var is a number" fi if [[ !...

December 4, 2014 · 3 min · oopsmonk

Raspberry Pi Monitor

Use RRDTool monitor Raspberry Pi, include CPU temperture, Memory usage, Disk I/O, Network I/O… Install install packages $sudo apt-get install libcairo2-dev libpango1.0-dev libglib2.0-dev libxml2-dev \ librrd-dev python2.7-dev rrdtool python-rrdtool $wget https://pypi.python.org/packages/source/p/psutil/psutil-2.1.1.tar.gz $tar xf psutil-2.1.1.tar.gz $cd psutil-2.1.1 $sudo python setup.py install Download or clone rpi-monitor on github https://github.com/oopsmonk/rpi-monitor Setup Crontab By defualt, the cron.log is disabled in Raspbian. To enable it: sudo vi /etc/rsyslog.conf find the line and uncomment it. # cron....

July 21, 2014 · 1 min · oopsmonk

Baking 2013

起司麵包 綜合麵包 平底鍋做麵包 戚風蛋糕 香蕉核桃馬芬蛋糕 鮭魚炒飯

December 31, 2013 · 1 min · oopsmonk

GitHub SVN Upstream (on Ubuntu12.04)

This is a git tutorial, create svn upstream on GitHub. Use MOC project as a example. #Checkout SVN and push to GitHub. Install packages $ sudo apt-get install subversion git-svn Create git repository (it will take a long time) $ git svn clone svn://daper.net/moc/trunk --no-metadata ./moc-svn-git $ cat moc-svn-git/.git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [svn-remote "svn"] noMetadata = 1 url = svn://daper.net/moc/trunk fetch = :refs/remotes/git-svn Update SVN repository...

August 26, 2013 · 2 min · oopsmonk

Building MOC

clone MOC svn repository to github Ref: Converting a Subversion repository to Git $ sudo apt-get install subversion git-svn $ mkdir moc-svn $ cd moc-svn $ svn co svn://daper.net/moc/trunk $ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt $ cd .. $ mkdir moc-git $ git svn clone svn://daper.net/moc/trunk --no-metadata -A ./moc-svn/authors-transform.txt ....

August 23, 2013 · 2 min · oopsmonk

Web dev example : JSON & jQuery Mobile & Bottle

Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. jQuery Mobile base on jQuery for mobile device. jQuery vs. jQuery Mobile vs. jQuery UI Install bottle: $ sudo apt-get install python-setuptools $ easy_install bottle Demo server deployment file structure: BottlejQuery ├── bottleJQuery.py └── index.html run command: $ ./bottleJQuery.py connect to server: http://localhost:8080/bottle Building simple web server use bottle bottleJQuery.py #!/usr/bin/env python from bottle import route, static_file, debug, run, get, redirect from bottle import post, request import os, inspect, json #enable bottle debug debug(True) # WebApp route path routePath = '/bottle' # get directory of WebApp (bottleJQuery....

August 7, 2013 · 4 min · oopsmonk

Sending HTML Mail Using SMTP With Authorization

Here is a text/plain MIME type parts in official exmaple code. I remove it from my sample code, because it’s not show up in mail at Office Outlook 2010. #!/usr/bin/env python """ File name: sendMail.py Python send HTML mail using SMTP with authorization Usage : ./sendMail.py to@gmail.com Subtitle [ FilePath | txt ] """ import smtplib import sys,traceback from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from time import gmtime, strftime #log file location log_path = "....

July 31, 2013 · 2 min · oopsmonk