grpdsku program allows user to check their group disk space in a server environment. The data in the dialog box queries a text file. Each text file is labeled with a current timestamp. Results output to a msgbox. Also, results output to a csv file. The csv file is sent to the user via email
When running the program, I am getting error } missing
. I check each open and close bracket and found no issue. There are other issues with this program. The dialog forms aren't creating and generating output. I appreciate any help you can give me. I have attached a document that explains the program process in more detail.
#!/bin/bash
# grpdsku.sh - A shell script to display the form dialog on screen
DIALOG_CANCEL=1
DIALOG_ESC=255
HEIGHT=0
WIDTH=0
display_result() {
dialog --title "$1" \
--no-collapse \
--msgbox "$result" 0 0
}
while true; do
Now=date + %M/%D/%Y
groups=""
date1=" "
n=""
email=""
# open fd - fields can't be empty,
error_message=
IFS=$'\n'; set -f
while [[ -z $groups || -z $date1 || -z $n|| -z $email ]]; do
set $(dialog � --form="creating new $error_message" � --output-fd=3 3>&1 >/dev/tty)
groups=$1 date1=$1 n=$1 email=$1
error_message="(fields must not be empty)"
done
unset IFS; set +f
# Store data to variable - data entry form for users
dialog --separate-widget $\n
--clear \
--ok-label "Submit" \
--cancel-label "Exit" \
--backtitle "SAS Managment" \
--title "Disk Space" \
--form "Disk Optimization" \15 50 0 \
"Enter groupname :" 1 1 "$groups" 1 10 30 0 \
"Enter current date (09/30/2016):" 2 1 "$date1" 2 10 10 0 \
"Enter the number records [1-30 or F]:" 3 1 "$n" 3 10 10 0 \
"Enter email:" 4 1 "$email" 4 10 60 0 \
2>&1 1>&3)| {
read -r groups
read -r date1
read -r n
read -r email
#-----read in the current timestamp text file----------
DISKINFO=tail -$n "/var/LV/$disk_'date +%Y.%H.%d'.txt"
#----check date format for example 09/30/2016---------------
regex=/^[0-1][0-9]/[0-3][0-9]/[0-9]\{4\}$/
if [[$regex =~ date -d "$date1"]]
then
echo $date1 NOT a valid mm/dd/yyy date
fi
#---------------if group name isn't in text file then display error message--
if ! grep -q '$group' $DISKINFO ; then
echo $group Not found.
ELSE
continue
fi
---------exit and continue shell scripting-----
exit_status=$?
# close fd
exec 3>&-
case $exit_status in
$DIALOG_CANCEL)
clear
echo "Program terminated."
exit
;;
$DIALOG_ESC)
clear
echo "Program aborted." >&2
exit 1
;;
Esac
# display values just entered
#match the group name the input to the group name in the text file, for example, hasasvmi
grp=(echo "$groups" | grep "$groups" "$DISKINFO")
#--------read in text file line by line. Print and format date and time---------
while IFS='' read -r f1 f2 f3 f4 f5 f6
do
f7= date +%m/%d/%Y | awk 'BEGIN {FS=". _" OFS="/"} {print $6'}'
f8 = date +%T " | awk 'BEGIN {FS="_ ." OFS=":"} {print $f6}'
#---if field f4 is null or has a dash then add 0.0%---------------------
if [${f4} eq'' || ${f4} eq '-'] Then ${f4} eq'0.0%'
fi
done
#----if the date from the input form matches the date from the text file and group name then print the fields
fi
do
if[${date1}==${Date}] && [grp] THEN
# display fields using f1, f2,..,f8
echo result =( printf '\tFileSystem%s\tSize%d%s\tAvail%d%s\tused(GB,KB,MB)%d %s\tuse% %s\ tMounted on %s\ tDate%s\ tTime%s\n' "$f1" "$f2" "$f3" "$f4" "$f5" "$f6" "$f7" "$f8")
fi
display_result "Disk Space used by $group"
#------print result output to a csv file. CSV File is group label--------
"$result" > $group.csv
#---------csv file is sent via email to user-----------------
[ -s group.csv ] && mailx -s "subject text" -a "$group.csv" "$email" < "Disk space used by $group "
done <"$DISKINFO"
Group name Group name current date: 09/30/2016
Example 2: output
from disk_2016.09.29.txt :
Below is how I want the output results to be displayed in
a csv file and on screen. The output must have headers. Date,and time must be
formatted. Columns must be aligned
correctly.