shell获取本机ip

获取本机ip ifconfig eth0 | sed -n 's/^\s*inet addr://p' | awk '{ print $1 }' 但是ifconfig的输出,有可能有中文。 ~$ ifconfig eth0 eth0 Link encap:以太网 硬件地址 ****** inet 地址:****** 广播:**** 掩码:***** inet6 地址: fe80::21a:a0ff:feab:1961/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1 接收数据包:38100 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:34026 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1000 接收字节:20977069 (20.9 MB) 发送字节:6029574 (6.0 MB) 中断:16 改一下才能通用: ...

January 15, 2010 · notsobad

清除kernel image和grub菜单

参考这里 ubuntu下,清除掉多余的kernel image和grub菜单。 保留最新的一两个就行了,多余的都去掉。 ~$ ls /boot/vml* /boot/vmlinuz-2.6.31-14-generic /boot/vmlinuz-2.6.31-15-generic /boot/vmlinuz-2.6.31-16-generic /boot/vmlinuz-2.6.31-17-generic ~$ sudo apt-get remove linux-image-2.6.31-14-generic ~$ sudo update-grub

January 13, 2010 · notsobad

利用reST来写文档

利用reST来写文档,然后用rst2html,rst2pdf来编译成html和pdf。 关于reST,我以后会再详细介绍一下。 509 ~/script/notsobad/reST/php_standard>tree . |-- Makefile |-- main.rst |-- main.style |-- php-standard.html `-- php-standard.pdf 0 directories, 5 files 510 ~/script/notsobad/reST/php_standard>cat Makefile all: php-standard.pdf php-standard.html php-standard.pdf: main.rst rst2pdf main.rst -o php-standard.pdf; php-standard.html: main.rst rst2html -ts -l zh_cn main.rst > php-standard.html clean: rm php-standard.* 511 ~/script/notsobad/reST/php_standard>make make: 没有什么可以做的为 'all' 512 ~/script/notsobad/reST/php_standard>rm php-standard.* 513 ~/script/notsobad/reST/php_standard>make rst2pdf main.rst -o php-standard.pdf; rst2html -ts -l zh_cn main.rst > php-standard.html

January 13, 2010 · notsobad

svn忽略文件

svn里面经常会有一些不必要的文件,比如.tmp,.swp等,这是因为添加的时候没注意 正确的应该是设置忽略文件,svn增加一个目录,先不增加里面的文件。 svn add php_standard/ --depth empty 然后设置忽略文件 ~$ svn propset svn:ignore "*.pdf" php_standard/ 设置属性 “svn:ignore” 于 “php_standard” ~$ ~$ svn propget svn:ignore *.pdf 或者忽略整个目录的内容 ...

January 12, 2010 · notsobad

随机显示一条脚本技巧

从http://www.shell-fu.org/lister.php?random 会随机的显示一条脚本技巧. 把下面的内容放到bashrc中,运行shellfu即可,enjoy! shellfu(){ curl -s "http://www.shell-fu.org/lister.php?random" | sed -e 's/ /\n<\/div>\n/g' | sed -n -e "/ /,/<\/div>/p" | lynx -stdin -dump -nolist; } 运行效果: 518 ~>shellfu The commmands below show the ten largest files/dirs in the working directory. Both commands give similar results, though handle things slightly differently. The 'du' option is good if you also need sizes of subdirectories, but the 'ls' option gives more detail. ls -laSh | head -10 du -s * | sort -nr | head -10 I find both to be useful in situations where I need to make more free space. 518 ~>shellfu Mail somebody about space running low in some path (ksh, bash): PATHS="/export/home /home" AWK=/usr/bin/awk DU="/usr/bin/du -ks" GREP=/usr/bin/grep DF="/usr/bin/df -k" TR=/usr/bin/tr SED=/usr/bin/sed CAT=/usr/bin/cat MAILFILE=/tmp/mailviews$$ MAILER=/bin/mailx mailto="[email protected]" for path in $PATHS do DISK_AVAIL=`$DF $path | $GREP -v "Filesystem" | $AWK '{print $5}'|$SED 's/%//g'` if [ $DISK_AVAIL -gt 90 ];then echo "Please clean up your stuff\n\n" > $MAILFILE $CAT $MAILFILE | $MAILER -s "Clean up stuff" $mailto fi done

January 11, 2010 · notsobad

我的处理照片脚本

以前写的一个处理相片的脚本,使用imagemagick 把数码相机里的照片转成1024宽的图片,同时在照片上添加一个水印,内容是从EXIF中取出的拍摄时间。 #!/bin/sh # File: deal_photo.sh # Description: # 把数码相机里的照片转成1024宽的图片 # 同时在照片上添加一个水印,内容是从EXIF中取出的拍摄时间 # Created: 2009-11-02 10:01:11 # Last modified: 2009-11-02 10:01:11 set -x for i in *.JPG;do out=`echo _$i|sed 's/JPG$/jpg/'` time=`identify -format "%[EXIF:DateTime]" $i` title="notsobad at $time" [ -f $out ] && rm $out; convert -gravity south\ -size 1024x \ +profile "*" \ -fill green \ -pointsize 30\ -font /home/wang/.fonts/MONACO.TTF \ -draw "text 10,10 '$title'" \ $i $out done

January 11, 2010 · notsobad

使用ffmpeg来进行屏幕录像

使用ffmpeg来进行屏幕录像 man里面的: X11 grabbing FFmpeg can grab the X11 display. ffmpeg -f x11grab -s cif -i :0.0 /tmp/out.mpg 0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. ffmpeg -f x11grab -s cif -i :0.0+10,20 /tmp/out.mpg 0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. 10 is the x-offset and 20 the y-offset for the grabbing. 保存为a.avi ffmpeg -f x11grab -s 1024x768 -r 60 -i :0.0 a.avi 结束后q退出,效果还不错。

January 10, 2010 · notsobad

随机的显示一张xkcd漫画

随机的显示一张xkcd的漫画, 把这个加到你的~/.bashrc里面。 xkcd(){ wget -q http://dynamic.xkcd.com/comic/random/ -O - | grep -Eo http://imgs.xkcd.com/comics/.*png | wget -q -i - -O - | display; } 然后无聊的时候运行下xkcd就行了 display工具是属于imagemagick的包里面

January 10, 2010 · notsobad

Beautifulsoup的unicode问题

python的unicode问题实在是让人痛苦,本身要写一段小程序,时间都被浪费在处理unicode上面了。 我的python版本 python -c 'import sys;print sys.version' 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] import os,sys from BeautifulSoup import BeautifulSoup, SoupStrainer def get_info(cont): print type(cont) soup = BeautifulSoup(cont) a = soup.findAll('a') print type(a) print(a) if __name__ == "__main__": s = sys.stdin.read() s = unicode(s, 'utf-8') get_info(s) 出错信息: 505 ~/script/notsobad/python/tool>cat /tmp/book_2742/index.html | ./book_res.py Traceback (most recent call last): File "./book_res.py", line 28, in get_info(s) File "./book_res.py", line 20, in get_info print(a) UnicodeEncodeError: 'ascii' codec can't encode characters in position 79-82: ordinal not in range(128) type(a) 是unicode,但是print a却报错。 最后在python的mail list里找到了篇 http://mail.python.org/pipermail/tutor/2005-August/040991.html http://mail.python.org/pipermail/tutor/2005-August/040993.html ...

January 9, 2010 · notsobad

shell输出多行文本

输出多行文本到文件中去 +239@~> echo " test `whoami` haha ">outfile +239@~> cat outfile test wang haha 但是里面如果出现引号之类的,比较难处理 可以用heredoc: +239@~> cat > outfile < just a test > "`whoami`" > haha'aa > EOF +239@~> cat outfile just a test "wang" haha'aa

January 7, 2010 · notsobad