Scripting array issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting array issue
# 8  
Old 10-16-2010
[code]#!/usr/bin/env ruby
require 'net/smtp'
def send_email(from,to,subject,message,server)
msg =

---------- Post updated at 10:02 PM ---------- Previous update was at 09:58 PM ----------

Code:
#!/usr/bin/env ruby
require 'net/smtp'
def send_email(from,to,subject,message,server)
    msg = <<-END_OF_MESSAGE
    From: <#{from}>
    To: <#{to}>
    Subject: #{subject}

    #{message}
   END_OF_MESSAGE

   Net::SMTP.start(server) do |smtp|
   smtp.send_message msg, from, to
   end
end

threshold=80
df=`df -H`
msg=[]
df.split("\n").each do|s|
  s=s.split
  cap=s[4].to_i
  filesystem=s[0]
  if cap >= threshold
    msg<<"#{filesystem}: #{cap}"
  end
end
if msg.size>1
 send_email("root@localhost","root","Alert","#{msg.join("\n")}","localhost")
end

# 9  
Old 10-16-2010
Code:
threshold=33
df -P | { read
 while read fs size used avail pcent mount
 do
  if [ ${pcent%?} -gt ${threshold:?} ]
  then
    printf "Filesystem %s on %s is %s full\n" "$fs" "$mount" "$pcent"
  fi
 done
}

# 10  
Old 10-18-2010
Quote:
Please post the output from:

df -H
df -k

And matching sample desired output.
We got the "df -H" , but you posted "df -h" not "df -k". When we have a script which is not working we like to see what the output from the key commands in the script looks like.
Also what do you want the final output of the script to look like?

Btw. If you have "df -P" on your system, just use cfajohnson's post .


@DGPickett . This is clearly not HP-UX (because "df -H" is not valid), but we don't know yet what O/S it is.
# 11  
Old 10-18-2010
Quote:
Originally Posted by methyl
Btw. If you have "df -P" on your system, just use cfajohnson's post .

df -P is standard (POSIX).
# 12  
Old 10-18-2010
@cfajohnson
Though not the first time I have seen "df -P", it is very rarely used in day-today scripting because of the units. The percentage used figure is good and all we needed for this exercise.
The syntax is not valid in umpteen versions of unix, though we can deduce that the O/P has a modern one which may well offer a POSIX compliant "df" option. Whether the POSIX version is called "df" or "bdf" is a matter for the standards people.


@DGPickett
You may find that issuing "df" commands as a non-root user gives you a different view of free space.
# 13  
Old 10-19-2010
Quote:
Originally Posted by methyl
@cfajohnson
Though not the first time I have seen "df -P", it is very rarely used in day-today scripting because of the units.

What units? The -P option doesn't change the units.

When scripting, one should always use the -P option, otherwise parsing the output is much harder.
Quote:
The percentage used figure is good and all we needed for this exercise.
The syntax is not valid in umpteen versions of unix, though we can deduce that the O/P has a modern one which may well offer a POSIX compliant "df" option.

I doubt that there are any modern Unixes in which is is not valid. Can you name one?
Quote:
Whether the POSIX version is called "df" or "bdf" is a matter for the standards people.

The POSIX version is called df.

Last edited by cfajohnson; 10-19-2010 at 11:27 AM..
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