Oops. vivekrag has read the requirement. In this problem a file counts as empty if it only contains a header line.
Mail is machine-specific. Please state what Operating System you have and which mail client you use.
Yeah gwrm,its simple as Karthik told,you can store it in an array or file whatever you want.Here I did some changes in my script to fulfill your requirement.
I assume your CSV file will have 1 line if it has only headers. My below code will check number of lines in a file & keeps track in log.txt file. This log.txt file is emailed at last. Hope this helps.
You can tell if a file is empty using the -s file operator (-s means "exists and has nonzero size"). For example:
If you want to do something to files that exist and are empty you can combine this with the -e ("exists") operator, like this:
I'm not entirely sure if that's the answer you were looking for, but that's my two cents worth.
The file operators are:
-a $file : file exists
-d $file : file is a directory
-e $file : file exists
-f $file : file is a regular file (not a directory or symbolic link)
-G $file : you are in the group that owns file
-h $file : file is a symbolic link
-N $file : file has been modified since it was last read
-O $file : you own file
-r $file : you have read permission on file
-s $file : file exists and is not empty
-w $file : you have write permission on file
-x $file : you have execute permission on file
$file1 -nt $file2 : file1 is newer than file2
$file1 -ot $file2 : file1 is older than file2
As an aside, I think Perl has a wider range of file operators than bash, so that may be something to explore.
I have a script, which is supposed to run 1 day of the month, connect to remote server certain directory, find files, tar the, and copy
find . -ctime -1 | tar -cvf transfer_dmz_start_monthly.tar *${Today}*.*;
if
then
echo "Cannot create a tar file, the terminated... (2 Replies)
Hello
So i have that script collection, in which i have a single script to create a configuration file.
In there, i have multiple occourences of something like this:
prj_title=$(tui-read "What is the TITLE? ($prj_name):")
] && prj_title="${prj_name/_/ }"
They all work as expected, if... (5 Replies)
Hi gurus ,
I have two files and i want to perform different action based on the condition if both or either is empty
If
then
Do something
elif
then
do something
elif
then
do something
else
do something
fi
I have tried the below bt its not... (4 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
1.pls tell me the command for checking whether a given directory is empty or not .
2. can i check what is the... (1 Reply)
1.pls tell me the command for checking whether a given directory is empty or not .
2. can i check what is the last copied item in a directory .
and i yes , i want to move that last copied item in another directory .
pls help me with shell code for these two tasks
thanks (1 Reply)
I need to check if a directory is empty using an if condition
in the pseudocode below
if ; then
else
although i looked at a few forums on this topic, I left feeling a little unclear and i could not use the command successfully
what can i substitute in the if conditon above,... (2 Replies)
I have the list of users in user.log, under each user folder there is sub1 folder is there. i want to check whether sub1 is empty or not, if it is empty i have to skip that user user folder and iterate next user folders. i have the sample code,its not giving not proper results.
while read line... (8 Replies)
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)
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)
Hello All,
I have written shell script whcih at the max 3 parameters.
When only one commandline argument and other two command line arguments are passed as empty string like
eg : archive ' ' ' '
Then i need to check whether the commandline... (12 Replies)