Help with variables for filesystems allocated


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with variables for filesystems allocated
# 1  
Old 07-09-2009
Question Help with variables for filesystems allocated

Hi all,
I am interning in a unix department and am very new to programming. I am supposed to write a script that counts the amount of filesystems a server has allocated, and the amount free. This is what I was given to start with:

#!/bin/ksh
df -m | grep -v ":"|grep -v Free|grep -v "/proc"| while read FSYSTEM BLKS FREE USED IUSED PERIUSED MOUNTEDON
#set -x
HOST=`hostname`
do
(( INUSE = $BLKS - $FREE ))
echo $HOST $MOUNTEDON $BLKS $FREE InUse= $INUSE
done

I am very new and not much of this makes sense. I was told that i would need to have to add a couple more variables which would show the total filesystems free, and allocated. Any help is appreciated. Thanks.
# 2  
Old 07-09-2009
Im very tempted to reply by giving clues and where to look since you are very new to UNIX
(how much is very new? - Why did you not post something in dummies then?)
1) Learning the hard way! (but then Im sure you will have learned alot by the time you finished...)
- a - Start by reading the script and look at all words that seem to be unix commands, the look what tha manuals say : man <command> e.g. man df
- b- Uncomment (remove the #) the line set -x and place it after the first line (To undestand this part, its man sh or ksh...)
- c - Run the script, and see what it does...
- d - Modify the script to see what happens (e.g. remove grep -v Free|... and again something else etc...)
- e - If you did not make a copy before, you are now doomed... (ask your collegues for the script again...) Now you shou have an alomst clear understanding of what is going on, if not post here in dummies what you executed, the result and what you dont understand...
.
.
- f - Try to figure out how you will have to modify your script to achieve the requested task and do it.
- G - Come back here with your freshly written script explaining what you wanted to do, the result you got, and explain your issue.
We will gladly comment your work, your progress in understanding, and hopefully assist you through the debugging of now your own script
So courage!
..
Waiting to see your first question...

---------- Post updated at 18:18 ---------- Previous update was at 18:17 ----------

Should I bother for
2) ?

---------- Post updated at 18:40 ---------- Previous update was at 18:18 ----------

2) You could start by comparing the output of df -m versus your script then figure out what is missing...(in both cases in regard of the appointed given task...)

Last edited by vbe; 07-09-2009 at 01:32 PM.. Reason: errata
# 3  
Old 07-09-2009
Very new meaning that I have jumped into this with no background experience and am trying getting my feet wet. I'm pretty much learning as I go and seeing if this is a field i would like to pursue.

ok, i have rearranged the script a little bit. I have left in the comment for set -x because it seems that the information is a little more organized for me that way. This is what I have right now:

#!/bin/ksh
#set -x
df -m | grep -v ":"|grep -v Free|grep -v "/proc"| while read FSYSTEM BLKS FREE USED IUSED PERIUSED MOUNTEDON
HOST=`hostname`
do
(( INUSE = $BLKS - $FREE ))
echo $FSYSTEM $BLKS $FREE InUse= $INUSE $MOUNTEDON



This returns:
/dev/hd4 1024.00 966.48 InUse= 58 /
/dev/hd2 3392.00 288.55 InUse= 3104 /usr
/dev/hd9var 2048.00 1976.50 InUse= 72 /var
/dev/hd3 2048.00 1834.10 InUse= 214 /tmp
/dev/hd1 1536.00 698.94 InUse= 838 /home
/dev/hd10opt 1024.00 556.55 InUse= 468 /opt
/dev/fslv00 30720.00 13025.69 InUse= 17695 /aix52_save_s
/dev/fslv01 1024.00 1023.52 InUse= 1 /var/adm/perf
/dev/nmon_lv 1600.00 1584.06 InUse= 16 /nmondata
comnascript.ksh[6]: INUSE = - : 0403-053 Expression is not complete; more tokens expected.

Now my first question, is how would I be able to separate this info into easier to read columns. Also how can i add the titles as the first line?

A variable that i believe i have to use is something for the entire server. I would need to have the script calculate the totals from "InUse" and "FREE" and have that echo back at the end. I hope this makes sense and thank you for your time.
# 4  
Old 07-09-2009
My understanding of the appointed task (but then I may be wrong - I speak french ordinarily... and so forgive my spelling and curious syntax...) was :
Count how many filesystems are on the host and how much free space is left ( per filesystem or globally?)
It could be display as the script does and add an extra line where you cumulate the columns to give a total...
set -x tells the shell to work in debug mode, and so each line will be shown with the command executed and if successfull.
Your code line:
Code:
df -m | grep -v ":"|grep -v Free|grep -v "/proc"| while read FSYSTEM BLKS FREE USED IUSED PERIUSED MOUNTEDON

tells you what its reading, so you can use it to do your title e.g
Code:
echo " FSYSTEM                BLKS     FREE     USED   IUSED   PERIUSED    MOUNTEDON"

but needs formatting...
just add that echo before the df line...

---------- Post updated at 19:46 ---------- Previous update was at 19:42 ----------

Here is the result of your command using set -x
Code:
+ read FSYSTEM BLKS FREE USED IUSED PERIUSED MOUNTEDON
+ + hostname
HOST=gon04
+ ((  INUSE = 25755648 - 25693308  ))
+ echo gon04 /data/ofa/export 25755648 25693308 InUse= 62340
gon04 /data/ofa/export 25755648 25693308 InUse= 62340

# 5  
Old 07-09-2009
I believe i need to count all the space that is left on the host (which i think is globally?) and have that echo back. along with that, i would need to have a return of all the space that is allocated to the filesystems on the host.

I added in the line that you gave me for the title. Is there anyway that i could have the information that is returned below them form into columns below the title?

my return is
Code:
 
 FSYSTEM    BLKS     FREE     USED   IUSED   PERIUSED    MOUNTEDON
/dev/hd4 1024.00 966.46 InUse= 58 /
/dev/hd2 3392.00 288.55 InUse= 3104 /usr
/dev/hd9var 2048.00 1976.49 InUse= 72 /var
/dev/hd3 2048.00 1834.10 InUse= 214 /tmp
/dev/hd1 1536.00 698.94 InUse= 838 /home
/dev/hd10opt 1024.00 556.55 InUse= 468 /opt
/dev/fslv00 30720.00 13025.69 InUse= 17695 /aix52_save_s
/dev/fslv01 1024.00 1023.52 InUse= 1 /var/adm/perf
/dev/nmon_lv 1600.00 1584.03 InUse= 16 /nmondata
comnascript.ksh[7]:  INUSE =  -  : 0403-053 Expression is not complete; more tokens expected.

I would like for it to look like this:

Code:
 FSYSTEM      BLKS        FREE     USED               MOUNTEDON
/dev/hd4       1024.00    966.46    InUse= 58         /
/dev/hd2       3392.00    288.55    InUse= 3104     /usr
/dev/hd9var   2048.00    1976.49   InUse= 72       /var
/dev/hd3       2048.00    1834.10   InUse= 214     /tmp
/dev/hd1       1536.00    698.94    InUse= 838      /home
/dev/hd10opt 1024.00    556.55    InUse= 468      /opt
/dev/fslv00    30720.00  13025.69  InUse= 17695   /aix52_save_s
/dev/fslv01    1024.00   1023.52    InUse= 1          /var/adm/perf
/dev/nmon_lv 1600.00   1584.03    InUse= 16        /nmondata

and then somewhere have the total free and total InUse.
# 6  
Old 07-10-2009
calculation:
there is a command: bc
but here are some clues for you to work on:
1:Search the forum, there are plenty of examples!
2: you can do this with the shell:
let DIFF=$WANTED-$GOT
sum=`expr $1 + $2`

---------- Post updated at 20:08 ---------- Previous update was at 20:01 ----------

Leave aside the formatting for now and conentrate on your calculation work!

You will need as many new variable as totals you want to display so if only the total of "InUse" and "FREE", that would be 2: TOTINUSE and TOTFREE

Need to leave... Hope someone else will follow you soon
All the best

---------- Post updated 07-10-09 at 17:05 ---------- Previous update was 07-09-09 at 20:08 ----------

What are the news today? ( Script progressed?)
# 7  
Old 07-10-2009
the script is done, i just need to format it. I actually started a thread in the dummy section for it.

here it is
https://www.unix.com/unix-dummies-que...lp-printf.html

Everything is done inside the script, i am just trying to figure out how to use printf for it. Im looking all over the place but nothing is dumbed down enough for me haha.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to change allocated memory for a process?

Hello, I am running ubuntu 14.04 in a server with 32GB ram. Due to receiving "high load" errors during ssh connection, I took a look at what's happening from command line. I detected that 20GB of total memory was allocated to a program. Below you can see some initial part of installation... (4 Replies)
Discussion started by: baris35
4 Replies

2. Shell Programming and Scripting

Shell script to sum up the space allocated to filesystems

Hi , I Would like to know the space allocated by adding up all the allocated space to group of filesystems .. example , df -h|grep /db | awk '{ print $4 }' ---> giving me all the used space on the filesystem but need to know the total used space by adding up all the values (3 Replies)
Discussion started by: nsankineni
3 Replies

3. Programming

find size of heap allocated

I want to find the size of the total memory allocated on the heap for the following statement: int* a = new int;How can I use the sizeof operator for this? I used: printf("\t===> %d\n",sizeof(*a)); Is this statement correct? I have asked the question because when I checked the memory of... (13 Replies)
Discussion started by: rupeshkp728
13 Replies

4. UNIX for Dummies Questions & Answers

How to find the disk space allocated.

Hello, I need to find the total allocated disk space for the home directory. How can i find that in unix?(in GB). Thanks. (4 Replies)
Discussion started by: kailash19
4 Replies

5. Programming

Why memory allocated through malloc should be freed ?

Actually for a process to run it needs text, stack , heap and data segments. All these find a place in the physical memory. Out of these 4 only heap does exist after the termination of the process that created it. I want to know the exact reason why this happens. Also why the other process need to... (20 Replies)
Discussion started by: karthiktceit
20 Replies

6. Programming

Dynamically allocated structures in C

I have a pointer to a structure containing an integer pointer: struct members { int id; int *neigh; }; The number of members N and its neighbors M change as the code runs, so I allocate the memory dynamically: members *grid = malloc(sizeof(members)*N); for(i=0;i<N;i++)... (2 Replies)
Discussion started by: brinch
2 Replies

7. Solaris

Increasing allocated space to a mount - possible?

Hey guys, I am somewhat new to Solaris - and very new when it comes to mounts. My problem is that when I installed Solaris, I allocated way too little diskspace to my / mount (it first became obvious now, however, because of new needs). bash-3.00# df -h Filesystem size ... (25 Replies)
Discussion started by: brightstorm
25 Replies

8. Solaris

Can be changeed the allocated space

i am working with solaris 9 and my disk usages are # df -k Filesystem kbytes used avail capacity Mounted on /dev/dsk/c0t0d0s0 2148263 1902721 202577 91% / /proc 0 0 0 0% /proc mnttab 0 0 0 ... (3 Replies)
Discussion started by: smartgupta
3 Replies

9. Solaris

xntpd[28781]: too many recvbufs allocated

Hi, I have a server that is getting the following alarm a couple times a day: Mar 25 10:56:54 hostname xntpd: too many recvbufs allocated (30) Mar 25 10:56:54 hostname xntpd: too many recvbufs allocated (30) I know this is some sort of NTP related issue but I need to gauge the severity of... (0 Replies)
Discussion started by: BrewDudeBob
0 Replies

10. Solaris

Memory allocated

Hi, How to find out what is the maximum memory allocated to TOMCAT server in SunOS 5.8? The Tomcat server crashes down during peak times.... Regards (1 Reply)
Discussion started by: baanprog
1 Replies
Login or Register to Ask a Question