File Exists


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Exists
# 8  
Old 02-20-2010
The manpage for "if" is called test(1), in the manpage you will see that -f switch tests that the file exists and that the -s switch tests for a file existing and being bigger than zero bytes in size, the ! before a switch inverts its meaning.
# 9  
Old 02-20-2010
File Exists

Hi,

I am getting an error 0403-021 charater Missing.

Vishal
# 10  
Old 02-21-2010
If your shell is posix compatible, then syntax is correct.
posix-sh, ksh, bash, bourne-shell sh, zsh, ash, dash, ...

echo $0
# 11  
Old 02-21-2010
Java

Please post your script which gave the error.

My interpretation of the problem is as as follows. This incorporates a subtle syntax change in the if ... and ... and ... .

Code:
if [ -f a.txt -a -f b.txt -a -f c.txt ]
then
        if [ ! -s b.txt ]
        then
                # All 3 files exist but b.txt is empty
                echo "Rerun informatica process"
                exit
        else
                # All 3 files exist and b.txt is not empty
                # Continue process
                :
        fi
else
        # One or more files is missing presumably an error
        echo "One of more files is missing"
        exit
fi
# Normal process starts here

# 12  
Old 02-22-2010
File Exists

Hi,

thank you ver much script is working now, one more question i need to make sure all the files is of today's date and time stamp.

any workaround for that.

Vishal
# 13  
Old 02-22-2010
here is another way

Code:
#!/bin/bash

# files we need to verify if they exist

ExistPath=("/path/to/file1.txt
                  /path/to/file2.txt
                  /path/to/file3.txt

")

for file in $ExistPath ; do

   if [[ -e $file ]]

   then /bin/echo "$file exists"

   else /bin/echo "$file does not exist"

    #now touch the file to update the time/date modified

   /usr/bin/touch $file
   
   fi

done

exit 0

I am not sure if the touch will still go through the loop as coded. I think closing out the if may kill the loop, but not sure.
# 14  
Old 02-22-2010
Validate timestamp

Thanks for the code.But i wanted to check if the file which exists in the folder has the timestamp of todays date, and if so has data in it which is greater than 0 so that i could go forward and process the file through the informatica process.Could you help me out with this.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File exists or not

Dear All, I am facing a small issue in my code where in I am searching for a file in a directory and if found it sends me a message along with the time and filename. However if a file is not found based on the search pattern, the result which I am getting is all the files present in that... (7 Replies)
Discussion started by: grvk101
7 Replies

2. Shell Programming and Scripting

Search if file exists for a file pattern stored in array

Hi experts, I have two arrays one has the file paths to be searched in , and the other has the files to be serached.For eg searchfile.dat will have abc303 xyz123 i have to search for files that could be abc303*.dat or for that matter any extension . abc303*.dat.gz The following code... (2 Replies)
Discussion started by: 100bees
2 Replies

3. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

4. Windows & DOS: Issues & Discussions

Script that, if file exists in Samba share, moves file to Unix server

I'm looking to do pretty much what the title says. I want a script that runs, it can run on Unix or Windows, doesn't matter, and searches a Samba shares for a .txt file. If the file exists, the script will move (or possibly copy) the file from the Samba share into a directory on our Unix... (3 Replies)
Discussion started by: twcostello
3 Replies

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

6. Shell Programming and Scripting

Newbie.. Find if a file exists and open, if not create the desired file..

Hey all, I'm brand new to script writing, I'm wanting to make a script that will ask for a file and then retrieve that file if it exists, and if it doesn't exist, create the file with the desired name, and I'm completely stuck.. so far.. #! bin/bash echo "Enter desired file" read "$file" if ... (5 Replies)
Discussion started by: Byrang
5 Replies

7. Shell Programming and Scripting

Grep pattern from different file and display if it exists in the required file

Hi, I have two files say xxx.txt and yyy.txt. xxx.txt is with list of patterns within double quotes. Eg. "this is the line1" "this is the line2" The yyy.txt with lot of lines. eg: "This is a test message which contains rubbish information just to fill the page which is of no use. this is... (3 Replies)
Discussion started by: abinash
3 Replies

8. Shell Programming and Scripting

file exists

hello, I want to know if a file exists, but do not know contador = 0 while(file$contador exists) do bla bla bla contador=$(($contador+1)) done how can i do it? thanks (4 Replies)
Discussion started by: uri_crack
4 Replies

9. Shell Programming and Scripting

Need to write a script in UNIX to find a file if another file exists

So I have a lot of Java applications on my servers all having their own folder from the applications subdirectory. Now, I need to do the following. Search all the applications subdirectories for message.jar. If the message.jar file exists, I need to search the application directory for... (1 Reply)
Discussion started by: mmdawg
1 Replies

10. Shell Programming and Scripting

Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things: STEP 1) Verify that the file arrived in morning. STEP 2) Compare the file size of the current... (3 Replies)
Discussion started by: rbknisely
3 Replies
Login or Register to Ask a Question