Script to Identify if folder has a file in it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to Identify if folder has a file in it
# 1  
Old 07-13-2011
Script to Identify if folder has a file in it

Hi everyone I am new to the forums.

I haven't done much linux myself but I have been asked if I can do the following.

Write a linux script that needs to scan a certain folder every x amount of minutes and if there is a file in the folder then it needs to call a different script.

Is this all possible?
Can some1 create/guide me through the script.
This is not my current work line so I am quite lost.

Thanks a million in advance.
Hope to hear from you guys soon.
# 2  
Old 07-13-2011
This script will check whether the current directory has any file ( atleast one file)

If the file is present, then it will trigger the script and wait for script execution and exit.

if the file is not present, then wait for 60 seconds, then again check whether any file is present in the directory or not

Code:
while [ 1 ]
do
 fileCount=`ls | wc -l`
 if [ "$fileCount" -ne "0" ] 
 then
  #Trigger the Script
  /home/abc/script.sh
  wait
  exit $?
 else
  sleep 60
 fi
done

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 07-13-2011
Thank you for the quick response, busy looking at it now Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Red Hat

Identify the folder is part of which mount point

Dear, I am using Redhat 6.6 . How to identify a given directory is part of which mount point. (2 Replies)
Discussion started by: aneesha
2 Replies

3. Shell Programming and Scripting

Mv series out of mixed folder & identify substring

Dear unix-Community, great to be here! Actually i try to build a script to sort out my serials into an series-folder. Reason is: plex cant handle mixed folder filled with other stuff than series only. First shot was ls in combination with grep and regex. Got no positiv result. Then i... (3 Replies)
Discussion started by: Zack
3 Replies

4. Shell Programming and Scripting

File to Folder script

I am trying to write a linux shell script that will take every file in a folder /home/user/desktop/fileme and place it in a folder with the same name as the folder before /home/user/desktop/fileme/stuff.txt /home/user/desktop/fileme/other.avi /home/user/desktop/fileme/last.jpg after... (2 Replies)
Discussion started by: FustFust
2 Replies

5. Shell Programming and Scripting

Bash script for new file in ftp folder

Hello, I'm trying to make a bash script that send me e-mail if there is any new file in my ftp folder. cat inotify.sh #!/bin/sh /usr/bin/inotifywait -e create \ -mrq /home/mrowcp | while read line; do echo -n "$line " >> /var/log/inotify.log echo `date | cut -d " " -f1-4` >>... (3 Replies)
Discussion started by: mrowcp
3 Replies

6. Shell Programming and Scripting

Help with parsing mailbox folder list (identify similar folders)

List sample: user/xxx/Archives/2010 user/xxx/BLARG user/xxx/BlArG user/xxx/Burton user/xxx/DAY user/yyy/Trainees/Nutrition interns user/yyy/Trainees/Primary Care user/yyy/Trainees/Psychiatric NP interns user/yyy/Trainees/Psychiatric residents user/yyy/Trainees/Psychology... (4 Replies)
Discussion started by: spacegoose
4 Replies

7. Shell Programming and Scripting

Script that delete a File when a DEL File will be placed in same folder

Hi there, i have a question. I have a folder called /usr/test There is a file in it.... test.csv I need not a shell script that checks if there is a file called: test.del And if the file is in the same folder then the script should delete the test.csv and also the test.del. Hope... (9 Replies)
Discussion started by: Bjoern28
9 Replies

8. Shell Programming and Scripting

shell script for moving all the file from the same folder

Hi , I need a shell script which basicaly moves all the files from one folder say folder x to folder y and once they are moved to folder y a datetimestamp should be attached to there name for ex file a should be moved to y folder and renamed as a_20081015 (1 Reply)
Discussion started by: viv1
1 Replies

9. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

10. Shell Programming and Scripting

Script to find a file in the other folder

Hi, I have two folders in two different directories.Both the folders contain set of text files. The name of the files are same in both the folders. I need to write a script to compare all the files in both the folders having same name. I am new to unix. Can you help me out in giving a script to... (4 Replies)
Discussion started by: ragavhere
4 Replies
Login or Register to Ask a Question