那么如何应用q些命o提高效率呢?下面我D一个例子,如何利用fttpq行后台下蝲Q假设你的ISPl你提供了shellq且可以用nohupQ你想由fttp.download.com/pub/internet/ 下蝲一?0M的程序aaa.zip具体步骤如下Q?
1.用notepad做一个文件如aaa1内容如下
open ftp.dwonload.com
user anonymous zyz@cenpok.net
cd /pub/internet/
i
get aaa.zip
close
bye
2.拨号dC的ISP上。用telnet 或nettermd到shellQ一般都在你的home子目录里bbs?
3.用fttp上传aaa1到ISP服务器你的子目录?
4. 执行nohup fttp Qinvd aaa2Q?
q样q个q程p攑֜ISP服务器的后台q行了,如果你想知道情况如何Q可以more aaa2可以知道情况如何了。这时你可以断线了或q点别的Q估计时间到?timeU?30M/(33.6K/9)s)拨号上去Qmore aaa2如果昄成功下蝲aaa.zippC?aaa.zip已经被下载到ISP的服务器上了Q你再由ISP的服务器拉回来就相当与点对点?记得下蝲完成后del掉你的文?aaa.zip)Q免得浪费ISP资源Q它会关掉shell?
]]>【linux脚本】bad interpreter: No such file or directoryhttp://www.tkk7.com/Javawind/archive/2007/08/30/141493.htmlkooyeekooyeeThu, 30 Aug 2007 11:14:00 GMThttp://www.tkk7.com/Javawind/archive/2007/08/30/141493.htmlhttp://www.tkk7.com/Javawind/comments/141493.htmlhttp://www.tkk7.com/Javawind/archive/2007/08/30/141493.html#Feedback0http://www.tkk7.com/Javawind/comments/commentRss/141493.htmlhttp://www.tkk7.com/Javawind/services/trackbacks/141493.html一般来_在windows用徏立的sh文g在linux中运行时Q因为window在每行后加入隐藏字符^M 所以当linux~译?׃无法~译^M而导致bad interpreter错误
1.1.3 变量 在其他编E语a中您必须使用变量。在shell~程中,所有的变量都由字符串组成,q且您不需要对变量 q行声明。要赋值给一个变量,您可以这样写Q? #!/bin/sh #对变量赋| a="hello world" # 现在打印变量a的内容: echo "A is:" echo $a 有时候变量名很容易与其他文字hQ比如: num=2 echo "this is the $numnd" qƈ不会打印?this is the 2nd"Q而仅仅打?this is the "Q因为shell会去搜烦变量numnd的| 但是q个变量时没有值的。可以用花括号来告诉shell我们要打印的是num变量Q? num=2 echo "this is the ${num}nd" q将打印Q?this is the 2nd
case :表达式可以用来匹配一个给定的字符Ԍ而不是数字? case ... in ...) do something here ;; esac 让我们看一个例子?file命o可以辨别Z个给定文件的文gcdQ比如: file lf.gz q将q回Q? lf.gz: gzip compressed data, deflated, original filename, last modified: Mon Aug 27 23:09:18 2001, os: Unix 我们利用q一点写了一个叫做smartzip的脚本,该脚本可以自动解压bzip2, gzip 和zip cd的压~文Ӟ #!/bin/sh ftype=`file "$1"` case "$ftype" in "$1: Zip archive"*) unzip "$1" ;; "$1: gzip compressed"*) gunzip "$1" ;; "$1: bzip2 compressed"*) bunzip2 "$1" ;; *) echo "File $1 can not be uncompressed with smartzip";; esac 您可能注意到我们在这里用了一个特D的变量$1。该变量包含了传递给该程序的W一个参数倹{?br>也就是说Q当我们q行Q? smartzip articles.zip $1 是字符?articles.zip
3. selsect select 表达式是一Ubash的扩展应用,其擅长于交互式使用。用户可以从一l不同的gq行选择? select var in ... ; do break done .... now $var can be used .... 下面是一个例子: #!/bin/sh echo "What is your favourite OS?" select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do break done echo "You have selected $var" 下面是该脚本q行的结果: What is your favourite OS? 1) Linux 2) Gnu Hurd 3) Free BSD 4) Other #? 1 You have selected Linux
4.loop
loop表达式: while ...; do .... done while-loop 运行直到表辑ּ试为真。will run while the expression that we test for is true. 关键?break" 用来跛_循环。而关键字”continue”用来不执行余下的部分而直接蟩C一个@环?
for-loop表达式查看一个字W串列表 (字符串用I格分隔) 然后其赋给一个变量: for var in ....; do .... done 在下面的例子中,分别打印ABC到屏q上Q? #!/bin/sh for var in A B C ; do echo "var is $var" done 下面是一个更为有用的脚本showrpmQ其功能是打C些RPM包的l计信息Q? #!/bin/sh # list a content summary of a number of RPM packages # USAGE: showrpm rpmfile1 rpmfile2 ... # EXAMPLE: showrpm /cdrom/RedHat/RPMS/*.rpm for rpmpackage in $*; do if [ -r "$rpmpackage" ];then echo "=============== $rpmpackage ==============" rpm -qi -p $rpmpackage else echo "ERROR: cannot read file $rpmpackage" fi done q里出现了第二个Ҏ的变?*Q该变量包含了所有输入的命o行参数倹{?br>如果您运行showrpm openssh.rpm w3m.rpm webgrep.rpm 此时 $* 包含?3 个字W串Q即openssh.rpm, w3m.rpm and webgrep.rpm.
6. Here documents -- 我们的技术是你的Q?a target=_blank>www.icwin.net
当要几行文字传递给一个命令时Qhere documentsQ译者注Q目前还没有见到q对该词适合的翻译) 一U不错的Ҏ。对每个脚本写一D帮助性的文字是很有用的,此时如果我们四有那个 here documents ׃必用echo函数一行行输出?一?"Here document" ?<< 开_后面接上一个字W串Q这个字W串 q必d现在here document的末。下面是一个例子,在该例子中,我们对多个文件进行重命名Qƈ?br>使用here documents打印帮助Q? #!/bin/sh # we have less than 3 arguments. Print the help text: if [ $# -lt 3 ] ; then cat < ren -- renames a number of files using sed regular expressions USAGE: ren 'regexp' 'replacement' files... EXAMPLE: rename all *.HTM files in *.html: ren 'HTM$' 'html' *.HTM HELP exit 0 fi OLD="$1" NEW="$2" # The shift command removes one argument from the list of # command line arguments. shift shift # $* contains now all the files: for file in $*; do if [ -f "$file" ] ; then newfile=`echo "$file" | sed "s/${OLD}/${NEW}/g"` if [ -f "$newfile" ]; then echo "ERROR: $newfile exists already" else echo "renaming $file to $newfile ..." mv "$file" "$newfile" fi fi done q是一个复杂一些的例子。让我们详细讨论一下。第一个if表达式判断输入命令行参数?br>否小??(Ҏ变量$# 表示包含参数的个? 。如果输入参数小?个,则将帮助文字传?br>lcat命oQ然后由cat命o其打印在屏q上。打印帮助文字后E序退出?如果输入参数{?br>于或大于3个,我们将W一个参数赋值给变量OLDQ第二个参数赋值给变量NEW。下一步,?br>们用shift命o第一个和W二个参C 参数列表中删除,q样原来的第三个参数成为参 数列?*的第一个参数。然后我们开始@环,命o行参数列表被一个接一个地被赋值给变量$file?br>接着?们判断该文g是否存在Q如果存在则通过sed命o搜烦和替换来产生新的文g名。然?br>反短斜U内命ol果赋值给newfile。这h们就辑ֈ了我们的?的:得到了旧文g名和?br>文g名。然后用mv命oq行重命名? 4)函数 如果您写了一些稍微复杂一些的E序Q您׃发现在程序中可能在几个地方用了相同的代码, q且您也会发玎ͼ如果我们使用了函敎ͼ会方便很多。一个函数是q个样子的: functionname() { # inside the body $1 is the first argument given to the function # $2 the second ... body } 您需要在每个E序的开始对函数q行声明?
下面是一个叫做xtitlebar的脚本,使用q个脚本您可以改变终端窗口的名称?br>q里使用了一个叫做help的函数。正如您可以看到的那Pq个定义的函数被使用了两ơ? #!/bin/sh # vim: set sw=4 ts=4 et: help() { cat < xtitlebar -- change the name of an xterm, gnome-terminal or kde konsole USAGE: xtitlebar [-h] "string_for_titelbar" OPTIONS: -h help text EXAMPLE: xtitlebar "cvs" HELP exit 0 } # in case of error or if -h is given we call the function help: [ -z "$1" ] && help [ "$1" = "-h" ] && help # send the escape sequence to change the xterm titelbar: echo -e "33]0;$107" #
在脚本中提供帮助是一U很好的~程习惯Q这h便其他用P和您Q用和理解脚本? 命o行参? 我们已经见过$* ?$1, $2 ... $9 {特D变量,q些Ҏ变量包含了用户从命o 行输入的参数。迄今ؓ止,我们仅仅了解了一些简单的命o行语法(比如一些强制性的 参数和查看帮助的-h选项Q?但是在编写更复杂的程序时Q您可能会发现您需要更多的 自定义的选项。通常的惯例是在所有可选的参数之前加一个减P后面再加上参数?( 比如文g?? 有好多方法可以实现对输入参数的分析,但是下面的用case表达式的例子无遗是一个不错的Ҏ? #!/bin/sh help() { cat < This is a generic command line parser demo. USAGE EXAMPLE: cmdparser -l hello -f -- -somefile1 somefile2 HELP exit 0 } while [ -n "$1" ]; do case $1 in -h) help;shift 1;; # function help is called -f) opt_f=1;shift 1;; # variable opt_f is set -l) opt_l=$2;shift 2;; # -l takes an argument -> shift by 2 --) shift;break;; # end of options -*) echo "error: no such option $1. -h for help";exit 1;; *) break;; esac done
echo "opt_f is $opt_f" echo "opt_l is $opt_l" echo "first arg is $1" echo "2nd arg is $2" 您可以这栯行该脚本Q? cmdparser -l hello -f -- -somefile1 somefile2 q回的结果是Q? opt_f is 1 opt_l is hello first arg is -somefile1 2nd arg is somefile2 q个脚本是如何工作的呢?脚本首先在所有输入命令行参数中进行@环,输入参?br>与case表达式进行比较,如果匚w则设|一个变量ƈ且移除该参数。根据unixpȝ的惯例, 首先输入的应该是包含减号的参? W?部分 实例 现在我们来讨论编写一个脚本的一般步骤。Q何优U的脚本都应该h帮助和输入参数。ƈ且写一个伪脚本Qframework.shQ,该脚本包含了大多数脚本都需要的框架l构Q是一个非怸错的L。这时候,在写一个新的脚本时我们只需要执行一下copy命oQ? cp framework.sh myscript 然后再插入自q函数? 让我们再看两个例子: 二进制到十进制的转换 脚本 b2d 二q制?(比如 1101) 转换为相应的十进制数。这也是一个用expr命oq行数学q算的例子: #!/bin/sh # vim: set sw=4 ts=4 et: help() { cat < b2h -- convert binary to decimal USAGE: b2h [-h] binarynum OPTIONS: -h help text EXAMPLE: b2h 111010 will return 58 HELP exit 0 } error() { # print an error and exit echo "$1" exit 1 } lastchar() { # return the last character of a string in $rval if [ -z "$1" ]; then # empty string rval="" return fi # wc puts some space behind the output this is why we need sed: numofchar=`echo -n "$1" | wc -c | sed 's/ //g' ` # now cut out the last char rval=`echo -n "$1" | cut -b $numofchar` }
chop() { # remove the last character in string and return it in $rval if [ -z "$1" ]; then # empty string rval="" return fi # wc puts some space behind the output this is why we need sed: numofchar=`echo -n "$1" | wc -c | sed 's/ //g' ` if [ "$numofchar" = "1" ]; then # only one char in string rval="" return fi numofcharminus1=`expr $numofchar "-" 1` # now cut all but the last char: rval=`echo -n "$1" | cut -b 0-${numofcharminus1}` } while [ -n "$1" ]; do case $1 in -h) help;shift 1;; # function help is called --) shift;break;; # end of options -*) error "error: no such option $1. -h for help";; *) break;; esac done # The main program sum=0 weight=1 # one arg must be given: [ -z "$1" ] && help binnum="$1" binnumorig="$1"
while [ -n "$binnum" ]; do lastchar "$binnum" if [ "$rval" = "1" ]; then sum=`expr "$weight" "+" "$sum"` fi # remove the last position in $binnum chop "$binnum" binnum="$rval" weight=`expr "$weight" "*" 2` done echo "binary $binnumorig is decimal $sum" 该脚本用的法是利用十q制和二q制数权?(1,2,4,8,16,..)Q比如二q制"10"?br>以这栯{换成十进Ӟ 0 * 1 + 1 * 2 = 2 Z得到单个的二q制数我们是用了lastchar 函数。该函数使用wc –c计算字符个数Q?br>然后使用cut命o取出末尾一个字W。Chop函数的功能则是移除最后一个字W?
文g循环E序 或许您是惛_所有发出的邮g保存C个文件中的h们中的一员,但是在过了几个月 以后Q这个文件可能会变得很大以至于对该文g的访问速度变慢。下面的 脚本rotatefile 可以解决q个问题。这个脚本可以重命名邮g保存文gQ假设ؓoutmailQؓoutmail.1Q?br>而对于outmail.1变成了outmail.2 {等{等... #!/bin/sh # vim: set sw=4 ts=4 et: ver="0.1" help() { cat < rotatefile -- rotate the file name
USAGE: rotatefile [-h] filename
OPTIONS: -h help text EXAMPLE: rotatefile out This will e.g rename out.2 to out.3, out.1 to out.2, out to out.1 and create an empty out-file The max number is 10 version $ver HELP exit 0 }
error() { echo "$1" exit 1 } while [ -n "$1" ]; do case $1 in -h) help;shift 1;; --) break;; -*) echo "error: no such option $1. -h for help";exit 1;; *) break;; esac done # input check: if [ -z "$1" ] ; then error "ERROR: you must specify a file, use -h for help" fi filen="$1" # rename any .1 , .2 etc file: for n in 9 8 7 6 5 4 3 2 1; do if [ -f "$filen.$n" ]; then p=`expr $n + 1` echo "mv $filen.$n $filen.$p" mv $filen.$n $filen.$p fi done # rename the original file: if [ -f "$filen" ]; then echo "mv $filen $filen.1" mv $filen $filen.1 fi echo touch $filen touch $filen q个脚本是如何工作的呢?在检用h供了一个文件名以后Q我们进行一??的@环。文?被命名ؓ10Q文?重命名ؓ9{等。@环完成之后,我们原始文件命名ؓ文g1同时建立一个与原始文g同名的空文g? 调试 //--------------------------------------- //-- www.icwin.net //--------------------------------------- 最单的调试命o当然是用echo命o。您可以使用echo在Q何怀疑出错的地方打印M变量倹{这也是l大多数的shellE序员要p80%的时间来调试E序的原因。ShellE序的好处在于不需要重新编译,插入一个echo命o也不需要多时间? shell也有一个真实的调试模式。如果在脚本"strangescript" 中有错误Q您可以q样来进行调试: sh -x strangescript q将执行该脚本ƈ昄所有变量的倹{? shellq有一个不需要执行脚本只是检查语法的模式。可以这样用: sh -n your_script q将q回所有语法错误?
]]>【Y件安装】Installing the Java Software Developers Kit Version (SDK) 1.4: http://www.tkk7.com/Javawind/archive/2007/08/29/141119.htmlkooyeekooyeeWed, 29 Aug 2007 14:51:00 GMThttp://www.tkk7.com/Javawind/archive/2007/08/29/141119.htmlhttp://www.tkk7.com/Javawind/comments/141119.htmlhttp://www.tkk7.com/Javawind/archive/2007/08/29/141119.html#Feedback0http://www.tkk7.com/Javawind/comments/commentRss/141119.htmlhttp://www.tkk7.com/Javawind/services/trackbacks/141119.html
Installing the Java Software Developers Kit Version (SDK) 1.4:
chmod +x j2sdk-1_4_0_03-linux-i586-rpm.bin
./j2sdk-1_4_0_03-linux-i586-rpm.bin
...
This is where you agree to their license. Press the space bar to scroll down in "More".
Do you agree the the above license terms? [yes or no]
yes
...
rpm -ivh j2sdk-1_4_0_03-fcs-linux-i586.rpm
The SDK installed in /usr/java/j2sdk1.4.0_03/
Set environment variables. (Add to $HOME/.bash_profile)
Must include "./" in CLASSPATH. This is necessary in 1.4.0_03.
Test program: Test.java
public class Test
{
public static void main(String[] args)
{
System.out.println("Hello world");
}
}
Compile: javac Test.java
(or /usr/java/j2sdk1.4.0/bin/javac Test.java) Note that the file name and the class name are the same. This became a requirement in SDK 1.4. The result of the compile is the file: Test.class
Run:
[prompt]$ java Test
Hello world
(or /usr/java/j2sdk1.4.0/bin/java Test)
[Potential Pitfall]: Red Hat Enterprise Linux and other Linus systems which install GNU Java may find that this conflicts with the Sun Java installation. You may have to remove this (for example RHEL4): rpm -e java-1.4.2-gcj-compat-1.4.2.0-27jpp java-1.4.2-gcj-compat-devel-1.4.2.0-27jpp.noarch
The Java SDK includes the following commands:
javac: Linux Java compiler (i.e. javac program-name.java)
java: Byte code interpreter / Java program launcher. (i.e. java program-name Do not include ".class" extension.) Test version: java -version
appletviewer: Views Java applet embedded in html file. (appletviewer myfile.html)