Posts

Showing posts from November, 2009

[Level 3] 1A2B shell game

Another game. # !/usr/bin/bash showUsage() {   cat <<EOF Usage:   $0 Ex.   $0 EOF } getNum() {   #set -vx   sNum="0|1|2|3|4|5|6|7|8|9"   sAns=""   declare -i n1=$RANDOM*10/32767+1   declare -i n2=$RANDOM*9/32767+1   declare -i n3=$RANDOM*8/32767+1   declare -i n4=$RANDOM*7/32767+1   s=`echo $sNum | cut -d'|' -f$n1` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`   s=`echo $sNum | cut -d'|' -f$n2` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`   s=`echo $sNum | cut -d'|' -f$n3` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`   s=`echo $sNum | cut -d'|' -f$n4` &&

[Level 3] OX shell game.

Today, I deliver the shell programming course. And I think, why not to write a simple shell script game. The script should be to fun. #!/usr/bin/bash showUsage() {   cat<<EOF Usage:   $0 init/load 0/X Ex.   $0 init 0/X   $0 load O/X EOF } checkLine() {   sDisp=$1   s1=`echo $sDisp | cut -d'|' -f1`   s2=`echo $sDisp | cut -d'|' -f2`   s3=`echo $sDisp | cut -d'|' -f3`   s4=`echo $sDisp | cut -d'|' -f4`   s5=`echo $sDisp | cut -d'|' -f5`   s6=`echo $sDisp | cut -d'|' -f6`   s7=`echo $sDisp | cut -d'|' -f7`   s8=`echo $sDisp | cut -d'|' -f8`   s9=`echo $sDisp | cut -d'|' -f9`   if [ $s1 == $s2 ] && [ $s2 == $s3 ]   then     echo "$s1 wins..." && return 0   elif [ $s4 == $s5 ] && [ $s5 == $s6 ]   then     echo "$s4 wins..." && return 0   elif [ $s7 == $s8 ] && [ $s8 == $s9 ]   then     echo "$s7 wins..." &&a

[Level 3] The script for demo creating mass zones on OpenSolaris

Days ago, my colleague will demo about the virtualization techniques on OpenSolari. So I share the script for him to demo fast creating zones on OpenSolaris. After test, my lap will create a zone per 3 seconds. That impress him, and he decided to demo on that session. The same script that I'd like to share to you, please refer the following script code. Any question, and suggestion, please feel free to let me know. #!/usr/bin/bash showUsage() {   cat< <EOF Usage:   $0 [c]reate  [original index] [start index] [end index]   $0 [d]estroy [start index]    [end index]   [always yes]   $0 [l]ist Ex.   $0 c 1 2 10   => create  zone2, zone3, ... ,zone10   $0 c 1 3 8    => create  zone3, zone4, ... ,zone8   $0 d 2 10 [F] => destroy zone2, zone3, ... ,zone10   $0 l PS.   for solaris 11 only   all indexes must greater then 1, less then 255 Zones: `listZone` EOF } createOriginZone() {   echo "create Zone (zone$nOriginIndex)..."   zfs creat

[Level 3] Script for create VirtualBox VM quickly.

This script is for quickly create VirtualBox VM, it base on ZFS snapshot/clone technique. The description for the script is as the following: The step as below: 1. create a ZFS filesystem first. Ex. # zfs create -p rpool/vbox/sourceOS 2. create a VirtualBox VM for source and put the vdi on the above ZFS filesystem. 3. use the script: Usage:   $0 create New_Machine_Name Source_Machine_Name interface begin_index end_index Ex.   ./createVBoxClientByClone.sh create NewVM SourceVM yukonx0 3 5 the above command will create 3 VMs (NewVM_3, NewVM_4, NewVM_5): The actions of create are, . snapshot origin ZFS . clone from origin ZFS snapshot to new ZFS . re-new vdi uuid on new ZFS . create new vm . modify new vm . modify new vm nic 4. If you want to delete VMs, use the command as below: Usage:   $0 delete New_Machine_Name Source_Machine_Name interface begin_index end_index Ex.   ./createVBoxClientByClone.sh delete NewVM SourceVM yukonx0 3 5 Above comand will delete 3 VM

[Level 2] How to get ZFS clone file system?

Now I have use VirtualBox with ZFS clone file system. So sometimes, I have to figure out which file system is native, which file system is clone. Therefore, I write a script to list the ZFS clone file system. #!/usr/bin/bash showUsage() {   cat < <EOF Usage:   $0 pool_name Ex.   $0 rpool EOF } ######################################################## main [ $# -lt 1 ] && echo "Error without parameters, exit program..." && showUsage && exit 1 sPoolname=$1 #sPoolname=${1:-rpool} echo "get pool($sPoolname)..." zfs get -r origin $sPoolname | egrep -v -- 'origin[ ]+-[ ]+-$' The you can use the command to find out the clone file system. # getCloneFS.sh rpool get pool(rpool)... NAME                                          PROPERTY  VALUE                                         SOURCE rpool/ROOT/opensolaris                        origin    rpool/ROOT/opensolaris-1@2009-11-18-05:46:35  - # Wish this helps. regards,

[Level 1] Install freemind on OpenSolaris

These days, my colleague want to find the freemind tool which can run on OpenSolaris, finally, we got one. And you can download it from the following link: http://freemind.sourceforge.net/wiki/index.php/Download After downloaded, you can got a zip file. then de-compress it. # cd /src # mkdir freemind # cd freemind; unzip ../freemind-bin-max-0_8_1.zip < lengthy output omitted > # chmod u+x ./freedmind.sh # ./freemind.sh # ps -ef | grep freemind  stanley  1155   810   0 14:25:00 pts/2       0:05 /usr/java/bin/java -Dfreemind.base.dir=. -cp ::./lib/freemind.jar:./lib/ant/lib Wish this helps. regards, Stanley Huang

[Level 2] Tips on ZFS.

1. Is that possible to migrate root filesytem from smaller hard disk to larger one without shutdown the operation system? The answer is "Yes", if you use OpenSolaris. You can use a larger disk to attach into the pool and make the hard disk be a part of mirror disk of the root file system. After join the pool, the zfs pool will reslivering the data from origin one to new hard disk. After reslivered, then deatch the old hard disk, then the zfs capacity will also increased. The simulation output as the following. # mkdir /temp # mkfile 128m /temp/128m # mkfile 256m /temp/256m # ls /temp/*m -rw-------   1 stanley  staff    134217728 Nov 19 09:06 /temp/128m -rw-------   1 stanley  staff    268435456 Nov 19 09:06 /temp/256m # # pfexec zpool create myPool /temp/128m # zpool status myPool   pool: myPool  state: ONLINE  scrub: none requested config:     NAME          STATE     READ WRITE CKSUM     myPool        ONLINE       0     0     0       /temp/128m  ONLINE 

[Leve 1] Use usb to com to connect SPARC machine in OpenSolaris.

Today, I try to use my colleage's usb to com cable, to connect SPARC machine. 1. check /dev/term folder first. # ls -al /dev/term total 8 drwxr-xr-x   2 root root   2 2009-11-10 18:20 . drwxr-xr-x 252 root sys  252 2009-11-10 18:20 .. 2. connect cable then try again. # ls -al /dev/term total 9 drwxr-xr-x   3 root root   3 2009-11-10 18:00 . drwxr-xr-x 253 root sys  253 2009-11-10 18:00 .. lrwxrwxrwx   1 root root  48 2009-11-10 18:00 0 -> ../../devices/pci@0,0/pci1043,8263@1d/device@1:0 3. use tip command to connect SPRAC machine. PS. you have to set baud rate to 9600. # tip -9600 /dev/term/0 4. Start the SPARC machine then you will get the console. Wish this helps. regards, Stanley Huang