很实用的Shell脚本(实践版)
shell脚本案例

shell脚本案例Shell脚本是将一系列的命令写入脚本文件中,让其运行时具备特定的功能。
Shell脚本的一大优势是可以实现一步操作多项任务,在繁重的日常任务管理与网络管理领域中都有着广泛的应用。
本文将着重介绍几个常见的Shell脚本案例,让读者了解有关Shell脚本的实际操作方法。
第一个脚本是批量更改文件所有者及所有组的脚本,代码如下: #!/bin/bashfiles=`ls -A`user=usernamegroup=groupnamefor file in $files; dochown $user:$group $filedone这个脚本首先列出当前工作目录下的文件,并将所有者及所有组设置为指定的两个用户,最后应用chown命令将文件的所有者和所有组都更改为给定的用户及组。
第二个脚本是用来实现文件/文件夹的备份的脚本,代码如下: #! /bin/bashsrcdir=/srcdirbackdir=/backdirmkdir -p $backdircp -R $srcdir/* $backdir这个脚本将指定的源文件夹srcdir的所有内容复制到一个备份文件夹backdir中,确保原文件的完整性。
第三个脚本是用来批量修改文件权限的,代码如下:#! /bin/bashfiles=`ls -A`for file in $files; dochmod -R 755 $filedone这个脚本将当前工作目录下的所有文件/文件夹的可读写权限设置为755,755权限可让所有者及同一组用户可以具有执行及读写权限,而其他用户只有可以读取权限。
以上三个案例展示了Shell脚本的强大功能,能够帮助用户快速完成一系列的工作,避免执行重复的操作,非常适合用作日常任务的自动化管理。
Shell脚本操作简单,编写起来也比较简单,学习它也并不困难,只要用户掌握一定的shell基础知识就可以编写出非常强大的脚本文件。
此外,Shell脚本还可以通过cron计划任务实现定时执行操作,能够有效的节省用户的时间。
30个关于Shell脚本的经典案例(下)

初次使用你要注意这几点:
脚本位置参数会与optstring中的单个字母逐个匹配,如果匹配到就赋值给name,否则赋值name为问号;
optstring中单个字母是一个选项,如果字母后面加冒号,表示该选项后面带参数,参数值并会赋冒号,表示屏蔽系统错误(test.sh: illegal option -- h);
允许把选项放一起,例如-ab
下面写一个打印文件指定行的简单例子,引导你思路:
#!/bin/bash
while getopts :f:n: option; do
case $option in
f)
FILE=$OPTARG
[ ! -f $FILE ] && echo "$FILE File not exist!" && exit
\"(yes/no)\" {send \"yes\r\"; exp_continue} \"password:\" {send \"$PASS\r\"; exp_continue} \"$USER@*\" {send \"df -h\r exit\r\"; exp_continue} }" 方法3:将expect脚本独立出来
Linux shell编程实验作业(含答案)

Linux shell实验作业参考1.编写一个Shell脚本,实现输入一个数字,输出该数字的阶乘。
思路:使用for循环,从1到输入的数字进行累乘,最终输出结果。
#!/bin/bashecho "请输入一个数字:"read numfact=1for ((i=1;i<=$num;i++))dofact=$(($fact*$i))doneecho "阶乘为:$fact"2. 编写一个Shell脚本,实现输入一个目录,输出该目录下所有文件名和文件大小。
#!/bin/bash# 获取目录路径read -p "请输入目录路径:" dir_path# 判断目录是否存在if [ ! -d "$dir_path" ]; thenecho "目录不存在!"exit 1fi# 遍历目录下所有文件for file in "$dir_path"/*do# 判断是否是文件if [ -f "$file" ]; then# 获取文件名和大小file_name=$(basename "$file")file_size=$(du -h "$file" | awk '{print $1}')echo "$file_name : $file_size"fidone使用方法:➢将以上代码保存为一个.sh文件,例如:`list_files.sh`➢给该文件添加执行权限:`chmod +x list_files.sh`➢在终端中运行该脚本:`./list_files.sh`,然后输入目录路径即可。
3. 编写一个Shell脚本,实现输入一个字符串,输出该字符串中所有大写字母的个数。
脚本的基本思路是遍历输入的字符串,对于每个字符,判断是否为大写字母,如果是则计数器加一。
编写高效的Shell脚本的技巧与实例

编写高效的Shell脚本的技巧与实例引言:Shell脚本是自动化执行一系列命令的脚本语言,它在操作系统中扮演着重要的角色。
编写高效的Shell脚本可以提高工作效率和生产力。
本文将介绍一些编写高效Shell脚本的技巧,并提供一些实例来加深理解。
一、选择合适的Shell解释器Shell脚本可以使用多种Shell解释器,如Bash、Zsh、Csh等。
选择合适的Shell解释器可以根据实际需求和环境来进行,一般来说,Bash是使用最广泛的Shell解释器。
二、规范命名和注释命名和注释是编写可读性强的Shell脚本的基础。
为了提高可读性,应使用有意义的变量名、函数名和文件名,并在需要的地方添加注释,以便其他人能够更容易地理解脚本的用途和实现方式。
三、使用合适的命令和参数Shell脚本可以调用系统中的各种命令,为了编写高效的脚本,应使用合适的命令和参数。
例如,对于文件操作,应使用适当的命令,如cp、mv和rm,而不是使用比如cat和grep来实现类似的功能。
四、使用变量和函数变量和函数是Shell脚本中非常重要的组成部分,它们可以帮助提高脚本的可维护性和可扩展性。
合理使用变量和函数可以使脚本更加灵活,易于调试和修改。
实例1:计算文件行数#!/bin/bashfile="/path/to/file.txt"lines=$(wc -l < $file)echo "文件 $file 的行数为 $lines"实例2:批量重命名文件#!/bin/bashprefix="new_"for file in /path/to/files/*; doif [ -f "$file" ]; thennew_name=${file##*/}new_name="$prefix$new_name"mv "$file" "/path/to/files/$new_name"fidone五、合理使用循环和条件语句循环和条件语句在Shell脚本中起着重要的作用。
【学习】LinuxShell脚本实例之一

【学习】LinuxShell脚本实例之⼀1.程序流程控制实例程序流程控制,实际上就是改变程序的执⾏顺序。
程序在执⾏过程中若流程被改变,就可能导致输出不同,因此利⽤这⼀特性就能够实现程序执⾏结果的控制。
程序流程控制可分为“选择”和“循环”这两类,在需要根据实际需求的不同实现不同的输出时,就可以改变程序的执⾏流程。
(1)for循环语句基于for语句的循环,基于继续执⾏循环或者结束循环的⽅式。
在for执⾏命令前,其会先检查所要执⾏的列表中所指定的值是否还有未使⽤的,若有未使⽤的就赋值并执⾏列表,直到列表中的值全部都使⽤过后才退出循环。
如下是⼀个简单的 for 控制语句的脚本程序,其使⽤“星期”作为变量名,并从列表中读取值,直到读取完成后退出。
我们执⾏⼀下说明:第03 ⾏,所定义的变量名为week,其值为Monday~ Sunday。
第05⾏,使⽤echo回显变量week的值。
(2)while循环语句while循环语句结构是⼀种执⾏⼀系列命令的语句结构,它所执⾏的命令由测试条件所决定,这些条件定义语句是否继续执⾏。
在 while 循环语句中执⾏命令,若条件为真,则将过程执⾏⼀遍并回到开始处,接着再次进⾏条件的判断,若条件仍然是真,则接着再执⾏⼀遍,直到条件为假时才退出循环。
如下是⼀个数值运算的while循环脚本,其实现的是数值相加运算。
执⾏⼀下看⼀下结果说明:第03和04⾏,声明x和sum都为整型变量并赋予初始值。
第05⾏,条件测试。
第06~09⾏,这是⼀个循环体,当执⾏遇到done后,跳到第06⾏处继续执⾏,直到条件不满⾜时退出循环。
第10⾏,输出总数值。
(3)until循环语句与for和while循环体⼀样,until循环也执⾏⼀系列的命令,直到条件满⾜后退出循环。
until循环在循环体的顶部继续判断条件,直到条件为真时结束循环,否则⼀直执⾏。
以下脚本使⽤until语句来实现⼀个简单的、不断循环的输出预设值,直到⼈为⼲预时结束循环(按Ctrl+C组合键退出)。
shell脚本100例、练习使用

shell脚本100例、练习使⽤1、编写hello world脚本#!/bin/bashecho"hello world"2、通过位置变量创建linux系统账户和密码#!/bin/bash#$1是执⾏脚本第⼀个参数 $2是执⾏脚本第⼆个参数useradd "$1"echo"$2" | passwd --stdin "$1"#测试脚本[root@template-host sh1]# sh2.sh aaa 123Changing password for user aaa.passwd: all authentication tokens updated successfully.#测试登录[root@template-host sh1]# su - aaa[aaa@template-host ~]$3、每周五使⽤tar命令备份 /var/log下的所有⽇志⽂件#!/bin/bashtar -czPf log-`date +%y%m%d`.tar.gz /var/log #加P是因为如果不加会出现错误:tar: Removing leading `/' from member names date和+之间注意有空格。
修改系统参数[root@template-host sh1]# crontab -e00 03 * * 5 /data/sh1/3.sh4、⼀键部署LNMP(RPM包版本)#!/bin/bash#此脚本需要提前配置yum源,否则⽆法配置成功。
本脚本使⽤于7.4yum -y install httpdyum -y install mariadb mariadb-devel mariadb-serveryum -y install php php-mysqlsystemctl start httpd mariadb #启动httpd、mariadbsystemctl enable httpd mariadb #加⼊开机⾃启动systemctl status httpd mariadb #查看是否成功5、实时监控本机硬盘内存剩余空间,剩余内存空间⼩于500M,根分区剩余空间⼩于1000M时,发送警报信息到命令⾏#!bin/bash#提取分区剩余空间单位:kbdisk_size=$(df / | awk'/\//{print $4}')#提取内存空间单位Mmem_size=$(free -m | awk'/Mem/{print $4}')while :doif [ $disk_size -le 512000 -o $mem_size -le 1024 ];thenecho"警报:资源不⾜"sleep5fidone6、随机⽣成⼀个100以内的随机数,提⽰⽤户猜数字,提⽰⽤户猜⼤了、猜⼩了、猜对了,直⾄⽤户猜对,脚本结束。
如何编写可维护的Shell脚本高级技巧和最佳实践

如何编写可维护的Shell脚本高级技巧和最佳实践Shell脚本是用于与操作系统进行交互的脚本语言,广泛应用于自动化任务、系统管理和软件开发等领域。
编写可维护的Shell脚本是提高开发效率、降低维护成本的重要任务。
本文将介绍一些Shell脚本的高级技巧和最佳实践,帮助您编写出结构清晰、可读性强、易于维护的Shell脚本。
一、使用可靠的Shell解释器选择合适的Shell解释器是编写可维护Shell脚本的第一步。
常见的Shell解释器包括Bash、Zsh和Fish等,其中Bash是最常用的Shell解释器。
确保在脚本的开头使用正确的解释器声明,例如:#!/bin/bash二、设置合适的选项设置合适的选项可以帮助您避免一些常见的错误,并改善脚本的健壮性和可移植性。
以下是一些常用的选项设置:set -o errexit # 如果任何命令的退出状态非零,则立即退出脚本set -o nounset # 当使用未初始化的变量时,立即退出脚本set -o pipefail # 如果管道中的任何命令失败,则将整个管道标记为失败三、注释和文档化良好的注释和文档化是编写可维护Shell脚本的关键。
通过清晰的注释和文档,可以使其他开发人员更容易理解和维护您的脚本。
以下是一些建议:- 在脚本的开头添加版权声明和摘要,描述脚本的用途和功能。
- 在每个函数的开头添加注释,说明函数的作用和参数。
- 对于复杂的逻辑或算法,使用注释来解释算法的思路和实现方法。
四、错误处理合适的错误处理可以提高脚本的健壮性和可维护性。
以下是一些建议:- 使用函数来封装重复的错误处理代码,提高代码的复用性。
- 在关键的错误处理点处添加必要的日志记录,以便更好地排查问题。
- 使用适当的返回值和退出码来指示脚本的状态。
五、变量和参数处理合理使用变量和参数可以使脚本更具可读性和灵活性。
以下是一些建议:- 使用有意义的变量名,提高代码的可读性和可维护性。
- 使用参数来传递脚本的输入,使脚本更具通用性。
shell脚本案例

shell脚本案例1.设计⼀个shell程序,添加组为class1,然后添加属于这个组的30个⽤户,⽤户名为 stuxx,其中xx从01到 30#!/bin/bashi=1groupadd class1while [ $i -le 30 ]doif [ $i -le 9 ];thenUSERNAME=stu0${i}elseUSERNAME=stu${i}fiuseradd $USERNAMEmkdir /home/$USERNAMEchown -R $USERNAME /home/$USERNAMEchgrp -R class1 /home/$USERNAMEi=$(($i+1))done2.编写⼀个shell程序,实现⾃动删除30个账号的功能,账户名为stu01⾄stu30#!/bin/bashi=1while [ $i -le 50 ]doif [ $i -le 9 ];thenname=stu0$ielsename=stu$ifiuserdel -r $namei=$(($i+1))done3.设计⼀个shell程序,在每⽉第⼀天备份并压缩/etc⽬录的所有内容,存放在 /root/back⽬录⾥,且⽂件名未如下命名格式,yy为年mm为⽉,dd为⽇。
shell程序fileback存放在/usr/bin⽬录下。
(1)编写shellx程序fileback#!/bin/bashDIRNAME=`ls /root/back`if [ $? -eq 0 ];thensleep 3exit 1elsemkdir /root/backcd /root/backYY=`date +%y`MM=`date +%m`DD=`date +%d`BACKETC=$YY$MM$DD_etc.tar.gztar zcvf $BACKETC /etc/echo "fileback finished"fi(2)编写定时任务echo "0 0 1 * * /bin/sh /usr/bin/fileback" > /root/etc_backcrontab /root/etc_back或者使⽤crontab -e添加定时任务0 0 1 * * /bin/sh /usr/bin/fileback3.设计⼀个shell程序,在/userdate⽬录下创建50个⽬录,即user1-user20,并设置每个⽬录的权限,其他⽤户的权限为:读,⽂件所有者的权限为:读,写执⾏,⽂件所有者所在的组的权限为:读,执⾏。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
很实用的Shell脚本(实践版)/erpHome/shell/old/$1/$2.zip.oldfind . -mtime +7 | xargs nice -n 20 zip -qm /erpHome/shell/old/$1/$2_$DayOfWeek.zip # find . -mtime +7FiarchiveOld2.sh. /erpHome/shell/setP.shexport DayOfWeek=`date +"%u"`if test "$#" -lt 1 || test -z "$1"thenecho At least one argument needed.exitfiif test ! -e "$ShellHome/old/$1"thencd $ShellHome/old/mkdir -p $1fiif test ! -e "$ERPHome/$1"thenecho "$ERPHome/$1" "does not exist" exitficd $ERPHome/$1mv $ShellHome/old/$1_$DayOfWeek.zip $ShellHome/old/$1.zip.oldfind . -mtime +7 -type f | xargs nice -n 20 zip -qm $ShellHome/old/$1_$DayOfWeek.zip #find . -mtime +7 -type farchiveOldAll.sh/erpHome/shell/archiveOld.shwork/dr/engine jrprint/erpHome/shell/archiveOld.sh work/de tmp /erpHome/shell/archiveOld2.sh publicbackupLog.shecho `date` ": Backup the logs". /erpHome/shell/setP.shcd $ERPHome/waslogsmkdir old/mv std*_*.txt old/mv $LOGHome/LOG_$DD.zip $LOGHome/LOG.zip.oldzip -qmr $LOGHome/LOG_$DD.zip `ls $ERPHome/waslogs | grep -Ev "std|FATAL_DEBUG.xml"`ls -l $LOGHome/LOG_$DD.zipecho `date` ": Backup the logs done."backupWASAll.sh. /erpHome/shell/setP.shcd /erpHome#rename old backup fileecho "####" `date` "ERP program backup ####" #mv /wasbackup/WASBackup_"$DayOfWeek".tar /wasbackup/WASBackup_old.tarrm -Rf /wasbackup/erpbak/WASBackup_"$DayOfWeek". tar#backup ERP programnice -n 20 tar -cf /wasbackup/erpbak/WASBackup_"$DayOfWeek". tar jln.ear/erp.war DIClient DIServer ThreadPool erpdatals -l /wasbackup/erpbak/WASBackup_"$DayOfWeek". tarcollectAudit.sh. /erpHome/shell/setP.sh jlnaudit shutdownauditpr -v < /audit/trail | grep PROC_Execute > $LOGHome/AUDIT_$YYMMDD.txt mv /audit/trail $LOGHome/trail_$TTgzip $LOGHome/trail_$TTaudit startlast | grep "$TT2" >$LOGHome/LOGIN_$YYMMDD.txtgrep "$TT3" /var/adm/sulog > $LOGHome/SU_$YYMMDD.txtcplogs.shexport dd=`perl -e '@y=localtime(time()-86400); printf "%02d\n",$y[3];'`cd /erpHome/shell/logsmkdir /test/erplogscp ./LOG_"$dd".zip /test/erplogscpnmon.shcd /worktmp/nmonexport dd=`perl -e '@y=localtime(time()-86400); printf "%02d\n",$y[3];'`export d=`date +%y%m`"$dd"export HOSTNAME=`hostname`export data="$HOSTNAME"_"$d"_"*"ftp -n <<EOFopen 10.32.1.138user nmon nmoncd $HOSTNAMEput $databyeEOFddd.shcd $1touch 11.txtfilter.awk BEGIN {DiscardURLs="/erp/de/deCommand/erp/jsp/"DiscardAmount=split(DiscardURLs,DiscardUR L," ")ResponseThreshold=4.9999nlines=0totalCount=0}function extractTime(myDate,aSize){if (aSize==2) return myDate[2]if (myDate[2]=="上午") return myDate[3]split(myDate[3],dates,":")return dates[1]+12 ":" dates[2] ":" dates[3]}function isSkip(myURL) {for (i = 1; i <= DiscardAmount; i++)if (index(myURL,DiscardURL[i])>0) return 1return 0}{if (isSkip($3)==0) {if (NF==10){totalCount++;if ($4 > ResponseThreshold){mySize=split($2,myDate," ")myTime=extractTime(myDate,mySize)print $1 "\t" myTime "\t" $3 "\t" $4 "\t" $5 "\t" $6 nlines++ }}}} END{print "本日网页执行总次数:" totalCount " (JSP,servlet,但不包含图片等静态网页,也不包含/erp/jsp/开头的这些监控画面)"print "共 " nlines " 笔异常资料"formatHTML.awkBEGIN {}function getSysName(myURL) {fCount=split(myURL,myArray,"/") return myArray[3]}functiongetMaxInArray(oArray,oResult,oIndex){maxValue=0for (idx in oCount){if(oCount[idx]>maxValue){maxValue=oCount[idx]maxSys=idx}}delete oArray[maxSys]oResult[oIndex,1]=maxSysoResult[oIndex,2]=maxValue}function sort(array,result,thresHold){ for(i=1;i<=5;i++){getMaxInArray(array,result,i)}}{oSys=getSysName($3)if (NF!=6){print $0 "<br/>"}else{oCount[oSys]++oRecord++;print "<tr style='background-color:#C4DAFF'><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td><td>" $4 "</td><td>" $5 "</td><td>" $6 "</td></tr>"}} END{oThreshold oRecord/10sort(oCount,oResult,oThreshold)print "</table>"print "<script>"max=oResult[1,2]for(i=1;i<=5;i++){print "addData(\"" (oResult[i,2]/max*100) "pt\"," i ",\"" oResult[i,1] "\",\"" oResult[i,2] "\")" }}formatHTML.awk.oldBEGIN {print "<html><head><meta http-equiv='Content-Type'content='text/html;charset=GBK'><style>td {border:1px solid black;}</style></head><body><H1 align>执行时间超过60 秒的网址</H1><table style='border:1px solid black' cellspacing=0 align=center>"}if (NF!=6){print $0 "<br/>"}else if (NR==1){print "<tr style='background-color:pink'align=center><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td><td>" $4 "</td><td>" $5 "</td><td>" $6 "</td></tr>"} else{print "<tr style='background-color:#C4DAFF'><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td><td>" $4 "</td><td>" $5 "</td><td>" $6 "</td></tr>"}} END{print "</table></body></html>"}htmlFoot.txt</script></body></html>htmlHead.txt<html><head><meta http-equiv='Content-Type' content='text/html; charset=GBK'><style>@import "/erp/html/dn/filtergrid.css";.td2 {border:0px}.td3 {border-right}.div1 {border:solid black 1px}.div2 {border:solid black 1px;text-align:right}.div3 {border:solid 1px white}td {border:1px solid black;}</style><script language="javascript" type="text/javascript"src="/erp/html/dn/actb.js"></script><!-- External script --><script language="javascript" type="text/javascript"src="/erp/html/dn/tablefilter.js"></scrip t><script language="javascript" type="text/javascript">function doFilter(){var props = {remember_grid_values: true,alternate_rows: true,rows_counter: true,rows_counter_text: "Displayed rows: ",btn_reset: true,btn_reset_text: "Clear", btn_text: " > ",loader: true,loader_text: "Filtering data...",col_0: "select",col_1: "none",col_3: "none",col_4: "none",col_5: "select",display_all_text: "< Show all >",sort_select: true}setFilterGrid("table1",props);}</script><script>var Colors=newArray("green","red","blue","yellow","oran ge")functionaddData(oWidth,oIndex,oSys,oData){chartBlock.innerHTML+="<div class=div3 style='background-color:"+Colors[(oIndex%5)] +";width="+ oWidth +"'></div>";sysBlock.innerHTML+="<div class='div1'>"+ oSys +"</div>";dataBlock.innerHTML+="<divclass='div2'>"+ oData +"</div>";}function doVisible(){if (vf1.innerText=="+"){ vf1.innerText="-";chartBlock.style.visibility="visible";sysBlock.style.visibility="visible";dataBlock.style.visibility="visible";}else {vf1.innerText="+";chartBlock.style.visibility="hidden"; sysBlock.style.visibility="hidden";dataBlock.style.visibility="hidden";}}</script></head><body><TABLE cellspacing=0 cellpadding=0><TR><TD width=100% class=td2><H1 align>执行时间超过 5 秒的网址</H1></TD><div id=myChart style="border:black solid 1px"><TD class=td3 id=chartBlock style="visibility:hidden"></TD><TD class=td2 id=sysBlock style="visibility:hidden"></TD><TD class=td2 id=dataBlock style="visibility:hidden"><td id=vf1 UNSELECTABLE=on style="cursor:hand"onclick="doVisible()">+</td></div></TD></TR></TABLE><BUTTON UNSELECTABLE=on style="cursor:hand"onclick="doFilter()">Filter</BUTTON><table id=table1 style='border:1px solid black' cellspacing=0 align=center><trstyle='background-color:pink'align=center><td>来源电脑</td><td>时间</td><td>网址</td><td>执行时间</td><td>QueryString</td><td>UserID</td></tr>increaseERP.sh. /erpHome/shell/setP.shcd /erpHomefind jln.ear -type f -mtime 2 -print >/tmp/filelist.txtfind erpdata -type f -mtime 2 -print >>/tmp/filelist.txttar cvfL/wasbackup/WASBackup_"$DayOfWeek".tar/tmp/filelist.txtnight.old. /erpHome/shell/setP.sh$ShellHome/backupLog.sh >> $NightLog 2>&1 $ShellHome/ApacheLogRotate.sh >> $NightLog 2>&1mv /erpHome/bx.ear/erp.war/access.txt /erpHome/shell/logs/access_$YYMMDD.txt awk -F "\t" -f /erpHome/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt > /erpHome/shell/logs/temp.csv#echo "ㄓ方筿福,丁,呼,磅︽丁,QueryString,UserID" > /erpHome/shell/logs/temp2.csvecho "来源电脑,时间,网址,执行时间,QueryString,UserID" > /erpHome/shell/logs/temp2.csvsort -t "," +3 -n -r /erpHome/shell/logs/temp.csv >> /erpHome/shell/logs/temp2.csvawk -F "," -f /erpHome/shell/formatHTML.awk /erpHome/shell/logs/temp2.csv > $ERPHome/public/$YYMMDD.htmlgzip -v /erpHome/shell/logs/access_$YYMMDD.txt >> $NightLog 2>&1sv#awk -f /erpHome/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt > $ERPHome/public/$YYMMDD.html#gzip -v /erpHome/shell/logs/access_$YYMMDD.txt >> $NightLog 2>&1night.sh. /erpHome/shell/setP.sh#/usr/WebSphere/AppServer/bin/stopServer. sh server1 >> $NightLog 2>&1$ShellHome/backupLog.sh >> $NightLog 2>&1 $ShellHome/ApacheLogRotate.sh >> $NightLog 2>&1#$ShellHome/processFile.sh db_serv2 0000 >> $NightLog 2>&1#mv $ERPHome/access.txt /erpHome/shell/logs/access_$YYMMDD.txt awk -F "\t" -f /erpHome/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt > /erpHome/shell/logs/temp.csvsort +3 -n -r /erpHome/shell/logs/temp.csv > /erpHome/shell/logs/temp2.csvcat /erpHome/shell/htmlHead.txt > $ERPHome/public/$YYMMDD.htmlawk -F "\t" -f /erpHome/shell/formatHTML.awk/erpHome/shell/logs/temp2.csv >> $ERPHome/public/$YYMMDD.htmlcat /erpHome/shell/htmlFoot.txt >> $ERPHome/public/$YYMMDD.html#gzip -v /erpHome/shell/logs/access_$YYMMDD.txt >> $NightLog 2>&1/erpHome/shell/archiveOldAll.sh >> $NightLog 2>&1#/usr/WebSphere/AppServer/bin/startServer .sh server1 >> $NightLog 2>&1night.sh.bak. /erpHome/shell/setP.sh#/usr/WebSphere/AppServer/bin/stopServer. sh server1 >> $NightLog 2>&1$ShellHome/backupLog.sh >> $NightLog 2>&1 $ShellHome/ApacheLogRotate.sh >> $NightLog 2>&1#$ShellHome/processFile.sh db_serv2 0000 >> $NightLog 2>&1#mv $ERPHome/access.txt /erpHome/shell/logs/access_$YYMMDD.txt#awk -F "\t" -f /erpHome/shell/filter.awk /erpHome/shell/logs/access_$YYMMDD.txt > /erpHome/shell/logs/temp.csv#sort +3 -n -r /erpHome/shell/logs/temp.csv > /erpHome/shell/logs/temp2.csv#cat /erpHome/shell/htmlHead.txt > $ERPHome/public/$YYMMDD.html#awk -F "\t" -f/erpHome/shell/formatHTML.awk/erpHome/shell/logs/temp2.csv >> $ERPHome/public/$YYMMDD.html#cat /erpHome/shell/htmlFoot.txt >> $ERPHome/public/$YYMMDD.htmlgzip -v /erpHome/shell/logs/access_$YYMMDD.txt >> $NightLog 2>&1/erpHome/shell/archiveOldAll.sh >> $NightLog 2>&1#/usr/WebSphere/AppServer/bin/startServer .sh server1 >> $NightLog 2>&1#Old.馵..@public!IHS.old.zip'public.zip.old#pu blic_5.zip$public_7.zip*public_1.zip%publ ic_2.zip&public_4.zip(public_6.zip)shell_ test.zipwork"public_3.zipxjh@p55013:/erpHome/shell#processFile.shexport YYMM=`/usr/bin/date +"%y%m"`; export YYMMexport YYMMDD=`/usr/bin/date +"%y%m%d"`; export YYMMDDmkdir -p /nmon/report/$1/$YYMM/$YYMMDD/ cd /nmonnice -n 20 ./nmon2rrd -f $1_"$YYMMDD"_$2.nmon -d /nmon/report/$1/$YYMM/$YYMMDD -xgzip -9 /nmon/report/$1/$YYMM/$YYMMDD/*rrd*gzip -9 $1_"$YYMMDD"_$2.nmonres.sh/erpHome/shell/stopServer.sh $1 /erpHome/shell/startServer.sh $1restartjvm.sh/usr/WebSphere/AppServer/profiles/AppSrv0 1/bin/stopServer.sh s1/usr/WebSphere/AppServer/profiles/AppSrv0 1/bin/startServer.sh s1#/usr/WebSphere/AppServer/profiles/AppSrv 01/bin/stopServer.sh s2#/usr/WebSphere/AppServer/profiles/AppSrv 01/bin/startServer.sh s2rmGClog.shcd/usr/WebSphere/AppServer/profiles/AppSrv0 1/logs/s1> native_stderr.logcd/usr/WebSphere/AppServer/profiles/AppSrv0 1/logs/s2> native_stderr.logcd/usr/WebSphere/AppServer/profiles/AppSrv0 1/logs/t1> native_stderr.logcd/usr/WebSphere/AppServer/profiles/AppSrv0 1/logs/t2rmwasbackup.shcd /wasbackupfind . -ctime +1 -exec rm {} \;server.lstserver1setP.shexport ERPHome=/erpHome/jln.ear/erp.warif ! test -e $ERPHomethenecho "Warning! " $ERPHome " not exists."exitfiexport ShellHome=/erpHome/shellexport LOGHome=/erpHome/shell/logsexport WAS_HOME=/usr/WebSphere/AppServer export Java_Home=$WAS_HOME/java/export TT=`date +"%Y%m%d%H%M%S"`export TT2=`date +"%b %d"`export TT3=`date +"%m/%d"`export YYMMDD=`date +"%Y%m%d"`export DD=`date +"%d"`exportUpdateLog=$LOGHome/update_$YYMMDD.txt exportNightLog=$LOGHome/night_$YYMMDD.txt export DayOfWeek=`date +"%u"`startAllService.sh/usr/WebSphere/IHS/bin/apachectl start /erpHome/ThreadPool/bin/go.sh start/erpHome/DIServer/bin/go.sh start/usr/WebSphere/AppServer/bin/startServer. sh server1startServer.sh#! /usr/bin/kshif test "$#" -lt 1 || test -z "$1"thenecho Usage: $0 [ServerName]echo "Available ServerName: "awk '{print "\t\t\t" $1}' /erpHome/shell/server.lstexitfiIFSsave=$IFSwhile IFS=''; read linedoif test $1 = $linethenexport ValidArg=1breakfidone < /erpHome/shell/server.lstIFS=$IFSsaveif test -z "$ValidArg"thenecho Invalid ServerName. echo "Available ServerName: "awk '{print "\t\t\t" $1}' /erpHome/shell/server.lstexitfiexport ServerName=$1echo "#################### start $1 `date` ####################" >> /erpHome/shell/logs/serverRestart.log/usr/WebSphere/AppServer/bin/startServer. sh $1stopServer.sh#! /usr/bin/kshif test "$#" -lt 1 || test -z "$1"thenecho Usage: $0 [ServerName]echo "Available ServerName: "awk '{print "\t\t\t" $1}' /erpHome/shell/server.lstexitfiIFSsave=$IFSwhile IFS=''; read linedoif test $1 = $linethenexport ValidArg=1 breakfidone < /erpHome/shell/server.lstIFS=$IFSsaveif test -z "$ValidArg"thenecho Invalid ServerName. echo "Available ServerName: "awk '{print "\t\t\t" $1}' /erpHome/shell/server.lstexitfiexport ServerName=$1echo "#################### stop $1 `date` ####################" >> /erpHome/shell/logs/serverRestart.log/usr/WebSphere/AppServer/bin/stopServer.s h $1syncConfig.shcp/erpHome/jln.ear/erp.war/WEB-INF/web.xm l/usr/WebSphere/AppServer/profiles/Dmgr01/ config/cells/p55013Cell01/applications/jl n.ear/deployments/jln/erp.war/WEB-INF/erpHome/jln.ear/erp.war/WEB-INF/web.xm l/usr/WebSphere/AppServer/profiles/AppSrv0 1/config/cells/p55013Cell01/applications/ jln.ear/deployments/jln/erp.war/WEB-INF /usr/WebSphere/AppServer/profiles/Dmgr01/ bin/GenPluginCfg.shsyncConfig.sh.bakcp/erpHome/jln.ear/erp.war/WEB-INF/web.xm/usr/WebSphere/AppServer/profiles/Dmgr01/ config/cells/p510Cell01/applications/jln. ear/deployments/jln/erp.war/WEB-INFcp/erpHome/jln.ear/erp.war/WEB-INF/web.xm l/usr/WebSphere/AppServer/profiles/AppSrv0 1/config/cells/p510Cell01/applications/jl n.ear/deployments/jln/erp.war/WEB-INF/usr/WebSphere/AppServer/profiles/Dmgr01/ bin/GenPluginCfg.shupdateFTPSrc.sh. /erpHome/shell/setP.shecho `date` > $ERPHome/work/da/log/update/last.log export DAHome=/home/ftpuser/pubif ! test $(find $DAHome -type f | wc -l) -eq 0thenecho `date` ": Update source" >> $UpdateLog 2>&1echo "################ Update the source ################" >> $UpdateLog 2>&1echo $ERPHome >> $UpdateLog 2>&1/usr/bin/cp -r $DAHome/* $ERPHome >> $UpdateLog 2>&1# /usr/bin/cp -r $DAHome/* /erpHome/shell/src >> $UpdateLog 2>&1# /usr/bin/rm -fre $DAHome/* >> $UpdateLog 2>&1find $DAHome -type f -exec \rm -e {} \; >> $UpdateLog 2>&1# echo "copy" >> $UpdateLog 2>&1# mail -s "$1 update program" root < $UpdateLogecho `date` ": Update source done" >> $UpdateLog 2>&1fiupdateSource.sh. /erpHome/shell/setP.sh $ShellHome/updateSrc.sh bin $ShellHome/updateSrc.sh toc $ShellHome/updateFTPSrc.sh。