If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Using functions in bash

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-06-04, 13:26
ducasio ducasio is offline
Registered User
 
Join Date: Aug 2004
Location: Rome, Italy
Posts: 81
Using functions in bash

I have a script whose content is mostly like this:

#!/bin/bash
......
.......
(
sqlplus -s <<EOF
$USER/$PASS
@sql_script1.sql
EOF
) 2>&1 | tee -a $LOGFILE | awk '/^ORA-[0-9]/ || /^SP2-[0-9]/ || /^TNS-[0-9]/ { match ($0, "^...-[0-9]*") ; print substr ($0, RSTART, RLENGTH) ; }' | while read oraerr
do
case $oraerr in
ORA-01017)
echo "\n I cannot connet: " 2>&1 |tee -a $LOGFILE
exit 1
;;
*)
echo "\n There are some errors: ($oraerr) " 2>&1 |tee -a $LOGFILE
exit 1
;;
esac
done

........................
........................

(
sqlplus -s <<EOF
$USER/$PASS
@${PATHSQL}/sql_script2
EOF
) 2>&1 | tee -a $LOGFILE | awk '/^ORA-[0-9]/ || /^SP2-[0-9]/ || /^TNS-[0-9]/ { match ($0, "^...-[0-9]*") ; print substr ($0, RSTART, RLENGTH) ; }' | while read oraerr
do
case $oraerr in
ORA-01017)
echo "\n I cannot connet: " 2>&1 |tee -a $LOGFILE
exit 1
;;
*)
echo "\n There are some errors: ($oraerr) " 2>&1 |tee -a $LOGFILE
exit 1
;;
esac
done


How can I put the sqlerror manipulation in function so i don't need to write it several times inside the script but I just call the function that manage the error.


Thank you in advance,
ducasio
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On