⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 free_frag.sh.txt

📁 管理online的shell程序
💻 TXT
字号:
#!/usr/bin/ksh#################################################################################       Module:         free_frag.sh#       Author:         Peter R. Schmidt#       Description:    Report on free space fragmentation##       Change Log##         Date    Name               Description.................#       07/08/99  Peter R. Schmidt   Start Program ################################################################################OUTPUT=free_frag.outXDATE=`date +%D-%T`MACHINE=`uname -n`BG=false###############################################################################if [ $# != 0 ]then	PE_FILENAME=$2        ARG2=$2        case $ARG2 in                 1|2|3|4) OPTION1=$ARG2;;                 *)       OPTION1=2;;         esac        BG=trueelse	while true	do        	echo        	echo "1 = Report in Megs"        	echo "2 = Report in Kbytes"        	echo "3 = Report in Pages"        	echo "4 = Report in Bytes"        	echo "0 = Exit this program"        	echo        	echo "Enter reporting unit desired (0,1,2,3,4)"        	read OPTION1	        	case $OPTION1 in 0|1|2|3|4) break;; esac        	echo        	echo "Error - you must enter 0,1,2,3 or 4!"        	echo	done	while true	do		echo		echo "This program uses the output of oncheck -pe to compute free space fragmentation."		echo		echo "If you have already run oncheck -pe you simply need to provide the filename"		echo "containing the output of oncheck -pe."		echo		echo "If you haven't run oncheck -pe, I will run one for you."		echo		echo "Have you already run oncheck -pe ? (y/n)"		read answer		case $answer in Y|y|N|n) break;; esac;		echo		echo "You must answer Y or N !!"		echo	done	case $answer in		Y|y)				while true			do				echo				echo "Enter filename of the file containing the output of oncheck -pe"				echo "(Press <Enter> for default of pe.out)"				read PE_FILENAME				if [ $PE_FILENAME ]				then					echo "Note: Using $PE_FILENAME"				else					PE_FILENAME=pe.out					echo "Note: Using default filename of $PE_FILENAME"				fi				if [ -f $PE_FILENAME ]				then					break				else					echo					echo "Error: filename $PE_FILENAME does no exist!"					echo				fi			done;;		N|n)				echo "No problem, I will run it for you."			type oncheck > /dev/null			if [ $? != 0 ]			then				echo				echo "Error: the program 'oncheck' is not available  to execute."				echo "Perhaps, you haven't set your environment."				echo "Sorry - Program canceled."				exit 1			fi			echo "Note: running oncheck -pe..."			oncheck -pe > pe.out			if [ $? != 0 ]			then				echo				echo "Hmmmmmm - I've seemed to have encountered some type of error"				echo "attempting to run oncheck -pe."				echo "Sorry - Program canceled."				exit 1			fi	esacfi        case $OPTION1 in        0)      echo "End requested by user"; exit;;	1)	UNIT=M; UNITDESC=Mbytes;;	2)	UNIT=K; UNITDESC=Kbytes;;	3)	UNIT=P; UNITDESC=Pages;;	4)	UNIT=B; UNITDESC=Bytes;;esacif [ -f $OUTPUT ]then        rm -f $OUTPUTfi#----------------------------------------------------------------------nawk ' \	BEGIN {		x=0;		a_max1=0;		a_max2=0;	}	/Chunk:/ {		full_device=$3			# Get full device name 		x=split (full_device,a,"/")	# split elements in array 		chunk_name=a[x]			# Get last element of array	}	/CHUNK FREE LIST PAGE/ {		continue	}	/FREE/ {		size_in_pages=$3		printf "%-25s%10d\n", chunk_name, size_in_pages	}' pe.out | sort | nawk ' \		BEGIN {		page_size=2		total_all_free=0	}	{		chunk_name     = $1		size_in_pages  = $2		#printf "Debug1: %s %d\n", chunk_name, size_in_pages		x=get_position1(chunk_name) 		a_cnt1[x]++		a_sum1[x] += size_in_pages		x=get_position2(chunk_name,size_in_pages) 		a_cnt2[x]++		a_sum2[x] += size_in_pages		total_all_free += size_in_pages		#printf "Debug2: %-20s %7d ret_val = %d\n",chunk_name,size_in_pages,x	}	#######################################################################	END {       		split (xdate,b,"-")       		udate=b[1]       		utime=b[2]	       		printf "%s %s     Informix Free Space Report     for %s@%s\n", udate, utime, server, machine		printf "                              Section 1              using a %dK page size\n", page_size		printf "                         (Numbers in %s)                              \n", unitdesc		print 		print "                # of    Size of    Total of   Total of   Percent"		print "Chunk           Free     Free        this       this     of this"		print "Name          Segments  Segment      Size       Chunk     Chunk"		last_chunk = ""		for (z=1; z<=a_max2; z++) {			if (a_chunk_name2[z] != last_chunk) { print }			size1_P=a_chunk_size2[z]			size1_K=a_chunk_size2[z]*page_size			size1_M=size1_K/1024			size1_B=size1_K*1024			size2_P=a_sum2[z]			size2_K=a_sum2[z]*page_size			size2_M=size2_K/1024			size2_B=size2_K*1024			x=get_position1(a_chunk_name2[z]) 			tot_free_P=a_sum1[x]			tot_free_K=a_sum1[x]*page_size			tot_free_M=tot_free_K/1024			tot_free_B=tot_free_K*1024			if (tot_free_K > 0) {				percent1 = ((size2_K/tot_free_K)*100)			}			if (unit == "P") {				printf "%-16s %3d %10d %10d %10d    %6.2f%\n",a_chunk_name2[z],a_cnt2[z],size1_P, size2_P, tot_free_P, percent1			}			if (unit == "K") {				printf "%-16s %3d %10d %10d %10d    %6.2f%\n",a_chunk_name2[z],a_cnt2[z],size1_K, size2_K, tot_free_K, percent1			}			if (unit == "M") {				printf "%-16s %3d %10d %10d %10d    %6.2f%\n",a_chunk_name2[z],a_cnt2[z],size1_M, size2_M, tot_free_M, percent1			}			if (unit == "B") {				printf "%-16s %3d %10d %10d %10d    %6.2f%\n",a_chunk_name2[z],a_cnt2[z],size1_B, size2_B, tot_free_B, percent1			}			last_chunk = a_chunk_name2[z]		}		#--------------------------------------------------------------		print "\f"       		printf "%s %s     Informix Free Space Report     for %s@%s\n", udate, utime, server, machine		printf "                              Section 2              using a %dK page size\n", page_size		printf "                         (Numbers in %s)                              \n", unitdesc		print 		print "                    # of   Total of      Total    Percent"		print "Chunk               Free     this        Free     of all "		print "Name              Segments   Chunk       Space   Free Space"		print		for (z=1; z<=a_max1; z++) {			tot_free_P=a_sum1[z]			tot_free_K=a_sum1[z]*page_size			tot_free_M=tot_free_K/1024			tot_free_B=tot_free_K*1024			tot_all_free_P=total_all_free			tot_all_free_K=total_all_free*page_size			tot_all_free_M=tot_all_free_K/1024			tot_all_free_B=tot_all_free_K*1024			if (tot_all_free_K > 0) {				percent2 = ((tot_free_K/tot_all_free_K)*100)			}			if (unit == "P") {				printf "%-20s %3d %10d %10d    %6.2f%\n",a_chunk_name1[z],a_cnt1[z],tot_free_P, tot_all_free_P, percent2			}			if (unit == "K") {				printf "%-20s %3d %10d %10d    %6.2f%\n",a_chunk_name1[z],a_cnt1[z],tot_free_K, tot_all_free_K, percent2			}			if (unit == "M") {				printf "%-20s %3d %10d %10d    %6.2f%\n",a_chunk_name1[z],a_cnt1[z],tot_free_M, tot_all_free_M, percent2			}			if (unit == "B") {				printf "%-20s %3d %10d %10d    %6.2f%\n",a_chunk_name1[z],a_cnt1[z],tot_free_B, tot_all_free_B, percent2			}		}	}	#######################################################################	function get_position1(p_chunk_name) { 		#printf "Debug: Passed arg is %s\n", p_chunk_name		ret_val = 0		if (a_max1 == 0) {			a_chunk_name1[1] = p_chunk_name			a_chunk_id[p_chunk_name] = 1			a_max1   = 1			ret_val = 1		} else {			for (i=1; i<=a_max1; i++) {				#printf "Debug: Checking element %d, %s\n",i,a_chunk_name1[i]				if (a_chunk_name1[i] == p_chunk_name) {					ret_val = i					#printf "Debug: Found element %d\n",ret_val					break				}			}			if (ret_val == 0) {				#print "Debug: inserting new array element"				a_max1++				a_chunk_name1[a_max1] = p_chunk_name				a_chunk_id[p_chunk_name] = a_max1				ret_val = a_max1			}		}		#printf "Debug: Returning %d\n", ret_val		return ret_val	}	#######################################################################	function get_position2(p_chunk_name,p_size) { 		#printf "Debug: Passed arg is %s %d\n", p_chunk_name, p_size		ret_val = 0		if (a_max2 == 0) {			a_chunk_name2[1] = p_chunk_name			a_chunk_size2[1] = p_size			a_max2  = 1			ret_val = 1		} else {			for (i=1; i<=a_max2; i++) {				#printf "Debug: Checking element %d, %s\n",i,a_chunk_name2[i]				if ((a_chunk_name2[i] == p_chunk_name) && (a_chunk_size2[i] == p_size)) {					ret_val = i					#printf "Debug: Found element %d\n",ret_val					break				}			}			if (ret_val == 0) {				#print "Debug: inserting new array element"				a_max2++				a_chunk_name2[a_max2] = p_chunk_name				a_chunk_size2[a_max2] = p_size				ret_val = a_max2			}		}		#printf "Debug: Returning %d\n", ret_val		return ret_val	}' xdate=$XDATE machine=$MACHINE unit=$UNIT unitdesc=$UNITDESC server=$INFORMIXSERVER > $OUTPUTif [ $BG = false ]then        pg $OUTPUTfiechoecho "Note: Output report is in $OUTPUT"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -