-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewbashscript
More file actions
243 lines (200 loc) · 6.45 KB
/
newbashscript
File metadata and controls
243 lines (200 loc) · 6.45 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/bash
Tmp=/tmp/$$
Tmp0=/tmp/$$_$$
Tmp1=/tmp/$$_$$_$$
Tmp2=/tmp/$$_$$_$$_$$
Tmp3=/tmp/$$_$$_$$_$$_$$
trap 'exit 0' INT HUP QUIT TERM ALRM USR1
trap 'rm -f "$Tmp" "$Tmp0" "$Tmp1" "$Tmp2" "$Tmp3"' EXIT
rm -f "$Tmp $Tmp0 $Tmp1 $Tmp2 $Tmp3" >/dev/null 2>&1;
UPDATE="NO"
while getopts "ur:" arg
do
case $arg in
u) UPDATE="YES"
r) UA="$OPTARG"
exit 0
;;
esac
done
shift $(($OPTIND - 1))
if [ "$UPDATE" == "YES" ]; then
RETVAL="YES"
else
RETVAL="NO"
fi
#================================================================
# HEADER
#================================================================
#% SYNOPSIS
#+ ${SCRIPT_NAME} [-hv] [-o[file]] args ...
#%
#% DESCRIPTION
#% This is a script template
#% to start any good shell script.
#%
#% OPTIONS
#% -o [file], --output=[file] Set log file (default=/dev/null)
#% use DEFAULT keyword to autoname file
#% The default value is /dev/null.
#% -t, --timelog Add timestamp to log ("+%y/%m/%d@%H:%M:%S")
#% -x, --ignorelock Ignore if lock file exists
#% -h, --help Print this help
#% -v, --version Print script information
#%
#% EXAMPLES
#% ${SCRIPT_NAME} -o DEFAULT arg1 arg2
#%
#================================================================
#- IMPLEMENTATION
#- version ${SCRIPT_NAME} 0.0.1
#- author MJE
#- copyright Copyright (c) All Rights Reserved
#- license All Rights Reserved
#- script_id 0.0.1
#-
#================================================================
# HISTORY
# 2024/11/15 : MJE : Script creation
#
#================================================================
# DEBUG OPTION
# set -n # Uncomment to check your syntax, without execution.
# set -x # Uncomment to debug this shell script
#
#================================================================
# END_OF_HEADER
#================================================================
#== needed variables ==#
SCRIPT_HEADSIZE=$(head -200 ${0} |grep -n "^# END_OF_HEADER" | cut -f1 -d:)
SCRIPT_NAME="$(basename ${0})"
#== usage functions ==#
usage() { printf "Usage: "; head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#+" | sed -e "s/^#+[ ]*//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g" ; }
usagefull() { head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#[%+-]" | sed -e "s/^#[%+-]//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g" ; }
scriptinfo() { head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#-" | sed -e "s/^#-//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g"; }
cat xxx | grep "yyy" | gawk '
BEGIN {
NOTHING=0
}
//{
}
END {
NOTHING=0
}'
# Check if a file exists
if [ -f "/path/to/your/file" ]; then
echo "File exists."
else
echo "File does not exist."
fi
# Check if a directory exists
if [ -d "/path/to/your/directory" ]; then
echo "Directory exists."
else
echo "Directory does not exist."
fi
# Check if input file is provided
if [ -z "$1" ]; then
echo "Usage: `basename "$0"` <input_file>"
exit 1
if
# filename munging
input_file="$1"
output_file="${input_file%.*}.html"
cat "$input_file" | sed '/^$/d' | sort | uniq > $Tmp; cp $Tmp "$input_file"
line_count=$(wc -l < "$input_file")
half_lines=$((line_count / 3))
# ifs
if [ "$num" -eq 2 ]; then
isnfs () {
LOCAL=`stat -f -c %T "$1"`
if [ "$LOCAL" == "nfs" ]; then
RETVAL="YES"
else
RETVAL="NO"
fi
}
consolebar () {
echo "********************************************************************************************"
}
consolemsg () {
# consolebar
echo "** $1"
# consolebar
A=$A
}
optconsolemsg () {
# echo "** $1"
A=$A
}
while getopts "ha:" arg
do
case $arg in
h) usagefull;
exit 0;
;;
a) A="$OPTARG"
exit 0
;;
esac
done
shift $(($OPTIND - 1))
# +===================================================================================================+
# +===================================================================================================+
# -a file file exists
# -d file file exists and is a directory
# -f file file exists and is an ordinary file
# -r file file exists and is readable
# -s file file exists and has a size greater than 0
# -w file file exits and is writable
# -x file file exists and is executable
# -L file file exists and is a symbolic link
# -O file file exists and owned by user file1 i
# -nt file2 file1 exists and is newer than file2 file1
# -ot file2 file1 exists and is older then file
#
# if [ ! -d "$DIRECTORY" ]; then
# echo "The directory [$DIRECTORY] does not exist."
# exit 0
# fi
#
# 0 - Normal Style (reset)
# 1 - Bold
# 2 - Dim
# 3 - Italic
# 4 - Underlined
# 5 - Blinking
# 7 - Reverse
# 8 - Invisible
# 30 - BLACK
# 31 - RED
# 32 - GREEN
# 33 - YELLOW
# 34 - BLUE
# 35 - PURPLE
# 36 - CYAN
# 37 - WHITE
# bold=$(printf '\033[%sm' "4")
# reset=$(printf '\033[%sm' "0")
#
# cat <<USAGE_TEXT
#
# USAGE_TEXT
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#