文件操作 - vmdeploy.sh
返回文件管理
返回主菜单
删除本文件
文件: /opt/dell/srvadmin/share/srvadmin-rac5/vmdeploy.sh
编辑文件内容
#!/bin/sh # ----------------------------------------------------------------------------- # # DELL COMPUTER CORPORATION PROPRIETARY INFORMATION # # This software is supplied under the terms of a license agreement or # nondisclosure agreement with Dell Computer Corporation and may not # be copied or disclosed except in accordance with the terms of that # agreement. # # Copyright (c) 2005-present Dell Computer Corporation. All Rights Reserved. # # Script Name: vmdeploy.sh # # Purpose: sample script to illustrate OS/patch deployment via Virtual Media. # NOTE: the boot image supplied to this script performs the deployment. # [ie. the boot image determines what/how deployment is done] # ----------------------------------------------------------------------------- SCRIPT=${0##*/} RC=0 PASS=0 # count successes/failures, report later FAIL=0 DBUG=0 VMDELAY=10 # expected max. Virtual Media connect time (seconds) PID=$$ DATETIME=`date +%Y%m%d.%H%M%S` LOGPATH=$(mktemp -d /tmp/.${SCRIPT%.sh}-XXXXXX) trap 'rm -rf $LOGPATH' QUIT HUP INT TERM EXIT ERR EXITING=0 NOKILL=0 CLEANUP="$LOGPATH/.$PID-CLEANUP" # to track things needing cleanup # --- console/log printing function printcon { echo -e "$@" [ -n "$CONLOG" ] && echo -e "$@" >>$CONLOG } function usage { # ------------------------------------------------------------------------- # if usage is passed an argument, it's an error message: print it & return. # else, print the usage text and exit # ------------------------------------------------------------------------- if [ $# -gt 0 ]; then FAIL=$((FAIL + 1)) printcon "\aerror($FAIL): $@" else printcon "\nusage: $SCRIPT -r<RAC-IP> -u<RAC-userid> -p<RAC-password> -i<DeviceID>" printcon " [ -f<floppy-image> | -c<ISO9660-image> ]" printcon "where:" printcon " <ISO9660-image> and <floppy-image> are bootable image files" printcon " <RAC-userid> = RAC user id, with 'virtual media' privilege" printcon " <RAC-password> = RAC user password" printcon " <RAC-IP> is either:" printcon " - a string of the form: 'RAC-IP_or_hostname[:SSL-port]'" printcon " - a file containing lines matching that form" printcon " In the latter case, the boot image is setup and booted" printcon " for each host/RAC IP contained in the file.\n" printcon " <DeviceID> = ID of Device to bootonce into" printcon " where DeviceID:" printcon " 0 = Disable - Disable this option" printcon " 1 = Virtual Flash/Virtual Media - Boot from virtual flash or virtual media device" printcon " 2 = Virtual Floppy - Boot from virtual Floppy device" printcon " 3 = Virtual CD/DVD/ISO - Boot from virtual CD/DVD/ISO device" printcon " 4 = PXE - Boot from network (PXE)" printcon " 5 = Hard Drive - Boot from the default Hard Drive" printcon " 6 = Utility Partition - Boot into the Utility Partition \n\t\t(NOTE: The Utility Partition should exist)" printcon " 7 = Default CD/DVD - Boot from the default CD/DVD drive" printcon " 8 = BIOS Setup - Reboot to the BIOS Setup screen" printcon " 9 = Primary Removable Media - Boot to the primary removable media\n" printcon "*Note: your boot image determines what is deployed, and how.\n" EXITING=1 exit $RC fi } # --- termination handler function quit { if [ $EXITING -eq 0 ]; then EXITING=1 RC=99 [ $# -ge 1 ] && printcon "\a\n$@\n" fi # ------------------------------------------------------------------------- # if this script is interrupted, any running tasks it spawned are terminated. # to change this default behavior, set NOKILL=1 at the top of this script. # then, any work started prior to the interruption is allowed to complete. # ------------------------------------------------------------------------- if [ -e $CLEANUP -a $NOKILL -eq 0 ]; then printcon "Cleaning up, please wait.." while read do # we're dying unexpectedly.. if [ -e "$REPLY" ]; then rm -f $REPLY # cleanup: delete log file else kill $REPLY && sleep 3 # cleanup: kill process fi done <$CLEANUP rm -f $CLEANUP fi exit $RC } # --- hook for unplanned termination trap "quit \"$SCRIPT interrupted!!\"" EXIT # --- parse command arguments if [ $# -gt 0 ]; then TEMP=`getopt -o r:u:p:f:c:i:d -- "$@"` RC=$? if [ $RC -eq 0 ]; then eval set -- "$TEMP" while true do case "$1" in -d) set -x; DBUG=1; VMOPTS="-v"; shift 1 ;; -f) [ -n "$TYPE" ] && TYPE="?" || TYPE="-f"; FILE=$2; shift 2 ;; -c) [ -n "$TYPE" ] && TYPE="?" || TYPE="-c"; FILE=$2; shift 2 ;; -p) RACP=$2; shift 2 ;; -u) RACU=$2; shift 2 ;; -i) DEVID=$2; shift 2 ;; -r) LIST=$2; shift 2 ;; --) shift; break ;; *) RC=8; break ;; esac done fi fi # --- validate command arguments [ $RC -gt 0 ] && usage "invalid options found" [ -z "$LIST" ] && usage "<RAC-IP> missing" [ -z "$RACU" ] && usage "<RAC-userid> missing" [ -z "$RACP" ] && usage "<RAC-password> missing" [ -z "$DEVID" ] && DEVID=1 [ ".$TYPE" = ".?" ] && usage "use <floppy-image> or <ISO9660-image>, not both" if [ -z "$FILE" ]; then usage "an image file is required" elif [ ! -e "$FILE" ]; then usage "no such image file: '$FILE'" fi # --- ensure RAC utilities available if [ -z "`which racadm 2>/dev/null`" ]; then usage "racadm doesn't appear to be installed" fi if [ -z "`which racvmcli 2>/dev/null`" ]; then usage "racvmcli doesn't appear to be installed" fi [ $FAIL -gt 0 ] && usage # error(s) ? quit now # --- check for writable floppy image if [ ".$TYPE" = ".-f" -a -w $FILE ]; then printcon "\n**warning: <floppy-image> appears to be writable." printcon " Enter 'q' now to quit, any other key to continue.." read RESP if [ ".$RESP" = ".q" -o ".$RESP" = ".Q" ]; then printcon "\nOK, quitting.. (good choice)" EXITING=1 exit 0 fi fi # --- OK, "let's roll" mkdir $LOGPATH >/dev/null 2>&1 # create directory for this run CONLOG=$LOGPATH/console.log # setup the console log file if [ ! -e "$LIST" ]; then # single RAC IP provided.. tmpfile="$LOGPATH/.iplist" # ..create a temp file echo "$LIST" >$tmpfile # ..add the single RAC IP echo "$tmpfile" >>$CLEANUP # ..mark it for cleanup LIST=$tmpfile fi # RAC 'boot once' property BOPROP="-g cfgRacVirtual -o cfgVirtualBootOnce $DEVID" while read # for each RAC IP/hostname: do IP=${REPLY%%[[:space:]]*} [ -z "$IP" -o -z "${IP##\#*}" ] && continue # (skip blank/comment lines) MSG=`echo y | racadm -r $IP -u $RACU -p $RACP config $BOPROP 2>&1` CC=$? echo $MSG | grep "ERROR" >/dev/null 2>&1 if [ $CC -ne 0 -o $? -eq 0 ]; then printcon "$MSG" CONN=0 # failed to set RAC 'boot once' property break fi IP=${REPLY%%[[:space:]]*} [ -z "$IP" -o -z "${IP##\#*}" ] && continue # (skip blank/comment lines) printcon "\nIP = $IP" tmpfile="$LOGPATH/log.$IP" # VM process logfile name (includes RAC IP) # ideally, at this point we'd check for the appropriate boot device # at top of boot list for the target server (or set it thus). # currently, we can't :( # fire off a virtual media process for the target server racvmcli -r$IP -u$RACU -p$RACP ${TYPE}${FILE} $VMOPTS >$tmpfile 2>&1 & VMPID=$! printcon "\tVM PID = $VMPID" # ensure the virtual media process connects successfully. # (check periodically, so we don't always incur the max delay) CONN=0 for ((i=0; i<$VMDELAY; i++)) { sleep 1 grep "connected" $tmpfile >/dev/null 2>&1 if [ $? -eq 0 ]; then CONN=1 # we're connected printcon "\tconnected" break; fi } # once connected, use racadm to set 'boot once', and reboot the host server. # if we cannot do these actions, we cannot deploy to this host while [ $CONN -eq 1 ] do printcon "\tpreparing target server for reboot.." #MSG=`echo y | racadm -S -r$IP -u$RACU -p$RACP config $BOPROP TRUE 2>&1` #CC=$? #echo $MSG | grep "ERROR" >/dev/null 2>&1 #if [ $CC -ne 0 -o $? -eq 0 ]; then printcon "$MSG" # CONN=0 # failed to set RAC 'boot once' property # break #fi # ideally, at this point we'd check the target host's power-on status # currently, we can't :( # so: first try power-cycling the server (fails if server is already off). # this shuts a running OS down more gracefully than a hard reset would sleep 10 MSG=`echo y | racadm -r$IP -u$RACU -p$RACP serveraction powercycle 2>&1` if [ $? -ne 0 ]; then echo $MSG | grep "already powered off" >/dev/null 2>&1 if [ $? -ne 0 ]; then printcon "$MSG" CONN=0 # powercycle failed, for unknown reasons else # OK, server already powered off, just power it on MSG=`echo y | racadm -r$IP -u$RACU -p$RACP serveraction powerup 2>&1` if [ $? -ne 0 ]; then printcon "$MSG" CONN=0 # powerup failed fi fi fi break done if [ $CONN -eq 1 ]; then # deployment is underway / host booting up echo "$VMPID" >>$CLEANUP # ..mark the VM process ID for cleanup echo $tmpfile >>$CLEANUP # ..ditto for the VM process logfile PASS=$((PASS + 1)) printcon "\tOK." # ---------------------------------------------------------------------- # NOTE: # # Once the deployment is complete, the Virtual Media session should be # disconnected using the following command for each system/IP: # # racadm -r <RAC IP> -u <username> -p <password> vmdisconnect # # ---------------------------------------------------------------------- else # ---------------------------------------------------------------------- # deployment failed, for this RAC host: # - kill the Virtual Media process # - save the RAC IP in the 'failed-hosts' file # NOTE: we never clean up logs for failed hosts -- must be done manually # ---------------------------------------------------------------------- kill $VMPID >/dev/null 2>&1 echo "$IP" >>$LOGPATH/failed-hosts FAIL=$((FAIL + 1)) printcon "\tFAILED -- see '$tmpfile'" fi done < $LIST # --- normal completion: if we get here, don't terminate any work we started. # (all files in the LOGPATH directory are left alone, for admin perusal) NOKILL=1 EXITING=1 printcon "\n$PASS deployment tasks started successfully." printcon "$FAIL deployment tasks failed." if [ $FAIL -gt 0 ]; then printcon "\nNote: the failed RAC IPs are in file '$LOGPATH/failed-hosts'" printcon " Check the individual process logfiles for more information" printcon " (for IP=XX, it's logfile is '$LOGPATH/log.XX')" fi printcon "\nThe console log was saved as '$CONLOG'." exit 0
修改文件时间
将文件时间修改为当前时间的前一年
删除文件