LinuxQuestions.org
Review your favorite Linux distribution.
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 08-12-2018, 01:41 PM   #1
iqb.bada@gmail.com
LQ Newbie
 
Registered: Aug 2018
Posts: 2

Rep: Reputation: Disabled
Need to monitor a dir for files


Need to monitor a dir for files
if count > 0, sleep for 3min and check again for count and if count >0 then write to logfile.

if count = 0 then write to logfile(no files available)
 
Old 08-12-2018, 01:46 PM   #2
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 1,998

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
Welcome to LQ

OK. Not sure what your question is...

What have you tried?
Please review the link in my signature, especially the link there about how to ask a question.
 
1 members found this post helpful.
Old 08-12-2018, 01:54 PM   #3
iqb.bada@gmail.com
LQ Newbie
 
Registered: Aug 2018
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
Welcome to LQ

OK. Not sure what your question is...

What have you tried?
Please review the link in my signature, especially the link there about how to ask a question.
Hi
I tried the below

#!/bin/bash
dir="/tmp/test1/test"
LOG_FILE="/tmp/test1/files_mon.log"
>$LOG_FILE
count=`find $dir -type f -ls | wc -l`
if [ $count -ge 1 ]; then
sleep 10s
count=`find $dir -type f -ls | wc -l`
if [ $count -ge 1 ];
then
echo -e "Error : Files are not processed under dir $dir " >>$LOG_FILE
else
echo "INFO : All files are processed under dir $dir">>$LOG_FILE
fi
fi
 
Old 08-12-2018, 02:17 PM   #4
smaclennan
LQ Newbie
 
Registered: May 2010
Location: Ottawa, Canada
Distribution: slackware
Posts: 22
Blog Entries: 2

Rep: Reputation: 9
That script looks fine... except you don't deal with the == 0 case. What is the problem?
 
Old 08-12-2018, 02:48 PM   #5
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 1,998

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
Quote:
Originally Posted by iqb.bada@gmail.com View Post
Hi
I tried the below

Code:
#!/bin/bash
dir="/tmp/test1/test"
LOG_FILE="/tmp/test1/files_mon.log"
>$LOG_FILE  
count=`find $dir -type f -ls | wc -l`
if [ $count -ge 1 ]; then
    sleep 10s
    count=`find $dir -type f -ls | wc -l`
    if [ $count -ge 1 ];
    then
        echo -e "Error : Files are not processed under dir $dir " >>$LOG_FILE
    else
        echo "INFO : All files are processed under dir $dir">>$LOG_FILE
   fi
fi
Please use [code] tags as above when posting code or output

Does that script not work? It looks like it should, except it doesn't match the specs in your OP. The sleep should be 180s or 3m (shorter for testing, perhaps?)

What is supposed to be happening in the directory that would change the count? If that's not happening, you'll never get the else. There are but two tests in 10 secs, then the script is done.

Last edited by scasey; 08-12-2018 at 02:53 PM.
 
Old 08-13-2018, 02:56 AM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 9,917
Blog Entries: 7

Rep: Reputation: 2442Reputation: 2442Reputation: 2442Reputation: 2442Reputation: 2442Reputation: 2442Reputation: 2442Reputation: 2442Reputation: 2442Reputation: 2442Reputation: 2442
wouldn't it be better to use inotifywait/inotifywatch for this?
 
Old 08-13-2018, 11:08 AM   #7
smaclennan
LQ Newbie
 
Registered: May 2010
Location: Ottawa, Canada
Distribution: slackware
Posts: 22
Blog Entries: 2

Rep: Reputation: 9
Quote:
Originally Posted by ondoho View Post
wouldn't it be better to use inotifywait/inotifywatch for this?
Quite possibly. But if it really does take minutes for the files to be processed, the script as shown is pretty simple with no real parsing necessary.
 
  


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
BASH checking DIr for empty of certain files before deleteing everything + dir BW-userx Programming 14 11-19-2015 01:37 PM
copying files from home dir to another dir from another dir in a lower dir chomito44 Linux - General 5 10-19-2013 07:18 PM
Move files contained in source dir to destination dir, but not source dir itself unixunderground Linux - Software 3 09-20-2013 12:17 PM
tar dir and sub dir removing files but not existing not empty dir j-me Linux - General 2 08-12-2013 12:37 PM
Command to display /dir, /dir/sub, /dir/sub/files knockout_artist Linux - Newbie 9 10-25-2007 03:57 PM

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

All times are GMT -5. The time now is 12:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration