Peak Ram Usage


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Peak Ram Usage
# 1  
Old 10-06-2016
Linux Peak Ram Usage

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.

Last edited by rbatte1; 10-26-2016 at 01:13 PM.. Reason: Added ICODE tags for error
# 2  
Old 10-06-2016
This:
Code:
2>&1 1>&3)| {

is opening a code block and there is no closing brace.

At the start of this block these variables are initialised through read statements from stdin that is piped ( | ) into the code blok from the dialog command :

Code:
  read -r groups
  read -r date1
  read -r n
  read -r email

Outside the code block these variables do not retain their values (this is because a pipe construction | is used and in most shells this is executed in the background).

Since one or more of them or their derivatives is used in the last mailx command, which is used in a loop, there should be a single closing brace after this loop:

Code:
  done <"$DISKINFO"
}


Last edited by Scrutinizer; 10-06-2016 at 01:31 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 10-10-2016
Using gawk to read and manipulate multiple texts from a file

OS is AIX

The first part of the program check if the input of a particular date and group name exist in a text file. The input values need to match on that entire record in the text file. This process is similar to SQL where clause statement.

The second part of the program display an error message and exit the loop if there isn't a match or else continue if there is a match. The date format needs to change from mm/dd/yyyy to mm/dd/yy in the output of results. The input variable n limit the number of records that are displayed.

I'm getting an error message when I run my code. Error message: too many errors to read.

a) Input variables in the code are
Code:
        group=hasasvmi
        date1=09/29/2016
         n=1

b) The following is the data in the text file
Example 1: data in disk_2016.09.29.txt :

Code:
/dev/sasdwk/hasasvmi 128 1 127  0% /sasdwk/hasasvmi  2016.09.29_11.30.27

c) The following is an example of the results that I want to display:

Code:
Filesystem                 GBks Free Used used%    Mt                  DT         TM                                                                     
/dev/sasdwk/hasasvmi 128   1      127    0%  /sasdwk/hasasvmi 09/29/16  11:30


Code:
group=hasasvmi
date1=09/29/2016
n=1
|{
read "$group"
read "$date1"
read "$n"

DISKINFO=tail $n" k_%Y.%M.%D.txt

  while IFS='' read $line

      do

        group=hasasvmi
        date1=09/29/2016

       f1='grep ^"f1" $line | awk '{print $1}''
       f2='grep ^"f2" $line | awk '{print $2}''
       f3='grep ^"f3" $line | awk '{print $3}''
       f4='grep ^"f4" $line | awk '{print $4}''
       f5='grep ^"f5" $line | awk '{print $5}''
       f6='grep ^"f5" $line | awk '{print $6}''

       If  grp= echo( $grep "$group" "$line") &&
       f7= echo ('grep " $date1" | date2= (date +%m/%d/%Y | gawk  "$line" 'BEGIN {FS=". _" OFS="/"} {print $7}'')
       && f8= (date +"%H:%M" | gawk "line" 'BEGIN {FS="_ ." OFS="."} {print $7}'')
       Then
         continue
            printf '\tFileSystem%s\tGBks%d%s\t Free%d%s\tused%d %s\tused%%s\ tMt %s\ tDate%s\ tTime%s\n'     
                   "$f1" "$f2" "$f3" "$f4" "$f5"  "$f6" "$f7" 
        else
             echo '$grp ' doesn't exist (exit)|| echo  '$f7' doesn't match the date on file for'$grp' (exit)

    fi

done <"$DISKINFO"


Last edited by rbatte1; 10-26-2016 at 01:14 PM.. Reason: Added CODE tags for input variables
# 4  
Old 10-10-2016
Hi,

seems lot of issues here.

Code:
 2>&1 1>&3) | {

Code:
if [[$regex =~ date -d "$date1"]]

has to be ( note the space after [[ and before ]].
Code:
if [[ $regex =~ `date -d "$date1"` ]]

it has to be small one. case sensitive.
Code:
  Esac

what is the aim here ?
Below codes are incorrect, IMO.

Code:
 grp=(echo "$groups" | grep "$groups" "$DISKINFO")


Code:
 f8 = date +%T   "  | awk  'BEGIN {FS="_ ." OFS=":"} {print $f6}'

Code:
if[${date1}==${Date}] && [grp] THEN

and many more.

can you please have a close look line by line and go through basic tutorial such as thisone ?

After that you can come back with your questions later on, which will help you , when people explains about the issue/technical detail.
# 5  
Old 10-10-2016
Quote:
Originally Posted by dellanicholson
There are other issues with this program.
Yes.

I will point out the most obvious ones, but i wouldn't bet on having found all of them. The script is in a state which begs a rewrite anyway.

Code:
#!/bin/bash

You mentioned using AIX. The system shell is ksh, not bash. Use it!

Code:
Now=date + %M/%D/%Y

I suppose you want to use the date command to fill a variable there. This will fill the variable "Now" with the string "date" instead and the rest of the line will produce a syntax error. You do it this way (i have corrected the date-command too):

Code:
Now=$(date +"%M/%D/%Y")

Code:
while [[ -z $groups || -z $date1 || -z $n|| -z $email ]]; do

This is not ouright wrong, just dangerous. Suppose the variable groups has no content: this would leave the following command to be executed:

Code:
while [[ -z || -z $date1 || -z $n|| -z $email ]]; do

similar, if groups contains a space char:

Code:
while [[ -z foo bar || -z $date1 || -z $n|| -z $email ]]; do

and this, subsequently, will lead to a syntax error. If you query variables and their contents do it this way (notice the quoting):

Code:
while [[ -z "$groups" || -z "$date1" || -z "$n" || -z "$email" ]]; do

or, even more preferably, because being POSIX-compliant:

Code:
while [ -z "$groups" || -z "$date1" || -z "$n" || -z "$email" ] ; do

This will also not work:

Code:
 dialog --separate-widget $\n 
       --clear \

Notice the "n" at the end of the first line. When you continue a line with a backslash, it needs to be the absolutely last character in this line, because in fact you are escaping the following newline character with it. If there is another character (common problem: a space) after it, the backslash will escape that instead of the newline.

Code:
DISKINFO=tail -$n "/var/LV/$disk_'date +%Y.%H.%d'.txt"

Same as above, if you want a variable filled from a commands output you need to do it like this:

Code:
DISKINFO=$(tail -$n "/var/LV/$disk_$(date +"%Y.%H.%d").txt")


Code:
regex=/^[0-1][0-9]/[0-3][0-9]/[0-9]\{4\}$/
if [[$regex =~ date -d "$date1"]]

This won't work at all. First, "date -d" is not available in AIX (and in no other POSIX-compliant UNIX, because "-d" is not part of the POSIX standard). Since i cannot figure out what you are trying to achieve no suggestion for an alternative here, but explain what it should do and we probably find a solution.


Code:
if ! grep -q '$group' $DISKINFO ; then

almost correct. The problem is that variables ("$group") will not be expanded inside single quotes, only double quotes. And "grep" only works on files or streams, not on fixed strings:

Code:
if ! echo "$DISKINFO" | grep -q "$group" ; then


Finally: capitalisation is not arbitrary in UNIX. If a keyword is "else", it is supposed to be "else", not "Else", "ELSE" or anything else either (sorry for the pun). Likewise with all the other keywords: do, done, if, while, then, ...

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 6  
Old 10-10-2016
Quote:
Originally Posted by bakunin
Yes.

[..]
Code:
while [[ -z $groups || -z $date1 || -z $n|| -z $email ]]; do

This is not ouright wrong, just dangerous. Suppose the variable groups has no content: this would leave the following command to be executed:

Code:
while [[ -z || -z $date1 || -z $n|| -z $email ]]; do

similar, if groups contains a space char:

Code:
while [[ -z foo bar || -z $date1 || -z $n|| -z $email ]]; do

and this, subsequently, will lead to a syntax error. If you query variables and their contents do it this way (notice the quoting):
Code:
while [[ -z "$groups" || -z "$date1" || -z "$n" || -z "$email" ]]; do

Hi Bakunin, this is not right. Again, this is mixing up shell keywords ( which [[ ... ]] are) and a shell utility (which is the case with [ ... ]) . There really is no reason to use double quotes here, unless you want to combine whitespace separated fields (which is not the same as field splitting) or prevent pattern matching together with the == operator or regex matching together with the =~ operator (if available).

From man bash
Quote:
Word splitting and pathname expansion are not performed on the words between the [[ and ]]
and man ksh (both 88 and 93):
Quote:
Field splitting and file name generation are not performed on the words between [[ and ]]
Quote:
or, even more preferably, because being POSIX-compliant:
Code:
while [ -z "$groups" || -z "$date1" || -z "$n" || -z "$email" ] ; do

This syntax is incorrect and not part of POSIX. Correct POSIX syntax would be:
Code:
while [ -z "$groups" ] || [ -z "$date1" ] || [ -z "$n" ] || [ -z "$email" ]; do


Last edited by Scrutinizer; 10-10-2016 at 09:22 PM..
# 7  
Old 10-10-2016
Thank for your help. I want to get my code running. I realized I need to get the code working before adding the shell script code to zenity dialog i. Here is what I am trying to do


The first part of the code check if the input of a particular date and group name exist in a text file. The input values need to match on that entire record in the text file. This process is similar to SQL where clause statement.

The second part of the code display an error message and exit the loop if there isn't a match or else continue if there is a match. The date format needs to change from mm/dd/yyyy to mm/dd/yy in the output of results. The input variable n limit the number of records that are displayed.

I'm getting an error message when I run my code. Error message:
Code:
 too many errors to read

.

a) Input variables in the code are
Code:
group=hasasvmi
date1=09/29/2016
n=1

b) The following is the data in the text file
Example 1: data in disk_2016.09.29.txt :

Code:
/dev/sasdwk/hasasvmi 128 1 127  0% /sasdwk/hasasvmi  2016.09.29_11.30.27

c) The following is an example of the results that I want to display:



Code:
Filesystem                 GBks Free Used used%    Mt                  DT         TM                                                                     
/dev/sasdwk/hasasvmi 128   1      127    0%  /sasdwk/hasasvmi 09/29/16  11:30


Here is my code:

Code:
/bin/ksh
group=hasasvmi
date1=09/29/2016
n=1
|{
read "$group"
read "$date1"
read "$n"

DISKINFO=DISKINFO=$(tail -$n "/var/LV/$disk_$(date +"%Y.%H.%d").txt")

 WHILE IFS='' read $line

DO

        
       f1='grep ^"f1" $line | awk '{print $1}''
       f2='grep ^"f2" $line | awk '{print $2}''
       f3='grep ^"f3" $line | awk '{print $3}''
       f4='grep ^"f4" $line | awk '{print $4}''
       f5='grep ^"f5" $line | awk '{print $5}''
       f6='grep ^"f6" $line | awk '{print $6}''
       Date= $(date +%m/%d/%Y | gawk  "$line" 'BEGIN {FS=". _" OFS="/"} {print $7}'')
       Time= $(date +"%H:%M" | gawk "line" 'BEGIN {FS="_ ." OFS="."} {print $7}'')

  if[${date1}==${Date}] && [grp] THEN'

 printf '\tFileSystem%s\tGBks%d%s\t Free%d%s\tused%d %s\tused%%s\ tMt %s\ tDate%s\ tTime%s\n'     
                   "$f1" "$f2" "$f3" "$f4" "$f5"  "$Date" "$Time" 
     ELSE
             echo '$grp ' doesn't exist (exit)|| echo  '$f7' doesn't match the date on file for'$grp' (exit)

    fi

DONE <"$DISKINFO"
(



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 10-11-2016 at 04:28 AM.. Reason: Added CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Ubuntu 14.04 - how to less ram usage

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)
Discussion started by: baris35
2 Replies

2. UNIX for Dummies Questions & Answers

Average CPU and RAM usage for a process

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)
Discussion started by: koustubh
3 Replies

3. OS X (Apple)

RAM Usage discrepancy

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)
Discussion started by: dasx
2 Replies

4. Red Hat

High RAM usage, extremely low swapping

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)
Discussion started by: hedkandi
6 Replies

5. Solaris

Server RAM Usage checkup & support

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)
Discussion started by: Paarth
9 Replies

6. Linux

Ram Usage

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)
Discussion started by: treds
8 Replies

7. Shell Programming and Scripting

RAM usage Information

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)
Discussion started by: warlock129
1 Replies

8. UNIX for Dummies Questions & Answers

Command to check RAM usage

Hi Guys, How can i check the RAM usage for a particular user on the Linux machine. What command can be used. Thanks in advance, Swapna (1 Reply)
Discussion started by: Swapna173
1 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

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)
Discussion started by: alert0919
3 Replies

10. Solaris

RAM Physical Memory usage by each Process.

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)
Discussion started by: bsrajirs
12 Replies
Login or Register to Ask a Question