I am trying to write a script which will check if the filesize is grather than 0 KB, compress the file and send to the email list else if the file size is zero KB don't send a mail update the log
When I am executing the script I am getting the below error
Please let me know where I am doing it wrong.
And if we compress the file and email, can we extract in windows using the normal winzip software?
I am trying to write a script which will check if the filesize is grather than 0 KB, compress the file and send to the email list else if the file size is zero KB don't send a mail update the log
When I am executing the script I am getting the below error
Please let me know where I am doing it wrong.
And if we compress the file and email, can we extract in windows using the normal winzip software?
Thanks and Regards,
Mora
The file size in ls -l output is field 5; not field 1. Try: if [ `ls -l /tmp/file.txt | awk '{print $5}'` -eq 0 ]
but as RavinderSingh13 suggested (but I think he reversed the desired outcome), a much more efficient test is:
Last edited by Don Cragun; 12-02-2014 at 05:17 AM..
Reason: Add more efficient test.
Let's start with the reason why you're getting the error message.
In short: You are doing the comparison on the wrong field.
The awk command you used returns the first column ($1) from the output of ls -l /tmp/file.txt.
I illustrated the different fields below
Note that the fields shown here might vary from system to system and thus it is no good practice to parse the ls -l output.
If you want to stick to your approach for whatever the reason, you need to change $1 in your awk command to $5, respectively to the field number that contains the file size on your system (verify in the shell first).
The second solution RavinderSingh13 has posted is probably the best alternative.
---
Another problem is that your code says if the filesize is 0, then send mail, but it should echo "No errors" if the filesize is 0.
So either you interchange the commands in the then and else section, or you change -eq to -gt
---
You are sending the email without attachment...
Below should zip the file and attach it to the email
When using zip, you should be able to unzip it on a windows machine.
Last but not least, maybe, before zipping the file, you will need to replace the UNIX/Linux newline character with Windows' equivalent using unix2dos (https://en.wikipedia.org/wiki/Unix2dos) or something, so that the text file can be properly displayed on Windows.
I am trying to check whether two files are empty or not using below if condition but its checking for only one file
if ]
Again I tried
if && ]
Need your assistance (2 Replies)
I have been a long time lurker, and have learned a lot from these forums, thank you to everyone.
I am using Zoneminder to record a security camera feed. No motion detection, just 24 hour recording. I then have a script that checks Mysql for events dated the day before, and throws them at... (4 Replies)
if ; then
cp /tmp/testfolder/*.* ~/new/logs/
else
echo "No files today"
exit
fi
The problem is this doen't work when there is more than 1 file. Please tell me how to
take the latest file and check the size of the file in a directory (1 Reply)
I want to write a batch job (ksh) with the following requirement
we have file feeds coming to our system from other team,
if the file size is greater than expected then we dont need to process the file for the day
and need to archive the file and send email notification to the manager saying... (5 Replies)
I have following script on AIX/KSH
if ] ; then
echo "filename exists and is > 0 bytes"
else
echo "filename does not exist or is zero length"
fi
It is not working. What is wrong here??? (3 Replies)
Hi All,
I am in small problem..
i have one script which transfers some big files to my ftp usign normal command like put ....
my problem is how to check whether my file have been transferred successfully on ftp or not...
i know only inside ftp we have option like 'size' command which... (2 Replies)
Hi Friends,
i am trying to write a shell script which will check for the logfile size.
if the content of the logfile is wc -l >=1 then send mail with log file as attachment.else do nothing.
i'm trying the below code can any one help on this
if ]
then
(echo "`cat... (2 Replies)
How can I perform size check of any character file(which switch)?
For example: I have to perform certain actions if file size is not zero. How can I do that?
Is this syntax fine?
if test ! -z $filename
then
fi (2 Replies)