Sponsored Content
Top Forums Shell Programming and Scripting Mail sent from variable is not aligned in shell script Post 302997337 by viay on Thursday 11th of May 2017 02:31:36 PM
Old 05-11-2017
First of all thanks for response,

This is my entire code, you can find more details here.

Code:
export maillist=123@gmail.com;
#df -PH /d04 /d05 /u01 /export | grep -vE '^Filesystem|none|cdrom'|awk '{ print $5 " " $6 }' | while read output;
#df -PH | grep -vE '^Filesystem|none|cdrom|swdepot'|awk '{ print $5 " " $6 }' > diskcheck.log;

#diskcheck is current output whereas disk_alert is previous runned output

if [ -s "$/monitor/log/disk_alert.log" ]; then
#Getting variables and compare with old
  usep=($(cat $/monitor/diskcheck.log | awk '{ print $1 }' | cut -d'%' -f1));
  partitions=($(cat $/monitor/diskcheck.log | awk '{ print $2 }' ));
  usep1=($(cat $/monitor/log/disk_alert.log | awk '{ print $1 }' | cut -d'%' -f1));
else
   cat "$/monitor/diskcheck.log" > "/monitor/log/disk_alert.log";
  usep=($(cat $/monitor/diskcheck.log | awk '{ print $1 }' | cut -d'%' -f1));
  partitions=($(cat $/monitor/diskcheck.log | awk '{ print $2 }' ));
  usep1=($(cat $/monitor/log/disk_alert.log | awk '{ print $1 }' | cut -d'%' -f1));
fi

echo ${usep[@]};
echo ${usep1[@]};
alertlist()
# index = i
for i in ${!usep[@]}; do
        if [ ${usep[$i]} -gt 80 ]; then
                if [ ${usep[$i]} -gt ${usep1[$i]} ]; then
                        #mail=awk '{ ${usep[$i]} print $0 }' $/monitor/diskcheck.log;
                        # Temp to store current percentage diff and partition to store in a variable.
                        tmp="$(echo -e "Running out of space \"${partitions[$i]} (${usep[$i]}%)\" on $(hostname) as on $(date)")";
                        #tmp=$(printf "%s\n" "(${usep[$i]}%) percent used on ${partitions[$i]}");
                        #alertlist holds the values to send mail.
                        #alertlist+="$tmp";
                        echo "$tmp"
                        echo "$tmp" | mail -s "ALERT:  Running out of space" $maillist;
                        #echo "Running out of space \"${partitions[$i]} (${usep[$i]}%)\" on $(hostname) as on $(date)";
                fi
        fi
done
#echo "$alertlist" | mail -s "ALERT:  Running out of space" $maillist;


those arrays contain numeric values???
yes, arrays only contain numeric values.

1.take the mail command out of the loop,
Yes, I've tried that But it print only the last value of variable(alertlist)

2.initialize alertlist to an empty string before you start your loop,
Yes, tried it but won't work

3.use echo "$tmp" inside the loop,
Echo looks good while inside loop

4.add the contents of the variable tmp as an additional line in the variable alertlist inside the loop
I think it is similar as previous one, Right?

Have a look at the summary.

Thanks

Last edited by Don Cragun; 05-11-2017 at 03:38 PM.. Reason: Add CODE and ICODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script to send a mail

Hi, I need a shell script which runs in the backround for all the 24 hours and send a mail to us regarding the output of the prstat command when the load average increase above certain percent. kindly help me on this...... (1 Reply)
Discussion started by: jayaramanit
1 Replies

2. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

3. Shell Programming and Scripting

Mail shell script

Hi All, I want to send mail to multiple users.. Currently I am using below script cat $STATUS_FILE|mailx -s "$SUBJECT" -r xxx@yyy.com $MAILTO How can i give cc or bcc to in this script Please help me thanks in advance Regards RG (3 Replies)
Discussion started by: rgumm
3 Replies

4. UNIX for Dummies Questions & Answers

How to send e-mail from shell script ( C shell )?

Hi , How to send e-mail from shell script ( C shell ) . Mailx command is not working ( It didn't giving error also ). Please help me (2 Replies)
Discussion started by: arukuku
2 Replies

5. Shell Programming and Scripting

Sending mail from shell script

Hello All, I m trying to send mail from my unix script, I have used the below command mailx -s 'hi' email address < temp.txt It is not giving me any error,but I couldn't receive the mail Can you please help me. Many Thanks, Pragyan (6 Replies)
Discussion started by: prarat
6 Replies

6. Shell Programming and Scripting

Shell Script To E-Mail

Hi All, I'm having some problems with my shell script. When running the script I get the following errors: line 101: <html>: command not found line 105: /dumpfile.txt: No such file or directory The file dumpfile.txt does exist and I have double and tripple checked this. I'm not sure... (14 Replies)
Discussion started by: SalientAnimal
14 Replies

7. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

8. Shell Programming and Scripting

To send a mail through shell script

I want to send a mail through shell script,If it is possible Please give me a code. mail id : upload.xxx@example.com (8 Replies)
Discussion started by: kannansoft1985
8 Replies

9. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

10. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies
UNBUFFER(1)						      General Commands Manual						       UNBUFFER(1)

NAME
unbuffer - unbuffer output SYNOPSIS
unbuffer program [ args ] INTRODUCTION
unbuffer disables the output buffering that occurs when program output is redirected from non-interactive programs. For example, suppose you are watching the output from a fifo by running it through od and then more. od -c /tmp/fifo | more You will not see anything until a full page of output has been produced. You can disable this automatic buffering as follows: unbuffer od -c /tmp/fifo | more Normally, unbuffer does not read from stdin. This simplifies use of unbuffer in some situations. To use unbuffer in a pipeline, use the -p flag. Example: process1 | unbuffer -p process2 | process3 CAVEATS
unbuffer -p may appear to work incorrectly if a process feeding input to unbuffer exits. Consider: process1 | unbuffer -p process2 | process3 If process1 exits, process2 may not yet have finished. It is impossible for unbuffer to know long to wait for process2 and process2 may not ever finish, for example, if it is a filter. For expediency, unbuffer simply exits when it encounters an EOF from either its input or process2. In order to have a version of unbuffer that worked in all situations, an oracle would be necessary. If you want an application-specific solution, workarounds or hand-coded Expect may be more suitable. For example, the following example shows how to allow grep to finish pro- cessing when the cat before it finishes first. Using cat to feed grep would never require unbuffer in real life. It is merely a place- holder for some imaginary process that may or may not finish. Similarly, the final cat at the end of the pipeline is also a placeholder for another process. $ cat /tmp/abcdef.log | grep abc | cat abcdef xxxabc defxxx $ cat /tmp/abcdef.log | unbuffer grep abc | cat $ (cat /tmp/abcdef.log ; sleep 1) | unbuffer grep abc | cat abcdef xxxabc defxxx $ BUGS
The man page is longer than the program. SEE ALSO
"Exploring Expect: A Tcl-Based Toolkit for Automating Interactive Programs" by Don Libes, O'Reilly and Associates, January 1995. AUTHOR
Don Libes, National Institute of Standards and Technology 1 June 1994 UNBUFFER(1)
All times are GMT -4. The time now is 04:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy