Sponsored Content
Top Forums Shell Programming and Scripting Help to Monitor the existence of a file Post 302371747 by Scott on Monday 16th of November 2009 06:20:10 AM
Old 11-16-2009
Using a test with one of these that suits you:

Code:
i.e.
if [ -r SomeFile ]; then ...
...
fi



       -a file
              Same as -e below.  This is obsolete.
       -b file
              True, if file exists and is a block special file.
       -c file
              True, if file exists and is a character special file.
       -d file
              True, if file exists and is a directory.
       -e file
              True, if file exists.
       -f file
              True, if file exists and is an ordinary file.
       -g file
              True, if file exists and it has its setgid bit set.
       -k file
              True, if file exists and it has its sticky bit set.
       -p file
              True, if file exists and is a fifo special file or a pipe.
       -r file
              True, if file exists and is readable by current process.
       -s file
              True, if file exists and has size greater than zero.
       -t fildes
              True, if file descriptor number fildes is  open  and  associated
              with a terminal device.
       -u file
              True, if file exists and it has its setuid bit set.
       -w file
              True, if file exists and is writable by current process.
       -x file
              True,  if  file exists and is executable by current process.  If
              file exists and is a directory, then true if the current process
              has permission to search in the directory.
       -L file
              True, if file exists and is a symbolic link.
       -h file
              True, if file exists and is a symbolic link.
       -N file
              True,  if  file exists and the modification time is greater than
              the last access time.
       -O file
              True, if file exists and is owned by the effective  user  id  of
              this process.
       -G file
              True,  if  file exists and its group matches the effective group
              id of this process.
       -S file
              True, if file exists and is a socket.
       file1 -nt file2
              True, if file1 exists and file2 does not, or file1 is newer than
              file2.
       file1 -ot file2
              True, if file2 exists and file1 does not, or file1 is older than
              file2.
       file1 -ef file2
              True, if file1 and file2 exist and refer to the same file.

These are for ksh, other shells may vary. Check the man page.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

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. 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

6. 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

7. Shell Programming and Scripting

Existence of a string in a file

Hi, I want to know whether a string or variable is exists in a perticular file or not. I want to use IF command in cshell. I am not sure how to use it. can any one help me.. (2 Replies)
Discussion started by: arup1980
2 Replies

8. 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

9. Shell Programming and Scripting

Checking for the file existence

Hi, I have written a script to validate the data file by referreing to the configurtion file. And moving the validated good records and bad records into HDFS. Suppose after 15 mins if i receive one more data fie,then after validation the good and bad records shold be stored in hadoop with the... (8 Replies)
Discussion started by: shree11
8 Replies

10. Shell Programming and Scripting

File existence

Hope someone can help me on this In a directory ,files are dynamically generated.I need a script to do the following if files are not received for more than 2 hours or if the received file is empty then do something How can I put that in a script.Thank you eg. in cd /dir_name the... (13 Replies)
Discussion started by: haadiya
13 Replies
TEST(1) 						      General Commands Manual							   TEST(1)

NAME
test - set status according to condition SYNOPSIS
test expr DESCRIPTION
Test evaluates the expression expr. If the value is true the exit status is null; otherwise the exit status is non-null. If there are no arguments the exit status is non-null. The following primitives are used to construct expr. -r file True if the file exists (is accessible) and is readable. -w file True if the file exists and is writable. -x file True if the file exists and has execute permission. -e file True if the file exists. -f file True if the file exists and is a plain file. -d file True if the file exists and is a directory. -s file True if the file exists and has a size greater than zero. -t fildes True if the open file whose file descriptor number is fildes (1 by default) is the same file as /dev/cons. s1 = s2 True if the strings s1 and s2 are identical. s1 != s2 True if the strings s1 and s2 are not identical. s1 True if s1 is not the null string. (Deprecated.) -n s1 True if the length of string s1 is non-zero. -z s1 True if the length of string s1 is zero. n1 -eq n2 True if the integers n1 and n2 are arithmetically equal. Any of the comparisons -ne, -gt, -ge, -lt, or -le may be used in place of -eq. The (nonstandard) construct -l string, meaning the length of string, may be used in place of an integer. These primaries may be combined with the following operators: ! unary negation operator -o binary or operator -a binary and operator; higher precedence than -o ( expr ) parentheses for grouping. The primitives -b, -u, -g, and -s return false; they are recognized for compatibility with POSIX. Notice that all the operators and flags are separate arguments to test. Notice also that parentheses and equal signs are meaningful to rc and must be enclosed in quotes. EXAMPLES
Test is a dubious way to check for specific character strings: it uses a process to do what an rc(1) match or switch statement can do. The first example is not only inefficient but wrong, because test understands the purported string "-c" as an option. if (test $1 '=' "-c") echo OK # wrong! A better way is if (~ $1 -c) echo OK Test whether is in the current directory. test -f abc -o -d abc SOURCE
/sys/src/cmd/test.c SEE ALSO
rc(1) TEST(1)
All times are GMT -4. The time now is 01:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy