Sponsored Content
Full Discussion: while loop output
Top Forums Shell Programming and Scripting while loop output Post 302642045 by prabhu_kumar on Thursday 17th of May 2012 12:26:35 AM
Old 05-17-2012
while loop output

SmilieHi
I am a beginner to unix

In a shell script i see the below code

Code:
# set admin email so that you can get email
ADMIN=someone@somewhere.com
host=`hostname`
date=`date`
# set alert level 70% is default
ALERT=70
df -h | grep / | grep -v '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  echo $output;
  usep=`(echo $output | awk '{ print $1}' | cut -d'%' -f1  )`
  partition=`(echo $output | awk '{ print $2 }' )`
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on "$host" as on "$date |
     mailx -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done


As we can see the script is send an alert email to the user when disk space exceeds 70%.
what I could not under stand is below line
Code:
df -h | grep / | grep -v '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;

we are diverting the modified df -h output to "while loop output". what does this mean?
how many times the loop is executed?

please provide any guidance.

thanks
p.

Last edited by Scrutinizer; 05-17-2012 at 03:28 AM.. Reason: Code tags. Removed email address, spelling
 

10 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

Loop column output

I need help in what to do with a bash script? I'm trying to run a command to output the data from a table and then insert it into commands. Looping for each row of data. For example the output data from a table: 10 John house 20 Jane apt 30 Joe townhomeThen I need to take the output... (1 Reply)
Discussion started by: handband2
1 Replies

2. Shell Programming and Scripting

While loop using command output...

If I run this command networksetup -listallnetworkservices I get the following output. Ethernet AirPort *Parallels Host-Guest *Parallels NAT MY VPN Ethernet 2 I want to make changes to only anything that contains the word "Ethernet" which I can do with grep. But What I really need a... (6 Replies)
Discussion started by: elbombillo
6 Replies

3. Shell Programming and Scripting

How to group the output of a loop

Hi Guys, This is based on my question previously posted. :) I have my shell script like this: #!/usr/bin/sh e_id=`sqlplus -s scott/tiger@DB<<eof SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF; select emp_id from employee; quit ... (1 Reply)
Discussion started by: alvingo
1 Replies

4. Shell Programming and Scripting

Bash: Help with output from a for loop

Hi, Sorry I'm new to shell scripting.. my loop is as follows: let i=0 for item in ${APPSARRAY} do #..some code to get a unique value called $result let i=i+1 done What I want to do is within the for loop, create a comma seperated list: ... (3 Replies)
Discussion started by: mjwoodford
3 Replies

5. Shell Programming and Scripting

Reverse the output using for loop

Good morning!! Im trying to ge tthe output in this for loop to be reversed. #!/usr/bin/perl $i = 1; for($i != 0 ; $i < 11 ; $i++){ print "$i\n"; } Ive tried changing the i++ to i--, but it makes the outputted numbers different also. Thanks bigben (4 Replies)
Discussion started by: bigben1220
4 Replies

6. Shell Programming and Scripting

loop with OK or NOK output at the same position

Hi This is my script $ cat ./openldap_test.sh #!/bin/bash for ldap_srv in 'testserver1' 'server2' 'server3' 'server4' 'testserver5' 'server6' 'server7' 'server8' 'server9' 'testserver10'; do ldapsearch -LLL -x -H ldap://$ldap_srv '(cn=examplebox)' memberNisNetgroup > /dev/null if ; then... (1 Reply)
Discussion started by: slashdotweenie
1 Replies

7. Shell Programming and Scripting

Output in for loop (ksh)

Hi , I'm writing the for loop script in home directory and wanted to get the files from /etc/data directory. #!/bin/ksh file_nm="/etc/dat" for test_data in $file_nm/fln* do echo "$test_data" done the code is executing successfully , but in the output it is showing ... (6 Replies)
Discussion started by: smile689
6 Replies

8. Shell Programming and Scripting

Loop with output to script?

Hey guys, I am VERY new to linux scripting and was wondering if you could help me with the following: essentially the use case is the following...a service crashes and a script must be executed to rerun 3000 entries one at a time....your options are to do each of those manually, 1 at a time... (6 Replies)
Discussion started by: wrnganswr
6 Replies

9. Shell Programming and Scripting

Use while loop - output variable

I'm very much a newbie and hence why this is going to be a stupid question. I'm attempting to create a korn shell script that pulls zone file locations and includes the copy command in the output. What? getzonedir.ksh #!/bin/ksh while read -r domain do ls */*"$domain" > $dir1 echo "cp... (5 Replies)
Discussion started by: djzah
5 Replies

10. Shell Programming and Scripting

For loop output redirection

Hi All, i have below for loop of which i am trying to redirect output in a file: for i in `/usr/sbin/ifconfig -a | awk '/flags/ {print $1}' | grep -v lo | sed 's/://g'` do ifconfig $i dhcp status done >> /tmp/logfile but instead the output is appearing as stdout on screen rather than... (12 Replies)
Discussion started by: omkar.jadhav
12 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 09:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy