File existence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File existence
# 8  
Old 11-12-2014
By mistake I had -mtime (days) instead of -mmin (minutes) in my post.
Now corrected.

---------- Post updated at 06:39 AM ---------- Previous update was at 06:30 AM ----------

The HP-UX find does not have -mmin.
For simply testing if files exist you better use a file_exists function.
# 9  
Old 11-12-2014
Quote:
Originally Posted by haadiya
Hi,thanks for replying to my post.the above script will return files which is older than 2 hours or empty.I want a script to monitor a folder for new incoming files. if the folder has empty/incomplete file in last 2 hours then trigger something.

i can have a cron to check the folder for incoming new files

Code:
while [ 1 ]; do                        
  if [ -e /dir_name/*.txt ];
    echo "File is found"             
    exit 0
  fi
  sleep 60

but the above code would list all *.txt files when cron job is invoked.the folder is not empty.
in my folder i have files like
abc001.txt
abc002.txt
abc003.txt
------
------
But I want a script that checks my folder for incoming files.If the folder has empty/incomplete file in last 2 hours then trigger something.

OS:HP-UX
That won't work if more than one file matches your pattern.
# 10  
Old 11-12-2014
You can create a file with a timestamp of your choosing and then use the find command to select files that are newer than it.

Would that help?



Robin
# 11  
Old 11-12-2014
Yes, use "touch: to make a mark file and "find ... -newer mark. Now, you may need a utility to give date-time 2 hours ago. I wrote a utility much like GNU date, one solution, but tailored to do any to any +- any time: tm2tm, whose source in in here: "date" difference between FreeBSD & Linux

You can get GNU date here: HP-UX Porting and Archiving Centre | sh_utils-2.0

You can get GNU find here: HP-UX Porting and Archiving Centre | findutils-4.4.2

Last edited by DGPickett; 11-12-2014 at 01:40 PM..
# 12  
Old 11-13-2014
Thanks for the reply .I couldnt use -mmin along with find in HP-UX

Code:
find: bad option -mmin

# 13  
Old 11-13-2014
You can also tweak your TZ variable. For me in the UK, TZ=GMT0BST so to go two hours back I could do this:-
Code:
ORIG_TZ=$TZ
TZ=GMT2BST
date '+%Y %m %d %H %M %S' | read year month day hours minutes seconds
TZ=$ORIG_TZ

touch -mt ${year}${month}${day}${hours}${minutes}.${seconds} /tmp/my_ref_file
ls -l /tmp/my_ref?file
find . -newer /tmp/my_ref_file -type f -name "pattern*match"

Does something like this help? Note the dot before the ${seconds}This tweak works for me on HPUX, AIX, Solaris, but not RHEL. Not sure what I'm doing wrong there, but for that, you can use the GNU date commands more like this:-
Code:
date --date='2 hours ago' '+%Y %m %d %H %M %S'



I hope that this helps,
Robin
# 14  
Old 11-21-2014
Sometimes it is good to sleep a second after creating a 'find -newer' marker file, so no more files are created/modified for that second. Computers are fast, and a second can be more than long enough.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

2. Shell Programming and Scripting

File existence

Hi I'm using the below command in shell script to check for file exists in the path if ..... fi path and test are variables path and the file exists but the commands inside if condition is executed (! operator used) Is the above way of checking for file existence is correct? ... (4 Replies)
Discussion started by: vinoth_kumar
4 Replies

3. Shell Programming and Scripting

Parse file from remote server to calculate count of string existence in that file

Hi I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files. Say a file abc.log exist on 2 servers. I want to search for string "test" on both files and calculate the total count of search string's existence. For... (6 Replies)
Discussion started by: poweroflinux
6 Replies

4. Shell Programming and Scripting

File existence and increment

count=0; while read line; do ] && let count=count+1; done < file_name.txt echo echo "$count of 10 files found " echo The scenario is a follows : I have a file which contains a list of filenames present in particular directory . I am checking fo the existence of the file and... (5 Replies)
Discussion started by: ultimatix
5 Replies

5. AIX

Check for File Existence

I have requirement where i need to search for files which start with SALESORDER and PURCHASEORDER. i need to process the files with SALESORDER first and then PURCHASEORDER. If SALESORDER files are not there i dont want to process PURCHASEORDER and i want to come out of script. I have written a code... (4 Replies)
Discussion started by: dsdev_123
4 Replies

6. AIX

check for file existence

Hello I am having a requirement like if there is no file in the directory then i need a message to pop on after the execution of the script. My script basically does for File in `ls -t $DIRECTORY | tail -1`; if there is no file the DIRECTORY then the script is simply exiting with out... (2 Replies)
Discussion started by: dsdev_123
2 Replies

7. Shell Programming and Scripting

File existence using ls

Hi I want to check a particular file is available or not. But i know only the pattern of that file sat AB1234*.txt.I need the latest file name and it ll be used in the script. How can i do this using ls -ltr command. Thanks, LathishSundar V (2 Replies)
Discussion started by: lathish
2 Replies

8. Shell Programming and Scripting

checking file existence

Hi, My requirement was to check the existence of a file having a specified pattern.The way i tried to achieve this was if ; then echo "File found" fi an example file having this pattern was 'ilvs_trace01.0124'. it will vary... (3 Replies)
Discussion started by: DILEEP410
3 Replies

9. Shell Programming and Scripting

File existence

Hey all, I have total new with shell scripting so I don't know if what I need to do even possible, here it is...for a duration of time (say...1 hour) I need to check for the existence of a particular file, if it exists then I will invoke a java program or I will continue to check until a)... (2 Replies)
Discussion started by: mpang_
2 Replies

10. UNIX for Dummies Questions & Answers

Loop for file existence

I wasn't sure if I should post it here of in the Shell Script category, but I figured it was definitely a newbie question. I'm trying to write a script that will check for the existence of a specific file (or for any files within the directory) and then take specific actions. I've removed all... (2 Replies)
Discussion started by: bd_joy
2 Replies
Login or Register to Ask a Question