Hallo,
ich versuche mich an meinem ersten Shell-Skript über Hello World Niveau. Kann sich jemand dieses Skript ansehen und mir sagen, ob das gut aussieht oder grobe Fehler enthält? Vielen Dank!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #!/bin/bash export ORACLE_HOME=/samplepath/oracle export ORACLE_SID=SAMPLEDB export LD_LIBRARY_PATH=/samplepath/oracle2: export PATH=$PATH:$ORACLE_HOME/samplepath USER=sampleuser PASSWRD=samplepw SQLRETRY=5 # Amount of loops if sqlcheck fails # ExitCodes: # # 0 Successful # 1 Folder does not exist # 2 Process does not exist # 3 SQLPlus failed #Check if Path exist as definded in Variables CheckFolder(){ CheckFolderArray=($ORACLE_HOME $LD_LIBRARY_PATH $PATH) # Create Array to check all neccessary Paths for i in ${CheckFolderArray[@]}; do if [ ! -d "$i" ]; then exit 1 fi done return 0 } #Check if database processes exist pscheck() { CheckProcessArray=(process_${ORACLE_SID} process_${ORACLE_SID}) # Create Array to check all neccessary Processes for i in ${CheckProcessArray[@]}; do ps –fu userprocess | grep "$i" > /dev/null || return 2 done return 0 } #Check if connection to database is working, also insert sample data and delete sample. sqlcheck() { sqlplus –s /nolog << EOF whenever sqlerror exit 3 connect $USER/$PASSWRD insert into table sampletable values (‘abc’,123); delete from table sampletable; commit; exit 0 EOF return $? } #Check if CheckFolder is successful or exit with error 1 CheckFolder || exit 1 #Check if psschek is successful or exit with error 2 pscheck || exit 2 #Check if sqlcheck is successful or retry $SQLRETRY amount of times. exit with error 3 if not successful while [ i -lt $SQLRETRY ] do i=$[$i+1] sqlcheck() && exit 0 sleep 60 done exit 3 |
Bearbeitet von rklm:
Syntaxhighlighting. Bitte beachte Forum/Syntax!