-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathibmibashtemplate.sh
128 lines (114 loc) · 4.22 KB
/
ibmibashtemplate.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/QOpenSys/pkgs/bin/bash
#----------------------------------------------------------------
# Script name: ibmibashtemplate.sh
# Purpose: This is a starter bash template - Enter program desc/purpose here
# Parameters: See the usage() function
#----------------------------------------------------------------
#Blow up on any errors - Uncomment this for global error trapping
#set -e
PROGNAME=$(basename $0) #Capture base script name
# ----------------------------------------------------------------
# Functions
# ----------------------------------------------------------------
function usage() {
#----------------------------------------------------------------
# Function to show command line usage
#----------------------------------------------------------------
SCRIPT="$(basename -- $0)"
echo -e "\
Usage:\t$SCRIPT [options]
Desc: This is the purpose of the program
OPTIONS
-h, --help Display this help text
-l, --library IBM i library **required**
-f, --file IBM i source file **required**
-m, --member IBM i source member **required**
-d, --outputdir IBM i IFS output directory **required**"
}
print_cli_error() {
#----------------------------------------------------------------
# Function to print cli error
#----------------------------------------------------------------
echo -e "\e[31m$1\n\e[39m"
usage
exit 1
}
function error_exit
{
#----------------------------------------------------------------
# Function for exit due to fatal program error
# Accepts 1 argument:
# string containing descriptive error message
#----------------------------------------------------------------
echo "//-----------------------------------------------------------"
echo "//${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
echo "//-----------------------------------------------------------"
exit 1
}
# ----------------------------------------------------------------
# Loop to extract the command line parms and make sure all required are specified
# ----------------------------------------------------------------
for opts in "$@"
do
case $opts in
-h | --help) # Show command usage
usage
exit
;;
-l=*|--library=*)
LIBRARY="${opts#*=}"
shift # past argument=value
;;
-f=*|--file=*)
FILE="${opts#*=}"
shift # past argument=value
;;
-m=*|--member=*)
MEMBER="${opts#*=}"
shift # past argument=value
;;
-o=*|--outputdir=*)
OUTPUTDIR="${opts#*=}"
shift # past argument=value
;;
--default)
DEFAULT=YES
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
# ----------------------------------------------------------------
# Make sure required parms are specified. Bail out if not.
# ----------------------------------------------------------------
if [[ -z "$LIBRARY" || -z "$FILE" ||-z "$MEMBER" || -z "$OUTPUTDIR" ]]; then
# Output the required parm selected values for reference
echo "Current parameter values:"
echo "LIBRARY = $LIBRARY"
echo "FILE = $FILE"
echo "MEMBER = $MEMBER"
echo "OUTPUTDIR = $OUTPUTDIR"
ERROR="ERROR: Missing at least one required option"
REQUIRED="[-l,--library] [-f,--file] [-m,--member] [-o,--outputdir]"
print_cli_error "$ERROR\nRequired options: $REQUIRED"
fi
# Example inline START output to STDOUT for logging
STARTTIME=$(date)
echo "-----------------------------------------------------------"
echo "Start Listing source for library $LIBRARY/$FILE.$MEMBER to IFS dir $OUTPUTDIR - $(date)"
echo "-----------------------------------------------------------"
# Example iterating a file line by line
# Display the list by iterating through the text file
##while IFS= read -r line
##do
## echo "${line}"
##done < "$DIRLISTFILE"
# Example inline END output to STDOUT for logging
# TODO - Possibly add elapsed time if needed
ENDTIME=$(date)
echo "-----------------------------------------------------------"
echo "End Listing source for library $LIBRARY/$FILE.$MEMBER to IFS dir $OUTPUTDIR - $(date)"
echo "Start time: $STARTTIME : End time: $ENDTIME"
echo "-----------------------------------------------------------"