Check daily files arrival in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check daily files arrival in a directory
# 1  
Old 09-27-2014
Check daily files arrival in a directory

Hi All,

I wanted to write a script to check if set of files exist in a directory or not for a particular day. each file has a date stamp. Now i want to implement this -
-i can check files of a particular date in a particular folder
-generate log and send it to through email.

Big THANKS !! in advance.
# 2  
Old 09-27-2014
What have you tried so far?
# 3  
Old 09-27-2014
Hi pilnet101,

Thanks for your reply.
I am just beginner in unix and wrote this code with the help of online tutorials so far for 2 files -
Code:
#!/bin/bash

echo "Enter date of file"
read date;
for x in {1}  ; 
do
    if [[ -f "new1_$date.txt" ]]; then
        echo "new1_$date.txt is a present"
    else 
        echo "BOOOOO...new1_$date.txt is absent"
fi
	if [[ -f "new2_$date.txt" ]]; then
        echo "new2_$date.txt is a present"
    else 
        echo "new2_$date.txt is absent"
    fi

if [[ -f "new3_$date.txt" ]]; then
        echo "new3_$date.txt is a present"
    else 
        echo "new3_$date.txt is absent"
    fi


done


but this isn't working for all files.

i have files like this -
Code:
howdy_20140925_XXXX.txt
hello_20140925_xxxx.txt
Fine_20140925.2599

these files come daily and i need to write script to check whether they come or not.

Thanks.

Last edited by Franklin52; 09-27-2014 at 06:24 PM.. Reason: Please use code tags
# 4  
Old 09-27-2014
Please use [ code ] tags around your code, makes it much easier to read AND help fixing it....
Also, what is the output you get?
# 5  
Old 09-27-2014
In recent bash, you could use extended pattern matching (cf. man bash) to get your result:
Code:
[ 3 -eq $(ls @(Fine|hello|howdy)*$date* | wc -w) ] && echo good || echo bad

# 6  
Old 09-28-2014
What irritates me is this, in the script you check for "new[1-3]$date.txt", but you have files named "hello,hody,Fine" which is about same weird.

Code:
read -p "Please enter the date: " date
list=($(ls *$date*))
[[ -z "$list" ]] && echo "No files with this date ($date) available" && exit 1
for F in "${list[@]}";do
    echo "Found file: $F"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check for files and move it to another directory - ksh

I'm trying to wirte ksh script for given requirement, but i unable to achive it. In dir1 directory I need to check for the files which suffixed with .csv or .txt, If there is no files, then i need to exit. If any files found I need to move the each file found to dir2 directory. I have to repeat... (4 Replies)
Discussion started by: Kayal
4 Replies

2. Shell Programming and Scripting

How to check total files size in hdfs directory?

Is there a way to calculate the total file size of HDFS file directory in GB or MB? I dont want to use du/df command. Without that is there a way HDFS Directory - /test/my_dir (1 Reply)
Discussion started by: rohit_shinez
1 Replies

3. Shell Programming and Scripting

Check Directory for files & Email

I'm working on a bash script to move files from one location, to two. The first part of my challenge is intended to check a particular directory for contents (e.g. files or other items in it), if files exists, then send the list of names to a txt file and email me the text file. If files do not... (4 Replies)
Discussion started by: Nvizn
4 Replies

4. Shell Programming and Scripting

How to check whether directory has files in it or not in shell script?

hi, I am having script in which i want to check if directory has any file in it or not. If directory contains a single or more files then and only then it should proceed to further operations... P.S.: Directory might have thousand number of files. so there might be chance of getting error... (4 Replies)
Discussion started by: VSom007
4 Replies

5. Shell Programming and Scripting

Daily health check script

Hi I am still learning how to write shell scripts, so I started to write a script like this: #!/bin/sh date echo outputOK () { echo $1 "" } outputOK () { echo $1 "" } for vol in `/usr/bin/grep -E 'hfs|vxfs|nfs|cifs' /etc/fstab | egrep -v '^#' | awk '{ print $3 }'` do if... (7 Replies)
Discussion started by: fretagi
7 Replies

6. Shell Programming and Scripting

Creating directory daily basis...

Need help on this script. the month is not changing to February... #!/bin/bash for X in `seq 1 100` do DATE=`date +%Y-%m-%d "--date=${X} day ago"` Y=`date +%Y` M=`date +%m` D=`date +%d "--date=${X} day ago"` DIR=/home/LogBackup for i in `seq 1 ` do if ;then # ... (1 Reply)
Discussion started by: alelee
1 Replies

7. Shell Programming and Scripting

Check if certain files exist in a directory, if not add name to a textfile

We recieve some logs on our windows box via FTP on a daily basis, in the same directory. I would like to check for missing logs files and add their name to a text file. Something like... Check if C:\logs\file1_currentdate exists (if not, add file1_currentdate to... (1 Reply)
Discussion started by: SunnyK
1 Replies

8. Shell Programming and Scripting

Zip all the files within a directory on a daily basis

I need to zip all the files within a directory on a daily basis and store them as a zip file within that directory with the date in its naming convention I have file extentions .log .lst and .out's within that directory How do i do this task zip -mqj mydir/allzip$YYMMDDDD.zip mydir/*.* ... (5 Replies)
Discussion started by: ramky79
5 Replies

9. AIX

Daily check helth

Can any one suggest some command that used to test the hardware and software (4 Replies)
Discussion started by: magasem
4 Replies

10. Shell Programming and Scripting

How to check if 3 files have same size in directory

I need to determine if any three files have the same file size in a specified directly? I have got as far as listing the file sizes but where to go from here? ls -al |sort -n -r +4 | awq '{print $5}' Thanks in anticipation (5 Replies)
Discussion started by: oggle
5 Replies
Login or Register to Ask a Question