LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03:51 PM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

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, 05:09 PM   #2
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

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, 01:03 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
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 01:39 AM.
 
Old 05-12-2014, 03:46 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

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

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 06:04 AM.
 
Old 05-12-2014, 08:38 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

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



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-06-2010 11:35 PM
Problem while writing Shell Script Rahil Parikh Linux - Newbie 5 11-29-2010 06:04 PM
problem in writing a script? sonu kumar Linux - Newbie 14 02-10-2010 05:33 AM
Problem in writing script capricorn80 Linux - Server 7 08-16-2007 06:30 AM
problem writing a script john8msu Linux - General 2 04-15-2004 03:59 PM

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

All times are GMT -5. The time now is 02:56 AM.

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
Open Source Consulting | Domain Registration