Sponsored Content
Full Discussion: Check file size and mail
Top Forums UNIX for Dummies Questions & Answers Check file size and mail Post 302927303 by Don Cragun on Tuesday 2nd of December 2014 03:11:23 AM
Old 12-02-2014
Quote:
Originally Posted by mora
Hi,

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

Code:
if [ `ls -l /tmp/file.txt | awk '{print $1}'` -eq 0 ]
then
echo "Validate the file" | mailx -s " There are errors : " ${EMAIL_LIST}
else
echo "No Errors" > log_file
fi


When I am executing the script I am getting the below error
Code:
 [: -rw-r--r--: integer expression expected

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:
Code:
if [ ! -s /tmp/file.txt ]


Last edited by Don Cragun; 12-02-2014 at 04:17 AM.. Reason: Add more efficient test.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Check file size

I need a unix script that will check the size of multiple files in the same directory or from a text file. (6 Replies)
Discussion started by: alnita
6 Replies

2. Shell Programming and Scripting

file size check

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)
Discussion started by: malaymaru
2 Replies

3. UNIX for Dummies Questions & Answers

Mail based on file size

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)
Discussion started by: rajendragora
2 Replies

4. Shell Programming and Scripting

To check file size

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)
Discussion started by: Shahul
2 Replies

5. Shell Programming and Scripting

Check for file size is zero or not.

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)
Discussion started by: Hangman2
3 Replies

6. Shell Programming and Scripting

Check the file size - help

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)
Discussion started by: sithara
5 Replies

7. Shell Programming and Scripting

check the file size

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)
Discussion started by: sandy1028
1 Replies

8. Shell Programming and Scripting

Mail file size of newest file in directory

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)
Discussion started by: iamVERYhungry
4 Replies

9. Shell Programming and Scripting

Check a file size

I'm doing a script thats check if mylogfile.log is bigger then 5000 but i dont know how to write it. thanks in avance. (6 Replies)
Discussion started by: Froob
6 Replies

10. Shell Programming and Scripting

File size check

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)
Discussion started by: Aditya_001
2 Replies
mlmmj-unsub(1)						      General Commands Manual						    mlmmj-unsub(1)

NAME
mlmmj-unsub - unsubscribe address from a mailinglist run by mlmmj SYNOPSIS
mlmmj-unsub -L /path/to/list -a john@doe.org [-b] [-c | -C] [-d | -n | -N] [-h] [-q] [-r | -R] [-s] [-U] [-V] -a: Email address to unsubscribe -b: Behave as if unsubscription is due to bouncing (internal use) -c: Send goodbye mail -C: Request mail confirmation -d: Unsubscribe from the digest version of the list -h: This help -L: Full path to list directory -n: Unsubscribe from the nomail version of the list -N: Unsubscribe from the normal version of the list -q: Be quiet (don't notify owner about the unsubscribe) -r: Behave as if request arrived via email (internal use) -R: Behave as if confirmation arrived via email (internal use) -s: Don't send a mail to the address if not subscribed -U: Don't switch to the user id of the listdir owner -V: Print version DESCRIPTION
This utility is used to unsubscribe people from the specified mailinglist. It will remove the specified email address from every file in the <listdir>/subscribers.d/, <listdir>/digesters.d/ and <listdir>/nomailsubs.d/ directories (or if the -d, -n or -N switch is given, only the one relevant directory). Unless the -U switch is used it will switch its user id to the user id owning the list directory. This is done to make sure that new files created are having correct permissions. Normally a mail is sent to the person being unsubscribed if the address is not subscribed to the list. If the -s switch is used such a mail will not be sent. When neither -c nor -C is specified, unsubscription happens silently from the point of view of the subscriber. When -q is specified, unsub- scription happens silently from the point of view of the list owner. Use of -s is recommended to ensure you don't spam unsubscribed addresses by accident. SEE ALSO
mlmmj-sub(1) AUTHORS
This manual page was written by the following persons: Soren Boll Overgaard <boll@debian.org> (based on html2man output) Mads Martin Jorgensen <mmj@mmj.dk> mlmmj-unsub September 2004 mlmmj-unsub(1)
All times are GMT -4. The time now is 03:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy