Hi, First version of a script-shell to manage socketclass :
Usage: ckrmsocket [[-v] <options>] without option, display the list of socketclass available. the syntax for a socket is <ipaddress:port> options description -v verbose mode -c [path/]socketclass_name [..] create a [list of] socketclass -d [path/]socketclass_name [..] delete a [list of] socketclass -f socket find the class_name of the socket -h -? --help display this help -i [path/]socketclass_name [..] display info/stats of the [list of] socketclass -l list all socketclass -l [path/]socketclass_name detailed socketclass information (shares) -m socket [path/]socketclass_name migrate/assign a socket into a socketclass -p display all socket per class -p [path/]socketclass_name display all socket of the socketclass -r to reclassify all sockets (all the socket) -r socket | [path/]socketclass_name to reclassify a socket or a socketclass Note : no stats/shares/config informations or reclassify yet. Enjoy, Patrick +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ Patrick Le Dot mailto: [EMAIL PROTECTED]@bull.net Centre UNIX de BULL S.A. Phone : +33 4 76 29 73 20 1, Rue de Provence B.P. 208 Fax : +33 4 76 29 76 00 38130 ECHIROLLES Cedex FRANCE http://www.bull.com =================================================================== #!/bin/bash # # ckrmsocket : socketclass management # RCFS=rcfs # User's preference else directory by default # RCFS_MOUNT=${CKRM_RCFS_MOUNT_POINT:-/$RCFS} BIN=/bin # Internals goodies # MEMBERS=members SHARES=shares CONFIG=config RECLASSIFY=reclassify TARGET=target STATS=stats VERBOSE= SOCKETCLASS=socketclass SOCKETCLASS_DIR=$RCFS_MOUNT/$SOCKETCLASS RBCE_DIR=$RCFS_MOUNT/ce # another name for the top level class socketclass ? # DEFAULT_CLASS=default # Current hierarchie limitation : class and sub-class # ABSOLUTE_MAX_LEVEL=3 RELATIVE_MAX_LEVEL=1 # Number of files into a class by default # NB_ITEMS_PER_CLASS=5 # Empty class # NO_DATA="No data to display" # the resource attribute string # RES="res=" # the syntax for a socket # SYNTAX="<ipaddress:port>" # to use the target/reclassify interface # IPV4="ipv4=" Usage(){ echo "Usage: $(basename $0) [[-v] <options>] without option, display the list of socketclass available. the syntax for a socket is $SYNTAX options description -v verbose mode -c [path/]socketclass_name [..] create a [list of] socketclass -d [path/]socketclass_name [..] delete a [list of] socketclass -f socket find the class_name of the socket -h -? --help display this help -i [path/]socketclass_name [..] display info/stats of the [list of] socketclass -l list all socketclass -l [path/]socketclass_name detailed socketclass information (shares) -m socket [path/]socketclass_name migrate/assign a socket into a socketclass -p display all socket per class -p [path/]socketclass_name display all socket of the socketclass -r to reclassify all sockets (all the socket) -r socket | [path/]socketclass_name to reclassify a socket or a socketclass " } # to handled -l and no option # List_all_sockets_and_exit(){ cd $SOCKETCLASS_DIR for ITEM in $(find . -type d) do # remove . and ./ DIR=$(echo $ITEM | cut -c 3-) if [ "$DIR" != "" ] then SOCKETS_LIST="$SOCKETS_LIST $DIR" fi done if [ "$SOCKETS_LIST" = "" ] then echo no socketclass available. else echo socketclass available : $SOCKETS_LIST fi exit 0 } # main # if [ ! -f $SOCKETCLASS_DIR/$MEMBERS ] then echo Sorry, cannot manage socketclass : CKRM is not initialized. exit 2 fi # no args : returns the list of socketclass available if [ $# = 0 ] then List_all_sockets_and_exit fi # search options in arguments # OPTIND and OPTARG are defined by getopts # while getopts "h?-:c:d:lprm:f:iv" option_name do case $option_name in h|'?') Usage exit 0 ;; -) # --help if [ $OPTARG = help ] then Usage exit 0 fi ;; c) # create a [list of] [path/]socketclass_name # skip the -v and -c options if [ $1 = -v ] then shift fi shift cd $SOCKETCLASS_DIR RC=0 while [ $# -ne 0 ] do if [ $1 = $DEFAULT_CLASS -o $1 = $SOCKETCLASS ] then echo $0 : cannot create the class by default. exit 2 fi if [ -d $1 ] then echo $0 : $1 already exist, cannot create. RC=2 else # relative -> absolute path if [ $(echo $1 | cut -c 1) = "/" ] then # absolute path : sanity check if [ $(dirname $1) != $SOCKETCLASS_DIR ] then echo $1 : bad path name. Please check the CKRM_RCFS_MOUNT_POINT echo variable in your environment. echo $0 : cannot create $1 - abort. exit 2 fi CLASS_PATH=$1 else CLASS_PATH=$SOCKETCLASS_DIR/$1 fi # no sub-level yet if [ $(echo $CLASS_PATH | sed 's/\// /g' | wc -w) -gt $ABSOLUTE_MAX_LEVEL ] then echo Hierarchie is limited to $RELATIVE_MAX_LEVEL : cannot create $1 RC=2 else mkdir $VERBOSE -p $CLASS_PATH echo $1 created. fi fi shift done exit $RC ;; d) # delete a [list of] [path/]socketclass_name # skip the -v and -d options if [ $1 = -v ] then shift fi shift cd $SOCKETCLASS_DIR RC=0 # the list of socketclass to delete SOCKETCLASS_TO_DELETE=$* while [ $# -ne 0 ] do if [ $1 = $SOCKETCLASS -o $1 = $DEFAULT_CLASS ] then echo $0 : cannot remove the socketclass by default. exit 2 else # relative -> absolute path if [ $(echo $1 | cut -c 1) = "/" ] then # absolute path : sanity check if [ $(dirname $1) != $SOCKETCLASS_DIR ] then echo $1 : bad path name. Please check the CKRM_RCFS_MOUNT_POINT echo variable in your environment. echo $0 : cannot remove $1 - abort. exit 2 fi CLASS_PATH=$1 else CLASS_PATH=$SOCKETCLASS_DIR/$1 fi if [ -d $1 ] then if [ $($BIN/ls $1 | wc -w) -eq $NB_ITEMS_PER_CLASS ] then # no sub-dir rmdir $VERBOSE $CLASS_PATH echo $1 removed. else echo -ne "remove $1 and all sub-classes ([y]/n) ? \c" read REP if [ "$REP" = n ] then echo $1 not removed. else rm $VERBOSE -rf $CLASS_PATH fi fi else # check if $1 is a parameter removed just before in this loop. # works for 2 levels only DIRNAME=$(dirname $1) if [ "$(echo $SOCKETCLASS_TO_DELETE | grep -w $DIRNAME)" = "" ] then RC=2 echo $0 : socketclass $1 does not exist, cannot remove. fi fi fi shift done exit $RC ;; l) # list socketclass information # skip the -v and -l options if [ $1 = -v ] then shift fi shift cd $SOCKETCLASS_DIR case $# in 0) # without parameter : list all socketclass name List_all_sockets_and_exit ;; 1) # display the socketclass=$1 with detailed information if [ $1 = $SOCKETCLASS -o $1 = $DEFAULT_CLASS ] then # special case : no shares file then do something useful cat $MEMBERS exit 0 fi if [ -d $1 ] then # temporary ? SOCKET_SHARES=$(cat $1/$SHARES) if [ "$SOCKET_SHARES" != "$NO_DATA" ] then echo $1 : $SOCKET_SHARES else cat $1/$MEMBERS fi exit 0 else echo $0 : socketclass $1 does not exist - abort. exit 2 fi ;; *) # echo $* : too many arguments - abort. exit 2 esac ;; p) # display the list of sockets per class # skip the -v and -p options if [ $1 = -v ] then shift fi shift cd $SOCKETCLASS_DIR case $# in 0) # display all sockets of all the class for DIR in $(find . -type d) do # remove . and ./ CLASS=$(echo $DIR | cut -c 3-) if [ "$CLASS" != "" ] then PIDS=$(cat $CLASS/$MEMBERS) if [ "$PIDS" != "$NO_DATA" ] then echo $CLASS : $PIDS fi fi done echo sockets in the class by default : cat $MEMBERS exit 0 ;; 1) # display all sockets of the specified class if [ $1 = $SOCKETCLASS -o $1 = $DEFAULT_CLASS ] then echo $(cat $MEMBERS) exit 0 fi if [ -d $1 ] then PIDS=$(cat $1/$MEMBERS) if [ "$PIDS" != "$NO_DATA" ] then echo $1 : $PIDS else echo $1 : socketclass is empty. fi exit 0 else echo $0 : socketclass $1 does not exist - abort. exit 2 fi ;; *) # echo $* : too many arguments - abort. exit 2 esac ;; r) # reclassify a socket or all sockets of a socketclass if [ ! -d $RULES_DIR ] then echo Sorry, CKRM rbce is not initialized. exit 2 fi # skip the -v and -r options if [ $1 = -v ] then shift fi shift cd $SOCKETCLASS_DIR case $# in 0) # without parameter reclassify all the sockets echo reclassify all the sockets # the current msg on the console echo socketclass: reclassify all not implemented yet echo 0 | cat > $RECLASSIFY exit 0 ;; 1) # check if $1 is a socketclass name # the current msg on the console echo socketclass: reclassify all not implemented yet exit if [ -d $1 ] then echo reclassify the socketclass $1 echo $1/$MEMBERS | cat > $RECLASSIFY exit 0 fi # or a valid socket for FILE in $(find . -name $MEMBERS) do if [ "$(grep -w $1 $FILE)" != "" ] then echo reclassify the socket $1 echo $1 | cat > $RECLASSIFY exit 0 fi done echo $0 : $1 is not a socket or a socketclass name - abort. exit 2 ;; *) # echo $* : too many arguments - abort. exit 2 esac ;; m) # migrate/assign a socket to a new class # skip the -v and -m options if [ $1 = -v ] then shift fi shift cd $SOCKETCLASS_DIR if [ $# -eq 2 ] then # check if $2 is a class name if [ ! -d $2 ] then echo $0 : $2 is not a socketclass name - abort. exit 2 fi # nothing to do ? if [ "$(grep -w $1 $2/$MEMBERS)" = $1 ] then echo $1 is already a member of the socketclass $2 exit 0 fi # a valid socket should be present into a members file for FILE in $(find . -name $MEMBERS) do if [ "$(grep -w $1 $FILE)" = $1 ] then echo migrate the socket $1 into the socketclass $2 echo "$IPV4$1" | cat > $2/$TARGET exit 0 fi done echo $0 : $1 is not a valid socket - abort. exit 2 else echo $* : bad argument number - abort. exit 2 fi ;; f) # find the [path/]class_name of a socket # skip the -v and -f options if [ $1 = -v ] then shift fi shift cd $SOCKETCLASS_DIR if [ $# -eq 1 ] then for FILE in $(find . -name $MEMBERS) do if [ "$(grep -w $1 $FILE)" = $1 ] then CLASS_NAME=$(dirname $FILE | cut -c 3-) if [ "$CLASS_NAME" = "" ] then CLASS_NAME="by default" fi echo socket $1 found into the socketclass $CLASS_NAME exit 0 fi done echo $1 not found. Please check the syntax : $SYNTAX echo $0 : $1 is not a socket. - abort. exit 2 else echo $* : bad argument number - abort. exit 2 fi ;; i) # display info/stats of a class # skip the -v and -i options if [ $1 = -v ] then shift fi shift cd $SOCKETCLASS_DIR case $# in 0) # without parameter, nothing to display echo Sorry, no info/stats by default. List_all_sockets_and_exit ;; *) # display info/stats of the specified class RC=0 while [ $# -ne 0 ] do if [ $1 = $DEFAULT_CLASS -o $1 = $SOCKETCLASS ] then echo Sorry, no info/stats by default. exit 2 fi if [ -d $1 ] then echo info/stats of the socketclass $1 cat $1/$STATS else echo $0 : $1 is not a socketclass name. RC=2 fi shift done exit $RC esac ;; v) # verbose VERBOSE=-v if [ $# -eq 1 ] then # nothing to do echo another option should be specified - abort. exit 0 fi ;; esac # exit 0 done # should never fails here echo $* : invalid parameter - abort. exit 2 ------------------------------------------------------- This SF.Net email is sponsored by Yahoo. Introducing Yahoo! Search Developer Network - Create apps using Yahoo! Search APIs Find out how you can build Yahoo! directly into your own Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005 _______________________________________________ ckrm-tech mailing list https://lists.sourceforge.net/lists/listinfo/ckrm-tech