check presence of input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check presence of input file
# 1  
Old 10-01-2009
check presence of input file

My script is taking a file "input.in" as input for running the script. My worry is that i need to execute the script only if the file is present, if it's not don't perform the next commands.

Just to have a check at the beginning of the script : If "input.in" exists, then go on. If it's does not exist exit.
# 2  
Old 10-01-2009
Code:
if [ -f input.in ] ; then

  DO THE JOB

else

  exit

fi

# 3  
Old 10-01-2009
Thank you, it's OK !

---------- Post updated 02-10-09 at 12:19 AM ---------- Previous update was 01-10-09 at 07:29 AM ----------

Hello again,

Now i need to test if the input file "input.in" exists and if it's NOT empty, then execute next commands. Else exit

Thanks in advance,
# 4  
Old 10-01-2009
Hi

Code:
[ -s file ]

Read the man page for your shell. It tells you all you need to know.
# 5  
Old 10-01-2009
Thank you !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if 2 input values exists in a file

I have a file number.txt.I need to get 2 inputs from the terminal like a=100 and b=200.If a and b are there in the file,then check if a < b,print "less".If a is not there in the file,print "a is missing" or if b is not there in the file,print "b is missing". number.txt: 100 200 300 (2 Replies)
Discussion started by: aneeta13
2 Replies

2. Shell Programming and Scripting

Check file presence and delete other file

Hello, I have file all_file.txt at the end of process this file all_file.txt should be deleted only if there is no file present in dir /all_file/tmp/ or in it's sub directory. can you please help me with the peace of code for this. Thanks (2 Replies)
Discussion started by: kumar30213
2 Replies

3. Shell Programming and Scripting

Check presence of trigger file

Hi, I make a sftp connection successfully.My requirement is the script shall execute only after i find a trigger file(dailyreport.OK.psv) in the remote dir. If the trigger file is not present ,the script should exit else it should continue with the rest of the scripts statements. Below code is... (13 Replies)
Discussion started by: samrat dutta
13 Replies

4. Shell Programming and Scripting

Check if file is present using input from another file

Hello, I have a comma delimited file such as: cat /statistics/support/input.txt ID,Serial,quantitity,atribute1,atribute2 1,89569698,5,800,9900, 1,35568658,8,1200,5550 1,89569698,8,320,5500 1,68753584,85,450,200 ID should always have 1 digit, Serial 8 digits, and the others may... (2 Replies)
Discussion started by: alex2005
2 Replies

5. Shell Programming and Scripting

Check input file with different criteria

HI Input file.txt ABCDE1 JFHFJFJF3 10 ABCDE2 JFHFJFJF5 20 ABCDE3 JFHFJFJF5 30 ABCDE4 JFHFJFJF6 - ABCDE5 JFHFJFJF6 20 ABCDE6 JFHFJFJF6 90 ABCDE7 JFHFJFJF6 9 ABCDE8 JFHFJFJF6 I want to check third column if data missing or wrong data the echo massage and out from script. 1.... (8 Replies)
Discussion started by: pareshkp
8 Replies

6. Shell Programming and Scripting

Check the presence of file >size?

Hi, Following script work fine: #!/bin/bash FILE=$1 if ; then echo Yay else echo Boo fi But I would like to add another condition that if FILE... (3 Replies)
Discussion started by: nrjrasaxena
3 Replies

7. Shell Programming and Scripting

Input file check

Hi, I have a script which runs daily. It gets 3 input files test1,test2,test3. I want to do a validation in my script to make sure i have all the 3 files available before running. If any one of the file is missing i want to break the script. Could you please help me with this request. ... (1 Reply)
Discussion started by: Krrishv
1 Replies

8. Shell Programming and Scripting

check file for presence of set of strings

hi everybody, I need a quick help with this issue. I have configuration file in which the following set of strings must be present. I need to check it with the bash script (leading spaces are not significant). Check must be case insensitive. Can anybody help? ... any lines <SECTION... (4 Replies)
Discussion started by: sameucho
4 Replies

9. Shell Programming and Scripting

How to check field formatting of input file?

Hi, I had input file with below data, abcdefghij;20100903040607;1234567891;GLOBAL; Having values of fields with seperated by semi-colon (;) and ended with line feed (\n). Through shell script, how can I check the field formatting? Thanks in advance. (18 Replies)
Discussion started by: Poonamol
18 Replies

10. OS X (Apple)

command to check presence of volume

Hi: I'm not really a programmer, but I've created a small logout hook script to copy some specific directories to a server volume when a user logs out (10.6.4). These is a laptop user, so I'm looking find: 1) the command to check if the volume (including path to directory?) is available. ... (1 Reply)
Discussion started by: kevinmmac
1 Replies
Login or Register to Ask a Question