genesis标注脚本perl源码
- 格式:pdf
- 大小:92.55 KB
- 文档页数:5
Genesis2000脚本命令大全1.switch的用法,注意每一个case必须要以breaksw结尾否则会继续执行下一个case的命令(1)另外,$<的意思是取得使用者的stand input(2)echo若加上-n的选项,则游标会停留在该行最后echo-n"Input one color:"set STOPLIGHT=$<switch($STOPLIGHT)case red:echo"red"breakswcase orange:echo"orange"breakswcase green:echo"green"breakswdefault:echo"you input$STOPLIGHT"endsw--------------------------------------------------------------------2.利用set来取得变数,set ABC="I am ABC"也可以利用`command`来取得命令且外,case也可以用万用字元*来代替set VER=`uname-r`switch($VER)case5.5:echo"run the setup of$VER"breakswcase5.3:echo"run the setup of$VER"breakswcase5.*:echo"like5.x"breakswcase4.*:echo"like4.x"breakswdefault:echo"no idea"endsw--------------------------------------------------------------------3.if的语法,比较数字set n1=1set n2=2if($n1==$n2)thenecho"$n1Equal$n2"elseecho"$n1Not Equal$n2"endif--------------------------------------------------------------------4.if的语法,比较字串set n1=abcdefset n2=abcdeif($n1==$n2)thenecho"$n1Equal$n2"elseecho"$n1Not Equal$n2"--------------------------------------------------------------------5.if的语法,比较相似的字串set n1=abcdefset n2=abcdeif($n1=~$n2)thenecho"$n1Like$n2"elseecho"$n1Not Like$n2"endif--------------------------------------------------------------------6.if的语法,比较数字的大小set n1=1set n2=2if($n1>$n2)thenecho"$n1>$n2"echo"$n1<$n2"endif--------------------------------------------------------------------7.每分钟执行一次的程式#mm等于当天时间的【分钟】数set mm=`date|cut-d''-f4|cut-d:-f2`if(-r$0.out)thenrm$0.outtouch$0.outelsetouch$0.outendifwhile($mm<=16)set mm=`date|cut-d''-f4|cut-d:-f2`echo"$mm now is`date`"sleep60#echo"$mm now is`date`">>$0.outendecho"Over">>$0.out--------------------------------------------------------------------8.一个回圈的范例,并且利用expr去作加的动作回圈的语法如下:foreach number(123)echo$numberendset counter=0while($counter<=10)echo"sleeping for5seconds"sleep5counter=`expr$counter+1`end--------------------------------------------------------------------9.设定一个用当天月份与日期作为档案名称的程式如今天是10/02,则$prefix会等于该程式+1002date.csh1002set prefix=`basename$0``date'+%m%d'`echo$0echo$prefix--------------------------------------------------------------------10.移除在foreach回圈内指定的档案内的font字串foreach file([b,e,g,h,s]*.html)echo-n"Processing$file,remove the line number`grep-n font $file`"#$log表示这个$file有几个font字串set log=`grep-c font$file`if($log=='0')thenecho",pass$file"else#先找出该档案的第一次出现font的行数,如果3,则$cmd=3dset cmd=`grep-n font$file|cut-d:-f1|head-1`d#利用sed去执行删除的动作,并把结果输出到${file}1sed$cmd$file>${file}1#如果${file}1没有资料,则passingif(-z${file}1)thenecho",${file}1is zero"elsecp${file}1$filerm{$file}1echo",$file remove ok"endifendifend#后来看过sed的更进一步用法,发现先前写的太笨了,试试这个#sed/font/d$file>${file}1#一次OK,我真是大笨蛋--------------------------------------------------------------------11.功能:将指定的档案中,出现第一次【回】的那一行,加上<ti tle>xxxx</title>foreach file(sky*.html)set filetitle=ftitle#主要部份为sed部份s/^*//表示将该行第一个字元前的空白删除echo"<title>`grep回$file|head-1|sed-e's/^*//'`</tit le>">$ftitle#将刚刚那一行,再插回去head-1$file>${file}headsed1d$file>${file}1cat$ftitle>>${file}headcat${file}1>>${file}headcp${file}head$filerm${file}1rm$ftitlerm${file}headecho"$file ok"end--------------------------------------------------------------------12.一个实际建立一个ftp server的程式里面包括许多应用,相当有参考价值(未完成)set path=(/usr/bin/usr/sbin)#set true=`grep-c ftp/etc/passwd`if($true==0)thenecho"no ftp user in your system"echo-n"do you want to create the ftp user?"set answer=$<if($answer=='y'||$answer=='Y')thenset maxid=`sort/etc/passwd|tail-1|cut-d:-f3`echo$maxidset newid=`expr$maxid+1`echo$newidecho"/usr/sbin/useradd-d/home1/ftp-u$newid-s/etc/false ftp"endifelseecho"Good.Your system already has the ftp user."set ftphome=`grep ftp:/etc/passwd|cut-d:-f6`echo$ftphomeendifif(-z$ftphome)thenecho"ftphome must be non-null"exit2endifif($ftphome=="/usr"||$ftphome=="/")then echo"ftphome can't be/or/usr"exit2endif#create the ftp home directoryif(!-d$ftphome)thenecho"mkdir$ftphome"endifecho"Setting up the ftphome for SunOS`uname-r`"if(!-d$ftphome)thenecho"mkdir-p$ftphome/usr/bin"endifcp/bin/ls$ftphome/usr/binchmod111$ftphome/usr/bin/lschown root$ftphome/usr/binchmod555$ftphome/usr/binif(-r$ftphome/bin)thenmv-f$ftphome/bin$ftphome/Obinendifln-s usr/bin$ftphome--------------------------------------------------------------------13.取得该使用者的UIDif($#argv==0)thenecho"$0usage:$1username"exit2endifset uid=`grep$1/etc/passwd|cut-d:-f3`echo$uid--------------------------------------------------------------------14.将指定档案内的html取代成htmforeach file(*.html)echo"Processing$file..."sed s/html/htm/$file>${file}1cp${file}1$filerm${file}1end--------------------------------------------------------------------15.一个简简单单的范例,看看就好#!/bin/csh-f echo.................echo WELCOME to\*TAPE COPY\* echo.................echo Enter your name:#$<can read from stand inputset name=$<echo""echo Hi$name\!set D=`date`echo Today\'s date is$D[1]$D[2]$D[3]if($D[1]==Mon)thenecho-------------------------------------------------------------echo Today is$D[1]day$name,it\'s time to copy your director ys\!echo-------------------------------------------------------------elseecho-------------------------------------------------------------echo Today is$D[1]day$name,no tape copies today\!echo-------------------------------------------------------------endif--------------------------------------------------------------------16.一个finger的程式set FINGER="/usr/ucb/finger"if(-x$FINGER)thenif($#argv==0)thencat<<TAG---------------------------------Hahahah....---------------------------------TAGelse$FINGER"$*"endifelseecho"Cannot find finger on this system."endif--------------------------------------------------------------------17.取得变数的方法set W=`who-r`echo$W[9]--------------------------------------------------------------------18.更改档案名称,将*.html-->*.htm#rename*.html to*.htmecho-n"This will change*.html to*.htm.Can I continue?(y/n): "set input=$<if($input!="y"&&$input!="Y")thenecho"Ok.Quit..."exit2endifforeach file(*.html)echo"Processing$file to`basename$file.html`.htm"mv$file`basename$file.html`.htmend--------------------------------------------------------------------19.更改档案名称,将*.htm-->*.htmlecho-n"This will change*.htm to*.html.Can I continue?(y/n): "set input=$<if($input!="y"&&$input!="Y")thenecho"Ok.Quit..."exit2endif#rename*.htm to*.htmlforeach file(*.htm)echo"Processing$file to`basename$file.htm`.html"mv$file`basename$file.htm`.htmlend--------------------------------------------------------------------20.将大写的档名改成小写的档名tr string1string2会将standard input的字串,所对应到的string1,都以string2取代foreach file(*)mv$file`echo$file|tr'[A-Z]''[a-z]'`end--------------------------------------------------------------------21.将小写的档名改成大写的档名foreach file(*)mv$file`echo$file|tr'[a-z]''[A-Z]'`end。
第十章 awk 工具编程 我们在genesis 编程中,awk 工具会经常用到,awk 工具很强大,它不仅可以从一个很大的文本文件中抽取数据包,还可以进行算术运算、比较运算等等很多功能,应该说awk 是一种比较完整的编程语言,本章我们就一一介绍这个较为强大的工具。
刘才林数字签名人 刘才林DN :cn=刘才林,c=CN-中国,o=上海桌凯,ou=工程,email=hillohowareyougo@ 原因:我是该文档的作者日期:2008.07.03 10:07:27 +08'00'10.1:awk简介:awk是一种编程语言,用于在linux/unix下对文本和数据进行处理。
数据可以来自标准输入、一个或多个文件,或其它命令的输出。
它支持用户自定义函数和动态正则表达式等先进功能,是linux/unix下的一个强大编程工具。
它可以在命令行中使用,但更多是作为脚本来使用。
awk的处理文本和数据的方式是这样的,它逐行扫描文件,从第一行到最后一行,寻找匹配的特定模式的行,并在这些行上进行你想要的操作。
如果没有指定处理动作,则把匹配的行显示到标准输出(屏幕),如果没有指定模式,则所有被操作所指定的行都被处理。
awk分别代表其作者姓氏的第一个字母。
因为它的作者是三个人,分别是Alfred Aho、Brian Kernighan、Peter Weinberger。
Awk后来在Linux系统上发展为gawk,在unix系统上发展为nawk,而在genesis2000编程的windows系统中,我们要应用awk95,它们之间也有一些区别,如果你编写的genesis2000程序要应用于多个系统,请注意您的awk程序是否能在各个系统中运行,并且定义不同系统为不同的awk,因为最早的awk很多功能都不能实现。
下面的讲解以gawk为主,但我们简称为awk,请大家不要混淆概念。
10.2:awk命令格式和选项:10.2.1:awk的语法有两种形式:awk [options] 'script' var=value file(s)awk [options] -f scriptfile var=value file(s)10.2.2:awk的常用选项:●–F fs:使用fs作为输入记录的字符分隔符,如果省略该选项,awk使用环境变量IFS的值。
1. switch 的用法,注意每一个case 必须要以breaksw 结尾 否则会继续执行下一个case 的命令(1) 另外,$< 的意思是取得使用者的stand input(2) echo 若加上-n 的选项,则游标会停留在该行最后echo -n "Input one color: "set STOPLIGHT = $<switch ($STOPLIGHT)case red:echo "red"breakswcase orange:echo "orange"breakswcase green:echo "green"breakswdefault:echo "you input $STOPLIGHT"endsw--------------------------------------------------------------------2. 利用set 来取得变数,set ABC = "I am ABC"也可以利用`command` 来取得命令且外,case 也可以用万用字元* 来代替set VER = `uname -r`switch ($VER)case 5.5:echo "run the setup of $VER"breakswcase 5.3:echo "run the setup of $VER"breakswcase 5.*:echo "like 5.x"breakswcase 4.*:echo "like 4.x"breakswdefault:echo "no idea"endsw--------------------------------------------------------------------3. if 的语法,比较数字set n1 = 1set n2 = 2if ($n1 == $n2) thenecho "$n1 Equal $n2"elseecho "$n1 Not Equal $n2"endif--------------------------------------------------------------------4. if 的语法,比较字串set n1 = abcdefset n2 = abcdeif ($n1 == $n2) thenecho "$n1 Equal $n2"elseecho "$n1 Not Equal $n2"endif--------------------------------------------------------------------5. if 的语法,比较相似的字串set n1 = abcdefset n2 = abcdeif ($n1 =~ $n2) thenecho "$n1 Like $n2"elseecho "$n1 Not Like $n2"endif--------------------------------------------------------------------6. if 的语法,比较数字的大小set n1 = 1set n2 = 2if ($n1 > $n2) thenecho "$n1 > $n2"elseendif--------------------------------------------------------------------7. 每分钟执行一次的程式# mm 等于当天时间的【分钟】数set mm = `date | cut -d' ' -f4 | cut -d: -f2`if ( -r $0.out ) thenrm $0.outtouch $0.outelsetouch $0.outendifwhile ( $mm <= 16 )set mm = `date | cut -d' ' -f4 | cut -d: -f2`echo "$mm now is `date`"sleep 60#echo "$mm now is `date`" >> $0.outendecho "Over" >> $0.out--------------------------------------------------------------------8. 一个回圈的范例,并且利用expr 去作加的动作回圈的语法如下:foreach number (1 2 3)echo $numberendset counter = 0while ($counter <= 10)echo "sleeping for 5 seconds"sleep 5counter = `expr $counter + 1 `end--------------------------------------------------------------------9. 设定一个用当天月份与日期作为档案名称的程式如今天是10/02 , 则$prefix 会等于该程式+ 1002set prefix = `basename $0``date '+ %m%d'`echo $0echo $prefix--------------------------------------------------------------------10. 移除在foreach 回圈内指定的档案内的font 字串foreach file ([b,e,g,h,s]*.html)echo -n "Processing $file, remove the line number `grep -n font $file`"# $log 表示这个$file 有几个font 字串set log = `grep -c font $file`if ( $log == '0' ) thenecho ", pass $file"else# 先找出该档案的第一次出现font 的行数,如果3,则$cmd = 3dset cmd = `grep -n font $file | cut -d: -f1 | head -1`d# 利用sed 去执行删除的动作,并把结果输出到${file}1sed $cmd $file > ${file}1# 如果${file}1 没有资料,则passingif ( -z ${file}1 ) thenecho " , ${file}1 is zero"elsecp ${file}1 $filerm {$file}1echo " , $file remove ok"endifendifend# 后来看过sed 的更进一步用法,发现先前写的太笨了,试试这个# sed /font/d $file > ${file}1# 一次OK, 我真是大笨蛋--------------------------------------------------------------------11. 功能:将指定的档案中,出现第一次【回】的那一行,加上<title> xxxx </title>foreach file (sky*.html)set filetitle = ftitle# 主要部份为sed 部份 s/^ *// 表示将该行第一个字元前的空白删除echo "<title>`grep 回$file | head -1 | sed -e 's/^ *//'`</title>" > $ftitle# 将刚刚那一行,再插回去head -1 $file > ${file}headsed 1d $file > ${file}1cat $ftitle >> ${file}headcat ${file}1 >> ${file}headcp ${file}head $filerm ${file}1rm $ftitlerm ${file}headecho "$file ok"end--------------------------------------------------------------------12. 一个实际建立一个ftp server 的程式 里面包括许多应用,相当有参考价值( 未完成)set path = ( /usr/bin /usr/sbin )#set true = `grep -c ftp /etc/passwd`if ( $true == 0 ) thenecho "no ftp user in your system"echo -n "do you want to create the ftp user? "set answer = $<if ($answer == 'y' || $answer == 'Y') thenset maxid = `sort /etc/passwd | tail -1 | cut -d: -f3`echo $maxidset newid = `expr $maxid + 1`echo $newidecho "/usr/sbin/useradd -d /home1/ftp -u $newid -s /etc/false ftp"endifelseecho "Good. Your system already has the ftp user. "set ftphome = `grep ftp: /etc/passwd | cut -d: -f6`echo $ftphomeendifif ( -z $ftphome ) thenecho "ftphome must be non-null"exit 2endifif ( $ftphome == "/usr" || $ftphome == "/" ) thenecho "ftphome can't be / or /usr"exit 2endif# create the ftp home directoryif ( ! -d $ftphome ) thenecho "mkdir $ftphome"endifecho "Setting up the ftphome for SunOS `uname -r`"if ( ! -d $ftphome ) thenecho "mkdir -p $ftphome/usr/bin"endifcp /bin/ls $ftphome/usr/binchmod 111 $ftphome/usr/bin/lschown root $ftphome/usr/binchmod 555 $ftphome/usr/binif ( -r $ftphome/bin ) thenmv -f $ftphome/bin $ftphome/Obinendifln -s usr/bin $ftphome--------------------------------------------------------------------13. 取得该使用者的UIDif ( $#argv == 0 ) thenecho "$0 usage: $1 username"exit 2endifset uid = `grep $1 /etc/passwd | cut -d: -f3`echo $uid--------------------------------------------------------------------14. 将指定档案内的html 取代成htmforeach file ( *.html )echo "Processing $file ..."sed s/html/htm/ $file > ${file}1cp ${file}1 $filerm ${file}1end--------------------------------------------------------------------15. 一个简简单单的范例,看看就好#!/bin/csh -fecho .................echo WELCOME to \* TAPE COPY \*echo .................echo Enter your name:# $< can read from stand inputset name = $<echo " "echo Hi $name \!set D = `date`echo Today\'s date is $D[1] $D[2] $D[3]if ($D[1] == Mon) thenecho -------------------------------------------------------------echo Today is $D[1]day $name, it\'s time to copy your directorys\! echo -------------------------------------------------------------elseecho -------------------------------------------------------------echo Today is $D[1]day $name, no tape copies today\!echo -------------------------------------------------------------endif--------------------------------------------------------------------16. 一个finger 的程式set FINGER = "/usr/ucb/finger"if ( -x $FINGER ) thenif ( $#argv == 0 ) thencat << TAG---------------------------------Hahahah ....---------------------------------TAGelse$FINGER "$*"endifelseecho "Cannot find finger on this system."endif--------------------------------------------------------------------17. 取得变数的方法set W = `who -r`echo $W[9]--------------------------------------------------------------------18. 更改档案名称,将*.html --> *.htm# rename *.html to *.htmecho -n "This will change *.html to *.htm. Can I continue ? (y/n) : " set input = $<if ( $input != "y" && $input != "Y" ) thenecho "Ok. Quit..."exit 2endifforeach file ( *.html )echo "Processing $file to `basename $file .html`.htm "mv $file `basename $file .html`.htmend--------------------------------------------------------------------19. 更改档案名称,将*.htm --> *.htmlecho -n "This will change *.htm to *.html. Can I continue ? (y/n) : " set input = $<if ( $input != "y" && $input != "Y" ) thenecho "Ok. Quit..."exit 2endif# rename *.htm to *.htmlforeach file ( *.htm )echo "Processing $file to `basename $file .htm`.html " mv $file `basename $file .htm`.htmlend--------------------------------------------------------------------20. 将大写的档名改成小写的档名tr string1 string2 会将standard input 的字串,所对应到的string1, 都以string2 取代foreach file ( * )mv $file `echo $file | tr '[A-Z]' '[a-z]'`end--------------------------------------------------------------------21. 将小写的档名改成大写的档名foreach file (*)mv $file `echo $file | tr '[a-z]' '[A-Z]'`end</P< p>。
一perl是什么?二perl在哪里?三运行四注释一、Perl是什么?Perl是Practical Extraction and Report Language的缩写,它是由Larry Wall设计的,并由他不断更新和维护,用于在UNIX环境下编程。
.Perl具有高级语言(如C)的强大能力和灵活性。
事实上,你将看到,它的许多特性是从C语言中借用来的。
.与脚本语言一样,Perl不需要编译器和链接器来运行代码,你要做的只是写出程序并告诉Perl来运行而已。
这意味着Perl对于小的编程问题的快速解决方案和为大型事件创建原型来测试潜在的解决方案是十分理想的。
.Perl提供脚本语言(如sed和awk)的所有功能,还具有它们所不具备的很多功能。
Perl还支持sed到Perl及awd到Perl的翻译器。
简而言之,Perl象C一样强大,象awk、sed等脚本描述语言一样方便。
二、Perl在哪里?Perl通常位于/usr/local/bin/perl或/usr/bin/perl中。
你可以在Internet用匿名FTP 免费得到它,如{{ftp:///pub/gnu/perl-5.004.tar.gz}}。
安装过程为:(1)解压:$gunzip perl-5.004.tar.gz$tar xvf - <perl-5.004.tar.gz(2)编译:$make makefile(3)放置:将编译生成的可执行文件拷贝到可执行文件通常所在目录,如:$copy <compiled excutable file> /usr/local/bin/perl注:这需要系统管理员权限。
三、运行用文本编辑器编辑好你的Perl程序,加上可执行属性:$chmod +x <program>就可以执行了:$./<program>。
如果系统提示:"/usr/local/bin/perl not found",则说明你没有安装成功,请重新安装。
genesis脚本实施方案Genesis脚本实施方案为了更好地实施Genesis脚本,我们需要制定一个详细的实施方案,以确保项目顺利进行并取得成功。
本文档将详细介绍Genesis脚本的实施方案,包括目标、步骤和关键注意事项。
1. 目标我们实施Genesis脚本的主要目标是提高系统的效率和稳定性,减少手动操作,降低人为错误的发生率。
通过Genesis脚本的实施,我们希望能够实现自动化部署、监控和故障排除,提高系统的可靠性和安全性。
2. 实施步骤(1)需求分析:首先,我们需要对系统的需求进行分析,确定Genesis脚本的具体功能和实施范围。
在这一阶段,我们需要与相关部门和人员充分沟通,了解他们的需求和期望,以便为实施方案的制定提供参考。
(2)技术评估:在确定了需求后,我们需要对系统的技术架构和环境进行评估,确保Genesis脚本可以与现有系统无缝集成。
同时,我们还需要评估团队的技术能力和资源情况,确保实施过程中能够得到充分的支持和配合。
(3)制定计划:在完成需求分析和技术评估后,我们需要制定详细的实施计划,包括时间安排、人员配置、风险评估和质量控制等方面。
在制定计划时,我们需要充分考虑各种可能的情况,确保实施过程中能够及时调整和应对。
(4)实施和测试:实施阶段是Genesis脚本实施方案的关键阶段,我们需要按照计划逐步推进,确保每个环节都得到充分的测试和验证。
在实施过程中,我们需要严格遵循规范和流程,确保系统的稳定性和安全性。
(5)培训和支持:在完成实施后,我们需要对相关人员进行培训,确保他们能够熟练操作和维护Genesis脚本。
同时,我们还需要提供充分的支持和帮助,确保系统能够稳定运行并发挥最大的效益。
3. 关键注意事项在实施Genesis脚本的过程中,我们需要特别注意以下几个方面:(1)风险管理:实施过程中可能会出现各种风险,我们需要及时评估和应对,确保项目不受影响。
(2)沟通协调:实施过程需要各个部门和人员的密切配合,我们需要加强沟通和协调,确保项目顺利进行。