一个专注于技术的IT男
Unix/Linux
用户的输入总是很有创意的
六 24th
有时候看似天衣无缝的代码遇到极具创意的用户是不得不低头的
且看下面一段简单的shell代码,检查用户输入如果是合法的文件,然后做一个copy
-r 测试文件存在且可读
-d 检测是否是目录
如果文件存在且可读而且不是目录,(这里不关心文件内容),那么这个输入是否合法呢?
#!/bin/sh echo "Enter the name of the new licence key file" echo "licencekeyfile=\c" read _afile if [ ! -r $_afile ] then echo "File does not exist" exit 1 fi if [ -d $_afile ] then echo "Licence key file must be a regular file" exit 1 fi #Copy new licenceKey to /var/sog/etc/.licenses/licenseKey if [ "$_afile" != "/var/sog/etc/.licenses/licenseKey" ] then cp $_afile /var/sog/etc/.licenses/licenseKey fi ...
用户如何break这个貌似天衣无缝的条件检测的?
Enter the name of the new licence key file licencekeyfile=/home/user/.licenses/lic*
如果 /home/user/.licenses/lic* 匹配多个文件的情况下,-r 和 -d 判断都能通过,接下来运行到cp 就杯具了
会报下面这个错:
cp: Target /var/sog/etc/.licenses/licenseKey must be a directory Usage: cp [-f] [-i] [-p] [-@] f1 f2 cp [-f] [-i] [-p] [-@] f1 ... fn d1 cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn
真的佩服用户输入的创意啊,为了避免匹配多个文件的情况,不得不用下面的代码来修bug
matches=`ls $_afile | wc -l | sed 's/ //g'` if [ $matches != 1 ] then echo "Your input of the new licence key file is not valid, it matches $matches files :" ls $_afile exit 1 fi
[高手必备]-screen
十二 22nd
自诩为一个Geek,一个高手,不知道screen是啥有点说不过去。。。
好歹现在开发和维护的产品也是运行在强大的Solaris上的,我还一直很土的用putty建多个连接到server上去看这看那,自鸣得意的把putty拖成几个方块,不同的窗口不同的功能,有的看日志,有的杀进程,有的检查coredump文件,无奈windows的DHCP导致PC机的IP总是在第二天上班的时候变了,可怜了我苦心建立起来的多个session,又得吭哧吭哧再连一遍,效率啊。。。
好歹咱也是学过《卓有成效的程序员》的人,于是决定不能再这么土下去了,终于决定走上正途,用screen
使用screen开始一个会话
screen
在screen会话中开启一个新的窗口
连续技: Ctrl+a c
查看当前会话中的窗口列表
连续技: Ctrl+a w
暂时退出当前会话
连续技: Ctrl+a d
| ~ ~ “tmp.txt” [New file] [detached] 1372# |
查看之前的screen会话
screen -list
| 1372# screen -list There is a screen on: 25618.pts-1.ema1372 (Detached) 1 Socket in /tmp/screens/S-root. |
删除无法连接的screen会话
screen -wipe
| 1372# screen -wipe There is a screen on: 25618.pts-1.ema1372 (Detached) 1 Socket in /tmp/screens/S-root. |
重现连接之前的会话
screen -r 25618
| 1372# screen -r 25618Ctrl+a w ~ 0-$ sh 1*$ sh |
重命名会话中的窗口
连续技: Ctrl+a A
| Set window’s title to: new_title |
连续技: Ctrl+a ?
如何保证sh脚本只有一个进程在运行
三 18th
#!/usr/bin/sh
LOCKFILE=jihao.lock
if [ -f ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
echo "filecollector is already running"
exit
fi
# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}
sleep 100
rm -f ${LOCKFILE}
ubuntu安装mplayer遇到的一些问题及解决办法
二 12th
关于ubuntu安装mplayer网上已经有很多的文章,我也装的时候也参照了一下下面两个链接。这篇文章主要是为了记录我安装的时候遇到的问题及解决办法。
http://linux.chinaunix.net/docs/2008-01-24/4725.shtml http://tech.ccidnet.com/art/3089/20090106/1652395_1.html
安装有五个步骤,我下载了Subversion snapshot的源文件,以及其他几个文件之后,
drwxr-xr-x 2 root root 4096 2009-02-11 23:22 codecs
drwxr-xr-x 2 root root 4096 2007-10-07 22:07 wincodecs
Check “configure.log” if you do not understand why it failed.
解决办法: google了一下发现我需要libavcodec这个东东,但是在我检查了一下明明以及装过了的,同时发现还有下面这个包没有装过,看了一下这个包的说明,猜想了一下觉得应该把它装上,这里要说的说ubuntu真的很方便,这个(Synaptic Package Manager) 新立得包管理器简直就是一个神器啊!在Synaptic Package Manager里选中这个包,它会把depend的其他包都自动下载安装,爽死了。
libavcodec-dev
development files for libavcodec
This is the codec library from the ffmpeg project. It supports most existing
encoding formats (MPEG, DivX, MPEG4, AC3, DV…).
This package contains the header files and static libraries needed to
compile applications or shared objects that use libavcodec.
Check “configure.log” if you do not understand why it failed.
解决办法: 继续google发现这次的解决办法是要安装下面两个包,还是用Synaptic Package Manager
libgladeui-1-7
GTK+ User Interface Build core library
libgladeui-1-dev
GTK+ User Interface Build core library (development files)
Glade is a RAD tool to enable quick and easy development of user
interfaces for the GTK+ 2 toolkit.
Glade is, since its “3.0″ major version, highly modular, and composed
of widgets which can be used by other applications to integrate
functionality similar to the one provided by the Glade application
itself.
hao@hao-desktop:~/downloaded/mplayer-export-2009-02-11$ sudo make install
[sudo] password for hao:
install -d /usr/local/mplayer//bin /usr/local/mplayer//etc/mplayer /usr/local/mplayer//lib
install -m 755 -s mplayer /usr/local/mplayer//bin
ln -sf mplayer /usr/local/mplayer//bin/gmplayer
install -d /usr/local/mplayer//share/mplayer/skins /usr/local/mplayer//share/pixmaps /usr/local/mplayer//share/applications
install -m 644 etc/mplayer.xpm /usr/local/mplayer//share/pixmaps/
install -m 644 etc/mplayer.desktop /usr/local/mplayer//share/applications/
install -m 755 -s mencoder /usr/local/mplayer//bin
install -d /usr/local/mplayer//share/man/zh_CN/man1
install -m 644 DOCS/man/zh_CN/mplayer.1 /usr/local/mplayer//share/man/zh_CN/man1/
cd /usr/local/mplayer//share/man/zh_CN/man1 && ln -sf mplayer.1 mencoder.1
hao@hao-desktop:~/downloaded/mplayer-export-2009-02-11$
最后还需要安装字体和皮肤,很简单的活,没遇到问题。
Q:ubuntu如何安装deb格式的包?