Sponsored Content
Full Discussion: Empty file check
Top Forums Shell Programming and Scripting Empty file check Post 302890390 by Akshay Hegde on Wednesday 26th of February 2014 02:05:19 PM
Old 02-26-2014
This might help you

Code:
$ touch test1
$ cat test1
$ touch test2
$ echo 'I am not empty' >test2
$ cat test2
I am not empty

Code:
#!/bin/bash



empty(){
	for file in $(echo "$*"); do 
		[ -s  "$file"  ] || return 1
	done
}

# Call function with one empty and non empty file
empty test1 test2

if [ "$?" -eq "0" ]; then
	echo "all fine"
else
        echo "something went wrong"
fi 

# Call function with non empty files
empty test2 test2

if [ "$?" -eq "0" ]; then
	echo "all fine"
else
	echo "something went wrong"
fi

Code:
$ bash test
something went wrong
all fine

---------- Post updated at 01:35 AM ---------- Previous update was at 01:30 AM ----------

what I wanted to suggest you that create function like above according to your need and play with exit code it's easy.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to check for empty file in Perl?

Hi, May I know how to check for empty file in Perl. Iam missing something, somewhere. #!/usr/bin/perl my $open_dir = '/path/'; my $file; my $ma = "abc_.*.\.psv\$" opendir(VAR, $open_dir) or die "Can't open $oepn_dir: $!\n"; while( defined ($file = readdir VAR) ) #read all... (1 Reply)
Discussion started by: deepakwins
1 Replies

2. UNIX for Dummies Questions & Answers

How to check if a file is empty?

Hi Masters..... I have problem !!! I need to check number of records in a file and if it is zero or file is empty i need to do some task. if ; then echo "File s empty" else echo "Not empty" fi so how to check this condition. I used wc -l < filename.txt => 1 for zero records same result... (1 Reply)
Discussion started by: shreekrishnagd
1 Replies

3. UNIX for Dummies Questions & Answers

to check if file is empty or not and return a non zero value

Hi All, I am new to unix worldd . I need to check a file1 if its empty or not. If its empty then return a non zero value say 99 could you pls let me know the perl script for this. (2 Replies)
Discussion started by: mavesum
2 Replies

4. Shell Programming and Scripting

check if file is empty

How do I check if a file is empty in a sh script I want to test in my shell script if the output file is empty and if it is do one thing and if it isnt empty do another? any ideas? (8 Replies)
Discussion started by: stolz
8 Replies

5. Shell Programming and Scripting

Need to check for empty file in C shell script

I am running a C shell script. I have an output file from a previous step and I need to run "something" in the next step to check if the file is empty. If the file is empty, then the job script should finish EOJ. If the file is not empty then the job script should abend. Please help Thanks. (4 Replies)
Discussion started by: jclanc8
4 Replies

6. Shell Programming and Scripting

Check if a text file is empty or not (using ls -s)

Hello, I want to make a script which says if a text file is empty or not. I tried two ways of making it, but I have problems with both of them. Now I think that the better way is the ls -s solution (considering that an empty text file has a 0 weight, because "cat file.txt" fails when file is... (4 Replies)
Discussion started by: Link_
4 Replies

7. Shell Programming and Scripting

Condition to check whether configuration file is empty or not?

CMD=$(find "${Release_Container}" -iname "${Release_Name}"_Release.txt) for i in `cat $CMD` do if ];then cd ${Sandbox_dir} CMD1=$(find "${Sandbox_dir}"/* -iname "${Release_Name}" -type d | awk -F/ '{print $(NF)}' | head -1 ) if ];then echo -e "################### CHECKOUT START... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

8. UNIX for Dummies Questions & Answers

Check if file is empty with variables, bash

Hello again! I have some trouble with scripting in bash. In the following script I read from a folder with the files line0_Ux.xy line1_Ux.xy line2_Ux.xy . . . Some of the files are empty. For those I would like to print a "0" in list. I think the problem with the code is that... (4 Replies)
Discussion started by: bjoern456
4 Replies

9. Shell Programming and Scripting

How to check if the file is empty or has blank space.?

Hi, I am using KSH. I am trying to check if the output file is empty or not. I tried with ] but what i see is my file is empty but still manages to have a size of 1 instead of 0. But my file doesnot have anything its empty. I am not sure how to check this. can any one help? (10 Replies)
Discussion started by: Sharma331
10 Replies

10. Shell Programming and Scripting

To check whether the file is empty or not in shell script (sh)

Hi All, I need to check a file whether it exists and also whether it is empty or not. I have a code for this but it is not working as per my requirement. Can anyone pls suggest me on this. function funcFLSanityCheck { if then echo "${varFLSentFileListPath}/${varFLSentFileName}... (7 Replies)
Discussion started by: Arun1992
7 Replies
NOAUTH(5)							AFS File Reference							 NOAUTH(5)

NAME
NoAuth - Disables authorization checking DESCRIPTION
The NoAuth file, if present in a server machine's /var/lib/openafs/local directory, indicates to the AFS server processes running on the machine that it is not necessary to perform authorization checking. They perform any action for any user who logs into the machine's local file system or issues a remote command that affects the machine's AFS server functioning, such as commands from the AFS command suites. Because failure to check authorization exposes the machine's AFS server functionality to attack, there are normally only two circumstances in which the file is present: o During installation of the machine, as instructed in the OpenAFS Quick Start Guide. o During correction of a server encryption key emergency, as discussed in the OpenAFS Administration Guide. In all other circumstances, the absence of the file means that the AFS server processes perform authorization checking, verifying that the issuer of a command has the required privilege. Create the file in one of the following ways: o By issuing the bosserver initialization command with the -noauth flag, if the Basic OverSeer (BOS) Server is not already running. o By issuing the bos setauth command with off as the value for the -authrequired argument, if the BOS Server is already running. To remove the file, issue the bos setauth command with "on" as the value for the -authrequired argument. The file's contents, if any, are ignored; an empty (zero-length) file is effective. SEE ALSO
bos_setauth(8), bosserver(8) COPYRIGHT
IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved. This documentation is covered by the IBM Public License Version 1.0. It was converted from HTML to POD by software written by Chas Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell. OpenAFS 2012-03-26 NOAUTH(5)
All times are GMT -4. The time now is 03:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy