顯示具有 shell script 標籤的文章。 顯示所有文章
顯示具有 shell script 標籤的文章。 顯示所有文章

2011年4月2日 星期六

android 使用proxy連接至網路

http://forum.xda-developers.com/showthread.php?t=766569
http://darkk.net.ru/redsocks/


in nexus one(cyanogenmod 7):
  eth0/wl0.1
    wifi/softap(BCM4329)
  lo
    loopback
  rmnet0
    3G

in rooted and installed superuser phone, if run "su root", the superuser program will ask user to confirm root access via UI.

transproxy.apk
  This program use redsock internal
     This tool allows you to redirect any TCP connection to SOCKS or HTTPS proxy using your firewall, so redirection is system-wide.

  after install this program, some file will be placed in data/data/com.hasbox.tproxy/, I found there are some scripts in "files" directory
    enable transproxy
      sh data/data/com.hasbox.tproxy/files/proxy.sh start /data/data/com.hasbox.tproxy/files type=http host= port= auth=false user= pass=
      sh data/data/com.hasbox.tproxy/files/redirect.sh start http
    disable transproxy
      sh data/data/com.hasbox.tproxy/files/proxy.sh stop /data/data/com.hasbox.tproxy/files
      sh data/data/com.hasbox.tproxy/files/redirect.sh stop

  when execution /data/data/com.hasbox.tproxy/files/redirect.sh,because android bionic libc not implement getprotobyname(), so there some warning messabe
    in my environment, 3G need use proxy but wifi can direct access , so modify redirect.sh, add " -o rmnet0" in each rule, only 3G access use proxy

  bugs
    android's netd will reset ipatbles when disable tethering(ether wifi or usb), so the setting by transproxy will gone.
      must set transproxy.apk after disable tethering
 

2011年2月25日 星期五

script內判斷cpu數量

CPUs=$(echo `cat /proc/cpuinfo | grep processor | tail -1 | awk'{print $3}'` +1 | bc)

2010年12月5日 星期日

找尋程式中使用哪些define的flag做判斷

一般程式會在編譯時定義一些flag來決定是否啟動某功能的支援,
而在程式內的實作會使用ifdef XXX來判斷,

可以用以下的script找出所有用ifdef判斷的flag,
來確認所需的功能是否在編譯時有加入

1. 搜尋所有ifdef
2. 取得第二個欄位的資料
3. 排序(刪去重複)


grep -rns ifdef * | awk '{FS=" "} {print $2}' | sort -u

2010年11月11日 星期四

tar加上分割檔案

今天要把資料打包放到隨身碟上,
不過卻發現隨身碟為fat32,不支援單一大檔案,
所以google一下方便的分割方法

參考:
http://blog.24reader.com/vincentlam/2009/04/22/%E4%BD%BF%E7%94%A8tar%E6%89%93%E5%8C%85%E5%A3%93%E7%B8%AE%E4%B8%A6%E5%88%86%E5%89%B2%E7%82%BA%E5%9B%BA%E5%AE%9A%E5%A4%A7%E5%B0%8F%E7%9A%84%E6%AA%94%E6%A1%88/
http://lovejuan1314.javaeye.com/blog/457841


原本壓縮:
tar -zcvf XXXX.tar.gz XXXX

原本解壓縮:
tar -zxvf XXXX.tar.gz



壓縮並分割:
tar -zcvf- XXXX| split -a 1 -b 1000m - ./XXXX.tar.gz.
壓縮結果:
XXXX.tar.gz.a
XXXX.tar.gz.b
XXXX.tar.gz.c
...

解壓縮:
cat XXXX.tar.gz* | tar -zxvf-

2010年5月31日 星期一

使用shell script計算CPU使用率

PROGRAM_NAME --程式名稱
DELAY ---------每隔多久看一次CPU usage
NUMBER --------總共看幾次


取得系統CPU使用率:
top -b -n NUMBER -d DELAY | tee top.log
cat top.log | grep CPU: | awk '{print $8}' | sed s/%//g

若要查看某程式的cpu使用率
cat top.log | grep -v grep | grep PROGRAM_NAME | awk '{print $7}'| sed s/%//g







example:
假設要看hello程式, 一分鐘內每隔一秒的CPU使用率:

top -b -n 60 -d 1 | grep -v grep | grep hello | awk '{print $7}'| sed s/%//g
輸出結果:
0
9
5
2
1
2
2
2
4
2
2
3
3
1
2
3
2
3
2
0
.....