Please see this


Contents

- INDEX
- HP-UX Index
- Solaris
- Linux Index
- Other Unix types
- General Unix
- Unix Networking
- Unix Scripts
- Unix databases

Associated Information

- Unix Scripts Tips

Useful Links

- Bash shell HOWTO
- Bourne Shell Man Page
- C Shell Guide
- Korn Shell Resources

CopyDepot.sh

#!/usr/bin/sh # # CopyDepot : Copy patches/software to/from SW Depots # Can be run in preview (default) , execution or force mode # preview - don't perform copy but list commands that would br run # execution - perform swcopy and any other coomands (e.g. mkdir) # force - perform swcopy with enforce_dependencies=false # # TD - 27/04/99 # Set variables PREVIEW="${1:-yes}" # If yes - dummy run (preview), if no - do for real LOGFILE=/tmp/copy.commands # Commands echoed into here when preview mode if [ $# -ne 0 ]; then # determine if force mode to be used (enforce_dependencies set to false) if [ $1 = "-f" ]; then FORCE=yes fi fi if [ $PREVIEW = yes ]; then #----------------------------------------------------------------------------- # Default mode is preview - start of preview section #----------------------------------------------------------------------------- # Issue messages explaining preview mode echo "Executing in preview mode. No commands will be actioned" sleep 2 echo "Answer questions normally." sleep 2 echo "A list of commands that would be executed will be printed at the end" sleep 2 # clear logfile and write initial message echo "The following commands would be issued \n" > $LOGFILE # Ask questions echo "Enter the name of the depot you want to copy into: \c" read DEPOT echo "Enter the source depot name/device: \c" read SOURCE echo "Set to copy $SOURCE into $DEPOT" #--------------------------------------------------------------------------- # Checking Section - Check target and souce valid #--------------------------------------------------------------------------- for file in $SOURCE $DEPOT do if [ $file = $SOURCE ]; then if [ -d $file -o -c $file ]; then swlist -d @ $file > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "($file is not a SD/UX Depot. Would have to register it)\n" \ >> $LOGFILE echo "swreg -l depot $file" >> $LOGFILE fi else echo "ERROR: Source not valid. Copy would fail" >> $LOGFILE cat $LOGFILE exit 99 fi else if [ ! -d $file -o -c $file ]; then echo "(Depot $file does not exist, would have to create it)\n" \ >> $LOGFILE echo "mkdir $file" >> $LOGFILE fi fi done #--------------------------------------------------------------------------- # Preview processing section - work out what to copy and format copy command #--------------------------------------------------------------------------- echo "Enter a for all filesets, s to select filesets" echo "Or anything else to quit: \c" read REPLY case $REPLY in a) SELECT="\*" ;; s) echo "Would you like to see the contents of the depot[y/n]\c" read REPLY2 if [ "$REPLY2" = y -o "$REPLY2" = Y ]; then swlist -d @ $SOURCE > /tmp/list.$$ more /tmp/list.$$ fi REPLY3=null SELECT="" until [ "$REPLY3" = e ] do echo "Enter product required or e to end: \c" read REPLY3 if [ "$REPLY3" != e ]; then SELECT="$SELECT $REPLY3" fi done ;; *) echo "Exiting..." exit 0 ;; esac # Copy command would be as below echo "swcopy -s $SOURCE $SELECT @ $DEPOT" >> $LOGFILE # Show all commands that would be issued cat $LOGFILE #----------------------------------------------------------------------------- # Execution mode - execute commands for real and perform copy #----------------------------------------------------------------------------- else # Ask questions to find out source and target DEPOTOK=no SOURCEOK=no # Keep looping round until a valid source and target specified until [ $SOURCEOK = yes -a $DEPOTOK = yes ] do if [ $DEPOTOK = no ]; then echo "Enter the name of the depot you want to copy into: \c" read DEPOT fi if [ $SOURCEOK = no ]; then echo "Enter the source depot name/device: \c" read SOURCE fi #------------------------------------------------------------------------- # Check target and souce valid #------------------------------------------------------------------------- echo "Checking $SOURCE and $DEPOT" for file in $DEPOT $SOURCE do if [ $file = $SOURCE ]; then if [ -d $file -o -c $file ]; then swlist -d @$file > /dev/null 2>&1 if [ $? -eq 0 ]; then SOURCEOK=yes fi else echo "$file not SD/UX Depot. Would you like to resiter it?[y/n]\c" read ANS if [ "$ANS" = Y -o "$ANS" = y ];then swreg -l depot $file if [ $? -ne 0 ]; then echo "ERROR: Couldn't register depot $file" exit 2 fi else echo "This script only copies from SD/UX format depots. Exiting...." exit 1 fi fi else if [ ! -d $file -o -c $file ]; then echo "Depot does not exist, would you like to create it?[y/n]\c" read ANS2 if [ "$ANS2" = Y -o "$ANS2" = y ]; then mkdir $file if [ $? -eq 0 ]; then DEPOTOK=yes fi else echo "This script only copies to SD/UX format depots" echo "Or empty directories. Exiting...." exit 3 fi else DEPOTOK=yes fi fi done done #--------------------------------------------------------------------------- # Select what to copy - locations OK so specify what needs copying #--------------------------------------------------------------------------- echo "Enter a for all filesets, s to select filesets" echo "Or anything else to quit: \c" read REPLY case $REPLY in a) # Copy whole depot SELECT="\*" ;; s) # Select what filesets to copy echo "Would you like to see the contents of the depot[y/n]\c" read REPLY2 if [ "$REPLY2" = y -o "$REPLY2" = Y ]; then swlist -d @ $SOURCE > /tmp/list.$$ more /tmp/list.$$ fi REPLY3=null SELECT="" until [ "$REPLY3" = e ] do echo "Enter product required or e to end: \c" read REPLY3 if [ "$REPLY3" != e ]; then SELECT="$SELECT $REPLY3" fi done ;; *) # quit script selected echo "Exiting..." exit 0 ;; esac # If force option used set OPTIONS variable (more options can be added here) if [ "$FORCE" = yes ]; then OPTIONS="-x enforce_dependencies=false" else OPTIONS="" fi #--------------------------------------------------------------------------- # Perform the copy #--------------------------------------------------------------------------- swcopy $OPTIONS -s $SOURCE $SELECT @ $DEPOT if [ $? != 0 ]; then echo "ERROR: Copy failed. Exiting...." # Tidy up rm /tmp/list.$$ > /dev/null 2>&1 exit 4 fi # Tidy up rm /tmp/list.$$ > /dev/null 2>&1 fi #### END OF SCRIPT

Copyright 2000 Intronet Computers Ltd
Email: Intronet Computers for enquiries