-2 gnuplot( ) j 2006 05 03 2006 05 12 2006 05 09 2 ( ) gnuplot /shell/myscript 1
1 shell script Level 1 myls #!/bin/sh # nowdir= pwd # if [ -f $1 -o -z $1 ] ; then echo "Enter pass" echo "ex) myls.sh./" # if [ -d $1 ] ; then dir=$1 cd $dir dir= pwd else echo "Error! --> No Such Directory" le= ls -1 nkf -e # echo -e "\033[40m\033[1;32mNow $nowdir\033[0m" echo -e "\033[40m\033[1;32mViewing $dir\033[0m" # le for lename in $le do if [ -d $lename ] ; then echo -e "\033[1;34m${lename}\033[0m\1/" done # le 2
for lename in $le do if [ -f $lename ] ; then echo "${lename}" done # cd $nowdir myls 1: myls getopts Level 2 #!/bin/sh myupper # if [ -z $1 ] ; then echo "Error! --> Enter FileName" echo " example) myupper abc.txt" # for le do 3
# if [ -f $le ] ; then # ch tr ch= echo $le tr "[a-z]" "[A-Z]" echo "$le ---> $ch" #mv mv $le $ch # else "Error! --> Enter FileName" done myupper %ls Add.dsa asd.dsa das.dsa %sh myupper.sh *.dsa Add.dsa ---> ADD.DSA asd.dsa ---> ASD.DSA das.dsa ---> DAS.DSA %ls ADD.DSA ASD.DSA DAS.DSA mymv 4
#!/bin/sh # if [ $# -gt 2 ] ; then if [ $# -eq 0 ] ; then echo "Error! --> How to use" echo " example) mymv.sh after *.before" echo " abc.before -> abc.after" else echo "Error! --> Enter 2 extension " echo "If you enter % mymv.sh you can see How to use" #after after=$1 # shift list="" # for koko do # if [! -f $koko ] ; then echo "$koko is not found!" else # list list="$list $koko" done # list le for le in $list do # ext= expr "$le" : ".*\.\(.*\).*" 5
#tole afterle= basename $le $ext $after # while [ 1 ] do echo -n "$le -----> $afterle rename?(yes/no) " # read ans # case $ans in ##yes/y yes y) mv $le $afterle break ;; ##no/n no n) break ;; ## *) echo "please enter yse or no" continue ;; esac done done mymv %ls ADD.DSA ASD.DSA DAS.DSA %sh mymv.sh txt *.DSA 6
ADD.DSA -----> ADD.txt rename?(yes/no) y ASD.DSA -----> ASD.txt rename?(yes/no) n DAS.DSA -----> DAS.txt rename?(yes/no) y %ls ADD.txt ASD.DSA DAS.txt.txt 2 Level 2 thum #!/bin/sh # if [ $# -lt 2 ] ; then echo "Usage: $0 SUFFIX RESIZE photo_num" echo " RESIZE: percent" echo " example) thumnail3.sh jpg 30 2" # SUFFIX=$1 RESIZE=$2 photo_num=$3 les= ls *.$SUFFIX # ## DIR=resized if [ -d $DIR ] ; then 7
echo " temporal directory ($DIR) exsits..." else mkdir $DIR echo " temporal directory ($DIR) CREATED." ## cd $DIR le_num=0 for lename in $les do convert -resize $RESIZE%x$RESIZE%../$lename ${lename}_s.$suffix echo "convert $lename to $DIR/${lename}_s.$SUFFIX" le_num= expr $le_num + 1 echo $le_num done cd../ #HTML count_pa=1 # HTML flg=1 # HTML count_ph=0 # ## page= expr $le_num / $photo_num page2= expr $le_num % $photo_num if [ $page2 -ne 0 ] ; then page= expr $page + 1 echo "create $page HTML les" ## HTML resized_les= ls $DIR/*_s.$SUFFIX for lename in $resized_les do ### HTML 8
if [ $flg -eq 1 ] ; then echo "<html>" > page$count_pa.html echo "<head>" >> page$count_pa.html echo "<title>page$page.html</title>" >> page$count_pa.html echo "</head>" >> page$count_pa.html echo "<body>" >> page$count_pa.html flg=0 ### echo "<img src=\"$lename\" alt=\"img$count_ph\" >" >> page$count_pa.html count_ph= expr $count_ph + 1 echo "$lename --- page$count_pa.html " if [ $count_ph -eq $photo_num ] ; then flg=1 count_ph=0 ###HTML 1 if [ $flg -eq 1 ] ; then echo "</body>" >> page$count_pa.html echo "</html>" >> page$count_pa.html echo "created page$count_pa.html " count_pa= expr $count_pa + 1 done ###HTML 2(#HTML 1 ) echo "</body>" >> page$count_pa.html echo "</html>" >> page$count_pa.html ### HTML 2 if [ $count_pa -gt $page ] ; then rm page$count_pa.html 9
else echo "created page$count_pa.html " thum sh thum.sh jpg 30 4 temporal directory (resized) CREATED. convert DSC00030.jpg to resized/dsc00030.jpg_s.jpg 1 convert DSC00057.jpg to resized/dsc00057.jpg_s.jpg 2 convert DSC00076.jpg to resized/dsc00076.jpg_s.jpg 3 convert DSC00149.jpg to resized/dsc00149.jpg_s.jpg 4 convert DSC00160.jpg to resized/dsc00160.jpg_s.jpg 5 convert DSC00204.jpg to resized/dsc00204.jpg_s.jpg 6 create 2 HTML les resized/dsc00030.jpg_s.jpg --- page1.html resized/dsc00057.jpg_s.jpg --- page1.html resized/dsc00076.jpg_s.jpg --- page1.html resized/dsc00149.jpg_s.jpg --- page1.html created page1.html resized/dsc00160.jpg_s.jpg --- page2.html resized/dsc00204.jpg_s.jpg --- page2.html created page2.html HTML http://www.ie.u-ryukyu.ac.jp/~j05017/ie/jikken/page1.html http://www.ie.u-ryukyu.ac.jp/~j05017/ie/jikken/page2.html HTML HTML HTML (flg) HTML 2 10
3 Level 4 log #!/bin/sh # if [ -z $1 ] ; then echo "Enter lename and option" echo "ex) log.sh access_log {ip/day}" # if [ -z $2 ] ; then echo "Enter option" echo "ex) log.sh access_log {ip/day}" # log_count= wc -l $1 echo "$log_count" ### if [ $2 = "day" ] ; then # touch day_list.dat chmod u+rwx day_list.dat # ( cut -d -f 4 < $1 cut -c 2-12 sort -n uniq -c ) > day_list.dat cat day_list.dat # echo set terminal png > day.gnuplot echo set output "day.png" >> day.gnuplot echo set title "Daily access log" >> day.gnuplot 11
echo set xlabel "Date (2004)" >> day.gnuplot echo set ylabel "Access rate" >> day.gnuplot echo plot "day_list.dat" using 2:1 with boxes >> day.gnuplot gnuplot < day.gnuplot # rm -f day_list.dat rm -f day.gnuplot ###IP if [ $2 = "ip" ] ; then #IP touch ip_list.dat chmod u+rwx ip_list.dat # IP ( cut -d -f 1 < $1 sort -n uniq -c ) > ip_list.dat cat ip_list.dat # echo set terminal png > ip.gnuplot echo set output "ip.png" >> ip.gnuplot echo set title "IP access log" >> ip.gnuplot echo set xlabel "IP" >> ip.gnuplot echo set ylabel "Access rate" >> ip.gnuplot echo plot "ip_list.dat" using 2:1 with boxes >> ip.gnuplot gnuplot < ip.gnuplot # rm -f ip_list.dat rm -f ip.gnuplot 12
###HTML if [ $3 ] ; then echo "<html>" > $3.html echo "<head>" >> $3.html echo "<title>$3.html</title>" >> $3.html echo "</head>" >> $3.html echo "<body>" >> $3.html echo "<img src=\"$2.png\" alt=\"$2_access_log\" >" >> $3.html echo "</body>" >> $3.html echo "</html>" >> $3.html echo "created $3.html " log %sh log.sh access_log day Daily 95 access_log 7 06/Dec/2004 1 08/Dec/2004 76 09/Dec/2004 2 10/Dec/2004 1 13/Dec/2004 2 15/Dec/2004 1 17/Dec/2004 2 21/Dec/2004 3 22/Dec/2004 created Daily.html HTML http://www.ie.u-ryukyu.ac.jp/~j05017/ie/jikken/le/daily.html IP %sh log.sh access_log ip IP 95 access_log 1 35.10.47.37 3 60.34.136.173 13
1 61.116.186.45 2 61.199.170.156 1 61.213.47.211 6 61.78.61.166 1 61.95.54.174 1 64.53.90.33 2 66.196.90.178 1 66.196.90.207 5 66.196.90.59 1 66.196.90.92 1 66.196.91.132 1 66.196.91.175 1 66.196.91.178 1 66.196.91.199 1 66.196.91.202 1 66.196.91.203 2 66.196.91.205 1 66.196.91.206 2 66.196.91.207 2 66.196.91.216 7 66.196.91.239 1 66.196.91.32 1 66.196.91.87 1 68.121.94.147 1 68.143.54.82 4 82.67.110.170 2 82.79.189.243 1 133.13.48.235 1 133.13.48.8 1 133.13.49.18 2 133.13.50.76 1 133.13.52.37 1 133.13.53.122 2 133.13.54.156 2 133.13.54.53 3 133.13.57.226 2 133.95.109.80 1 210.139.250.215 1 210.47.27.36 14
1 218.113.200.138 1 218.146.238.174 1 219.160.252.142 5 219.166.179.56 3 220.109.8.237 5 220.110.222.75 3 220.20.70.41 1 220.221.238.133 2 220.221.239.196 created IP.html HTML http://www.ie.u-ryukyu.ac.jp/~j05017/ie/jikken/le/ip.html IP 1. IP - - [ : 2. IP 3. 4 TeX itembox [1] gnuplot http://www.eva.ie.u-ryukyu.ac.jp/ tnal/2006/info1/shell/index.html 15
[2] Shell Shell Script http://www.iis.elec.fuk.kindai.ac.jp/ sira/index.php? [3] UNIX http://x68000.q-e-d.net/ 68user/unix/ [4] Bash-Prompt-HOWTO http://www.linux.or.jp/jf/jfdocs/bash-prompt-howto.html [5] http://www.ybi.co.jp/koike/src/bsh.htm.html 16