LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-11-2014, 04:51 PM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 236

Rep: Reputation: Disabled
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.
 
Old 05-11-2014, 06:09 PM   #2
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 236

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-12-2014, 02:03 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 622

Rep: Reputation: 136Reputation: 136
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

Last edited by eklavya; 05-12-2014 at 02:39 AM.
 
Old 05-12-2014, 04:46 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,563

Rep: Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900
I am curious why when you ran the commands the first time you placed them inside $()?
 
Old 05-12-2014, 07:01 AM   #5
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 236

Original Poster
Rep: Reputation: Disabled
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.

Last edited by battles; 05-12-2014 at 07:04 AM.
 
Old 05-12-2014, 09:38 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,563

Rep: Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] problem writing a shell script phile800 Linux - Software 7 12-07-2010 12:35 AM
Problem while writing Shell Script Rahil Parikh Linux - Newbie 5 11-29-2010 07:04 PM
problem in writing a script? sonu kumar Linux - Newbie 14 02-10-2010 06:33 AM
Problem in writing script capricorn80 Linux - Server 7 08-16-2007 07:30 AM
problem writing a script john8msu Linux - General 2 04-15-2004 04:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration