Sponsored Content
Top Forums Shell Programming and Scripting Mail sent from variable is not aligned in shell script Post 302997547 by viay on Tuesday 16th of May 2017 08:51:59 AM
Old 05-16-2017
Hello Don,

As you suggest I tried the new script,

a.)all of your assignments like this are wasting CPU and memory by using cat when it is not needed. Try:
Yes

Code:
export maillist=abc@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 }' > $HOME/monitor/diskcheck.log;

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

echo ${usep[@]};
echo ${usep1[@]};
unset alertlist
# index = i
for i in ${!usep[@]}; do
        if [ ${usep[$i]} -gt 80 ]; then
                if [ ${usep[$i]} -gt ${usep1[$i]} ]; then
                        # 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)")";
                        echo "$tmp"
                        #tmp=$(printf "%s\n" "(${usep[$i]}%) percent used on ${partitions[$i]}");
                        alertlist=("${alertlist[@]}" "$tmp")
                fi
        fi
done

if [ ${#alertlist} -gt 0 ]; then
        printf '%s\n' "${alertlist[@]}" | mail -s "ALERT:  Running out of space" $maillist;
        echo "Following text sent as body of mail to $maillist:"
        printf '%s\n' "${alertlist[@]}"
fi                     #alertlist holds the values to send mail.

While I run the script it seems everything okay as usual the output of run script is,
Code:
[vijay@localhost monitor]$ sh disk_alert.sh
19 1 39 3 40 93 1 14 96
19 1 39 3 40 83 1 14 66
Running out of space "/u05 (93%)" on localhost.local as on Tue May 16 
Running out of space "/u02 (96%)" on localhost.local as on Tue May 16 
Following text sent as body of mail to abc@gmail.com:
Running out of space "/u05 (93%)" on localhost.local as on Tue May 16 
Running out of space "/u02 (96%)" on localhost.local as on Tue May 16

When I receive the mail it's remains with the old format
Code:
Running out of space "/u05 (93%)" on localhost.local as on Tue May 16 Running out of space "/u02 (96%)" on localhost.local as on Tue May 16

1.)
Note, however, that if a mounted filesystem is ever unmounted or a new filesystem is mounted between runs of your script, there is no guarantee that the order of the percentage values stored in the arrays usep and usep1 are in the same order!

Is their any solution for this?
 

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
comm(1) 							   User Commands							   comm(1)

NAME
comm - select or reject lines common to two files SYNOPSIS
comm [-123] file1 file2 DESCRIPTION
The comm utility reads file1 and file2, which must be ordered in the current collating sequence, and produces three text columns as output: lines only in file1; lines only in file2; and lines in both files. If the input files were ordered according to the collating sequence of the current locale, the lines written will be in the collating sequence of the original lines. If not, the results are unspecified. OPTIONS
The following options are supported: -1 Suppresses the output column of lines unique to file1. -2 Suppresses the output column of lines unique to file2. -3 Suppresses the output column of lines duplicated in file1 and file2. OPERANDS
The following operands are supported: file1 A path name of the first file to be compared. If file1 is -, the standard input is used. file2 A path name of the second file to be compared. If file2 is -, the standard input is used. USAGE
See largefile(5) for the description of the behavior of comm when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes). EXAMPLES
Example 1 Printing a list of utilities specified by files If file1, file2, and file3 each contain a sorted list of utilities, the command example% comm -23 file1 file2 | comm -23 - file3 prints a list of utilities in file1 not specified by either of the other files. The entry: example% comm -12 file1 file2 | comm -12 - file3 prints a list of utilities specified by all three files. And the entry: example% comm -12 file2 file3 | comm -23 -file1 prints a list of utilities specified by both file2 and file3, but not specified in file1. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of comm: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 All input files were successfully output as specified. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
cmp(1), diff(1), sort(1), uniq(1), attributes(5), environ(5), largefile(5), standards(5) SunOS 5.11 3 Mar 2004 comm(1)
All times are GMT -4. The time now is 03:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy