script in solaris to send mail when file systems reaches prescribed threshold value [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












-2















#!/bin/bash
threshold="1"
mailx -s "sub" abc@.com



Now if a fs crosses the threshold limit, we should get mail










share|improve this question















closed as unclear what you're asking by Rui F Ribeiro, Christopher, Stephen Harris, Luciano Andress Martini, Toby Speight Feb 28 at 18:34


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 2





    If the code works but you need improvement, you should go to Code Review Stackexchange.

    – Weijun Zhou
    Feb 27 at 7:17











  • I guess you don't want to send an email if /tmp/output is empty?

    – Freddy
    Feb 27 at 8:04











  • the code is working perfectly. I tested it, high space in the sense files with occupying more space in the filesystem and yes i dont want to send a mail if /tmp/output is empty

    – Sri
    Feb 27 at 8:44











  • You are not expecting a answer with how to write a script that shows the large files sorted in a filesystem. So why this title?

    – Luciano Andress Martini
    Feb 28 at 11:42












  • the question is now edited correctly can you review my question and clear the flag

    – Sri
    Mar 4 at 7:49















-2















#!/bin/bash
threshold="1"
mailx -s "sub" abc@.com



Now if a fs crosses the threshold limit, we should get mail










share|improve this question















closed as unclear what you're asking by Rui F Ribeiro, Christopher, Stephen Harris, Luciano Andress Martini, Toby Speight Feb 28 at 18:34


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 2





    If the code works but you need improvement, you should go to Code Review Stackexchange.

    – Weijun Zhou
    Feb 27 at 7:17











  • I guess you don't want to send an email if /tmp/output is empty?

    – Freddy
    Feb 27 at 8:04











  • the code is working perfectly. I tested it, high space in the sense files with occupying more space in the filesystem and yes i dont want to send a mail if /tmp/output is empty

    – Sri
    Feb 27 at 8:44











  • You are not expecting a answer with how to write a script that shows the large files sorted in a filesystem. So why this title?

    – Luciano Andress Martini
    Feb 28 at 11:42












  • the question is now edited correctly can you review my question and clear the flag

    – Sri
    Mar 4 at 7:49













-2












-2








-2








#!/bin/bash
threshold="1"
mailx -s "sub" abc@.com



Now if a fs crosses the threshold limit, we should get mail










share|improve this question
















#!/bin/bash
threshold="1"
mailx -s "sub" abc@.com



Now if a fs crosses the threshold limit, we should get mail







shell scripting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 4 at 7:29







Sri

















asked Feb 27 at 7:08









SriSri

15




15




closed as unclear what you're asking by Rui F Ribeiro, Christopher, Stephen Harris, Luciano Andress Martini, Toby Speight Feb 28 at 18:34


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Rui F Ribeiro, Christopher, Stephen Harris, Luciano Andress Martini, Toby Speight Feb 28 at 18:34


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2





    If the code works but you need improvement, you should go to Code Review Stackexchange.

    – Weijun Zhou
    Feb 27 at 7:17











  • I guess you don't want to send an email if /tmp/output is empty?

    – Freddy
    Feb 27 at 8:04











  • the code is working perfectly. I tested it, high space in the sense files with occupying more space in the filesystem and yes i dont want to send a mail if /tmp/output is empty

    – Sri
    Feb 27 at 8:44











  • You are not expecting a answer with how to write a script that shows the large files sorted in a filesystem. So why this title?

    – Luciano Andress Martini
    Feb 28 at 11:42












  • the question is now edited correctly can you review my question and clear the flag

    – Sri
    Mar 4 at 7:49












  • 2





    If the code works but you need improvement, you should go to Code Review Stackexchange.

    – Weijun Zhou
    Feb 27 at 7:17











  • I guess you don't want to send an email if /tmp/output is empty?

    – Freddy
    Feb 27 at 8:04











  • the code is working perfectly. I tested it, high space in the sense files with occupying more space in the filesystem and yes i dont want to send a mail if /tmp/output is empty

    – Sri
    Feb 27 at 8:44











  • You are not expecting a answer with how to write a script that shows the large files sorted in a filesystem. So why this title?

    – Luciano Andress Martini
    Feb 28 at 11:42












  • the question is now edited correctly can you review my question and clear the flag

    – Sri
    Mar 4 at 7:49







2




2





If the code works but you need improvement, you should go to Code Review Stackexchange.

– Weijun Zhou
Feb 27 at 7:17





If the code works but you need improvement, you should go to Code Review Stackexchange.

– Weijun Zhou
Feb 27 at 7:17













I guess you don't want to send an email if /tmp/output is empty?

– Freddy
Feb 27 at 8:04





I guess you don't want to send an email if /tmp/output is empty?

– Freddy
Feb 27 at 8:04













the code is working perfectly. I tested it, high space in the sense files with occupying more space in the filesystem and yes i dont want to send a mail if /tmp/output is empty

– Sri
Feb 27 at 8:44





the code is working perfectly. I tested it, high space in the sense files with occupying more space in the filesystem and yes i dont want to send a mail if /tmp/output is empty

– Sri
Feb 27 at 8:44













You are not expecting a answer with how to write a script that shows the large files sorted in a filesystem. So why this title?

– Luciano Andress Martini
Feb 28 at 11:42






You are not expecting a answer with how to write a script that shows the large files sorted in a filesystem. So why this title?

– Luciano Andress Martini
Feb 28 at 11:42














the question is now edited correctly can you review my question and clear the flag

– Sri
Mar 4 at 7:49





the question is now edited correctly can you review my question and clear the flag

– Sri
Mar 4 at 7:49










1 Answer
1






active

oldest

votes


















0














Just a suggestion how you could do it. See the comments in the script.



#!/bin/bash

# define constants on top so you can find and edit them easily
declare -ri threshold=1
declare -r mailsubject="[$(hostname)] FS Alert Exceed $threshold%"
declare -r mailbodystart="$(hostname) Filesystem Alert, threshold=$threshold%n"
declare -r mailto="abc@.com"

# use variable instead of output file
declare mailbody=""

for fs in $(df -hk | awk 'print $6' | sed '1d'); do
chk=$(df -hk $fs | sed '1d' | awk 'print $5' | awk -F% 'print $1')
if [ "$chk" -gt "$threshold" ]; then
# append to mailbody
mailbody="$mailbody$chk% $fsn"
fi
done

# send mail if mailbody is non-empty
if [ -n "$mailbody" ]; then
# sort by filesystem size, largest first
mailbody=$(echo -e "$mailbody" | sort -nr)
echo -e "$mailbodystart$mailbody" | mailx -s "$mailsubject" "$mailto"
fi





share|improve this answer

























  • I want to add Thanks and regards and under it my name in the mailbody, tried different combinations using /t and /n but didnt work, can you help me out

    – Sri
    12 hours ago

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Just a suggestion how you could do it. See the comments in the script.



#!/bin/bash

# define constants on top so you can find and edit them easily
declare -ri threshold=1
declare -r mailsubject="[$(hostname)] FS Alert Exceed $threshold%"
declare -r mailbodystart="$(hostname) Filesystem Alert, threshold=$threshold%n"
declare -r mailto="abc@.com"

# use variable instead of output file
declare mailbody=""

for fs in $(df -hk | awk 'print $6' | sed '1d'); do
chk=$(df -hk $fs | sed '1d' | awk 'print $5' | awk -F% 'print $1')
if [ "$chk" -gt "$threshold" ]; then
# append to mailbody
mailbody="$mailbody$chk% $fsn"
fi
done

# send mail if mailbody is non-empty
if [ -n "$mailbody" ]; then
# sort by filesystem size, largest first
mailbody=$(echo -e "$mailbody" | sort -nr)
echo -e "$mailbodystart$mailbody" | mailx -s "$mailsubject" "$mailto"
fi





share|improve this answer

























  • I want to add Thanks and regards and under it my name in the mailbody, tried different combinations using /t and /n but didnt work, can you help me out

    – Sri
    12 hours ago















0














Just a suggestion how you could do it. See the comments in the script.



#!/bin/bash

# define constants on top so you can find and edit them easily
declare -ri threshold=1
declare -r mailsubject="[$(hostname)] FS Alert Exceed $threshold%"
declare -r mailbodystart="$(hostname) Filesystem Alert, threshold=$threshold%n"
declare -r mailto="abc@.com"

# use variable instead of output file
declare mailbody=""

for fs in $(df -hk | awk 'print $6' | sed '1d'); do
chk=$(df -hk $fs | sed '1d' | awk 'print $5' | awk -F% 'print $1')
if [ "$chk" -gt "$threshold" ]; then
# append to mailbody
mailbody="$mailbody$chk% $fsn"
fi
done

# send mail if mailbody is non-empty
if [ -n "$mailbody" ]; then
# sort by filesystem size, largest first
mailbody=$(echo -e "$mailbody" | sort -nr)
echo -e "$mailbodystart$mailbody" | mailx -s "$mailsubject" "$mailto"
fi





share|improve this answer

























  • I want to add Thanks and regards and under it my name in the mailbody, tried different combinations using /t and /n but didnt work, can you help me out

    – Sri
    12 hours ago













0












0








0







Just a suggestion how you could do it. See the comments in the script.



#!/bin/bash

# define constants on top so you can find and edit them easily
declare -ri threshold=1
declare -r mailsubject="[$(hostname)] FS Alert Exceed $threshold%"
declare -r mailbodystart="$(hostname) Filesystem Alert, threshold=$threshold%n"
declare -r mailto="abc@.com"

# use variable instead of output file
declare mailbody=""

for fs in $(df -hk | awk 'print $6' | sed '1d'); do
chk=$(df -hk $fs | sed '1d' | awk 'print $5' | awk -F% 'print $1')
if [ "$chk" -gt "$threshold" ]; then
# append to mailbody
mailbody="$mailbody$chk% $fsn"
fi
done

# send mail if mailbody is non-empty
if [ -n "$mailbody" ]; then
# sort by filesystem size, largest first
mailbody=$(echo -e "$mailbody" | sort -nr)
echo -e "$mailbodystart$mailbody" | mailx -s "$mailsubject" "$mailto"
fi





share|improve this answer















Just a suggestion how you could do it. See the comments in the script.



#!/bin/bash

# define constants on top so you can find and edit them easily
declare -ri threshold=1
declare -r mailsubject="[$(hostname)] FS Alert Exceed $threshold%"
declare -r mailbodystart="$(hostname) Filesystem Alert, threshold=$threshold%n"
declare -r mailto="abc@.com"

# use variable instead of output file
declare mailbody=""

for fs in $(df -hk | awk 'print $6' | sed '1d'); do
chk=$(df -hk $fs | sed '1d' | awk 'print $5' | awk -F% 'print $1')
if [ "$chk" -gt "$threshold" ]; then
# append to mailbody
mailbody="$mailbody$chk% $fsn"
fi
done

# send mail if mailbody is non-empty
if [ -n "$mailbody" ]; then
# sort by filesystem size, largest first
mailbody=$(echo -e "$mailbody" | sort -nr)
echo -e "$mailbodystart$mailbody" | mailx -s "$mailsubject" "$mailto"
fi






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 28 at 10:36

























answered Feb 27 at 10:15









FreddyFreddy

1,359210




1,359210












  • I want to add Thanks and regards and under it my name in the mailbody, tried different combinations using /t and /n but didnt work, can you help me out

    – Sri
    12 hours ago

















  • I want to add Thanks and regards and under it my name in the mailbody, tried different combinations using /t and /n but didnt work, can you help me out

    – Sri
    12 hours ago
















I want to add Thanks and regards and under it my name in the mailbody, tried different combinations using /t and /n but didnt work, can you help me out

– Sri
12 hours ago





I want to add Thanks and regards and under it my name in the mailbody, tried different combinations using /t and /n but didnt work, can you help me out

– Sri
12 hours ago


Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)