LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem writing script (https://www.linuxquestions.org/questions/linux-newbie-8/problem-writing-script-4175504652/)

battles 05-11-2014 03:51 PM

Problem writing script
 
#!/bin/bash
cd pool
if [ $( find -maxdepth 1 | grep -cv '^\.$' ) -gt 50 ]; then
"Pool >= " find -maxdepth " - check for flooding!" | mail -s "Server Flooding Notice" me@my.net
fi

I am trying to write a script that will alert me if a directory get too many files therein. I want the script to send the
find -maxdepth 1 | grep -cv '^\.$'
info placed between the text in quotes.

Thanks.

battles 05-11-2014 05:09 PM

I can get the echo "Pool >= 40: " when it is sent alone, but when the find follows, the find numbers show up without the preceeding echo.

echo "Pool >= 40: " | find -maxdepth 1 | grep -cv '^\.$' | mail -s "Server Flooding Notice" me@my.net

eklavya 05-12-2014 01:03 AM

Code:

#!/bin/bash
cd pool
direc=$(find -maxdepth 1 | grep -cv '^\.$')
if [ $direc -gt 50 ]; then
echo "Pool = $direc - check for flooding!" | mail -s "Server Flooding Notice - $direc files" me@my.net
fi


grail 05-12-2014 03:46 AM

I am curious why when you ran the commands the first time you placed them inside $()?

battles 05-12-2014 06:01 AM

Beats me, I copied to code from a Linux sample site :).
I'm just an itty, bitty, Linux baby who thinks that he is smarter by half than everyone else!

Thanks for everyone's help.

grail 05-12-2014 08:38 AM

Well we all start somewhere and mine was a clue to help rather than a solution .... ie if you look up what that construct does you might just find out why your original script did not work :)


All times are GMT -5. The time now is 09:21 AM.