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.
Code:
#!/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.
Hi All,
I am trying to find the physical memory usage by each process/users.
Can you please let me know how to get the memory usage?.
Thanks,
bsraj. (12 Replies)
how can I find cpu usage memory usage swap usage and
I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times
my final destination is monitor process
logical volume usage above X % and number of Logical voluage above
can I not to... (3 Replies)
Hi i just wanted to know what is the code to display amount of RAM and also the percentage used? I know i can possibly use the vmstat code but what part indicates the RAM? Any help would be much appreciated. Thanks (1 Reply)
Hi
one of our applications that runs on our Linux server leaks memory resulting in Ram that was used by the program not being released back to the operating system once a file has been processed. the result is over a very short period virtual all the memory has been used. an example currently
... (8 Replies)
Hi RAM of my system is 24 GB however when i checked the processes pids and counted the memory usage by pmap i found out that the total memory usage is 36 GB
It s obvious that my system might be using some of virtual memory or swap space . How can i check which memory it is using and how ..
... (9 Replies)
Hi team
I have three physical servers running on Red Hat Enterprise Linux Server release 6.2 with the following memory conditions:
# cat /proc/meminfo | grep -i mem
MemTotal: 8062888 kB
MemFree: 184540 kB
Shmem: 516 kB
and the following swap conditions:
... (6 Replies)
Hey there! I'm a new user here who registered because I couldn't get these kind of questions answered in the place I directly com from. :o
I've found a discrepancy in total RAM used and I can't figure out why it is. My only guess is there are some RAM used by some stuff impossible to identify,... (2 Replies)
Hi,
I will be creating a process myself and I want to know the average CPU and RAM used by the process over the lifetime of the process. I see that there are various tools available(pidstat) for doing , I was wondering if it possible to do it in a single command while creation.
Thanks in... (3 Replies)
Hello,
I have an ubuntu14.04 installed pc with 32GB ram.
Operating System: Ubuntu 14.04.5 LTS
Kernel: Linux 4.9.148-xxxx-std-ipv6-64
Architecture: x86_64
When I check free memory it shows:
total used free shared buffers cached
Mem: 31882 ... (2 Replies)