Scripting array issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting array issue
# 1  
Old 10-15-2010
Scripting array issue

Hi guys,

I'm a scripting noob in need of some help Smilie
I am creating a script that checks the filesystems and will alert based upon if the percent full is greater than the threshold set.

The problem that I am having is that when I set the 'filesystem' variable, all of the output is treated as 1 single variable instead of 4 variables that will run through.

so: /dev/sda2 /dev/sda1 /dev/sda3 /dev/sda4 will be set as 1 variable instead of being broken out and spilt into 4 different variables...
I think this needs to be done with an array, but i'm not sure how to accomplish this.

Any suggestions?

ThanksSmilie

Code:
#!/bin/bash
THRESHOLD="30%"
filesystems=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{print $1}')
for i in $filesystems
do
UTILIZED=$(/bin/df -k $filesystems | /usr/bin/tail -1 | /bin/awk '{print $5}')
# Compare the utilized value against the threshold:
  if [[ "$UTILIZED" > "$THRESHOLD" || "$UTILIZED" = "100%" ]]; then
        echo -e "OS|Filesystem|PctUsed\t$filesystems\t2\t$filesystems is at $UTILIZED.  Please have a sysadmin check the environment for issues."
  else
        echo -e "OS|Filesytem|PctUsed\t$filesystems\t0"
  fi

done

exit 0

# 2  
Old 10-15-2010
Looks just like ksh - must tell shell it is an array:

Array variables
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 10-15-2010
Code:
df | awk -v THRESHOLD=30 '/\/dev\/sd/{if(int($5)>THRESHOLD) print $1}'

# 4  
Old 10-15-2010
Please post a sample of:

Code:
df -H
df -k

And matching sample desired output.

# 5  
Old 10-15-2010
It is wise to keep an eye on inodes, too.
# 6  
Old 10-15-2010
Here are the outputs requested:
Code:
# df -H
Filesystem             Size   Used  Avail Use% Mounted on
/dev/sda2               11G   3.6G   6.1G  37% /
/dev/sda5               11G   6.4G   3.3G  67% /opt
/dev/sda3               11G   5.0G   4.8G  51% /var
/dev/sda1              128M    12M   110M  10% /boot
tmpfs                  4.3G      0   4.3G   0% /dev/shm

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.5G  3.4G  5.7G  37% /
/dev/sda5             9.5G  6.0G  3.1G  67% /opt
/dev/sda3             9.5G  4.6G  4.4G  52% /var
/dev/sda1             122M   11M  105M  10% /boot
tmpfs                 4.0G     0  4.0G   0% /dev/shm

# 7  
Old 10-15-2010
Code:
$ df -i .
/home                (/home      ) :  1834176 total i-nodes
                                                    116539 free i-nodes
                                                   1717637 used i-nodes
                                                      1473 % i-nodes used
$

HPUX does a strange percentage calc, but inodes are not a problem on vxfs, as it makes more on demand, so some filtering to ensure only static inode count FS are checked is in order! Smilie

Last edited by DGPickett; 10-15-2010 at 02:26 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array size in C shell scripting

Hi, I would like to know how to define the size of the array in c shell scripting. (15 Replies)
Discussion started by: gopishrine
15 Replies

2. UNIX for Beginners Questions & Answers

Convert String to an Array using shell scripting in JSON file.

This is the sample json I have pasted here. I want all the IP address strings to be converted into an array. For example "10.38.32.202" has to be converted to everywhere in the JSON. There are multiple IPs in a JSON I am pasting one sample object from the JSON. But the IPs already in an Array... (11 Replies)
Discussion started by: vinshas1
11 Replies

3. Shell Programming and Scripting

Need to remove first 6 lines and last line in a array ---- perl scripting

Hi I have stored a command output in an array like below @a = `xyz`; actually xyz comnad will give the output like this tracker date xxxxxxx xxxxxxx --------------------- 1 a 2 b ---------------------- i have stored the "xyz" output to an... (3 Replies)
Discussion started by: siva kumar
3 Replies

4. Shell Programming and Scripting

Assigning array values using awk in shell scripting

hi My script as below #!/bin/ksh for i in `seq 1 7` do a=$(awk '{print $i}' /home/rama/expenese.txt) done for i in `seq 1 7` do echo "${a}" done content of expense.txt is as below 5032 210179 3110 132813874 53488966 11459221 5300794 I want output as... (6 Replies)
Discussion started by: Ramakrishna V
6 Replies

5. Shell Programming and Scripting

4x4 Array in csh scripting

I am trying to code a 4 by 4 array. However the naming convention is diffrent. Please refer the image below https://lh5.googleusercontent.com/-Dl0vdjfXtU0/Tnh02_ORJpI/AAAAAAAAAKU/4c2zyFP9IB0/array.JPG I want to name them in order : from 0 to 3 --> (0,0) cell to (0,3) from 4 to 7 --> (1,0)... (0 Replies)
Discussion started by: animesharma
0 Replies

6. Shell Programming and Scripting

ksh scripting- array format

Hi Everyone, I have a ksh script that queries a database. The query output looks like this: $queryResult = echo ${queryResult} = name1 echo ${queryResult} = age1 echo ${queryResult} = name2 echo ${queryResult} = age2 ... I need to insert those values into a new array that would... (2 Replies)
Discussion started by: practitioner
2 Replies

7. Shell Programming and Scripting

array + if in linux shell scripting

Hi, I am having two set of files with different number of columns and rows. A set of files have only single row with 20 columns. B set of files have 1000s of rows with 5 columns. both set contains equal number of files. I want to save all the 20 columns of A in variables one by one and... (21 Replies)
Discussion started by: CAch
21 Replies

8. Shell Programming and Scripting

Bash Scripting - How to grep a file into an array

I have figured out how to grep the file like this: echo `grep $(date +'%Y-%m-%d') Cos-01.csv | cut -d',' -f1` The above line does echo the correct information from the lines in which my search criteria is found. Now I am trying to get that information (Yes, just one column of every line) into... (6 Replies)
Discussion started by: TwelveDays
6 Replies

9. Solaris

V880 and T3 array issue

We're trying to install a third T3 array onto our V880. The other two T3's are connected to a qlogic fibre card. We can see this connection fine when we do a luxadm probe -p command. The full device paths are shown etc. ie: the first T3's logical name is c2t1d0 and the second one is c3t1d0. ... (3 Replies)
Discussion started by: mjl927
3 Replies

10. UNIX for Dummies Questions & Answers

Simple Array in Ksh Scripting

Ksh Scripting Can some one give me a simple example of array operations using ksh. For Ex: week_array = {Sunday Monday Tuesday Wednesday Thursday Friday Saturday} I want to assign and retrieve and print them along with their index. I am looking for the o/p like: 0 Sunday 1 Monday ... (2 Replies)
Discussion started by: ravikirankethe
2 Replies
Login or Register to Ask a Question