Script to compare file size
Hi All,
I am looking for a script to compare file size and if the newest file is less than or equal to the older file i would like it to send me an email. Basically i had database backups getting scp'd to another box and when i needed to restore a database i found out that the file was not being fully transfered. I keep 3 days worth of backups of each db. But i want to just compare the 2 most current. So lets say i have nazs.sql.gz . It gets newcopied and becomes nazs.sql.gz,1 and then the new file comes in and overwrites nazs.sql.gz. Now i want to compare the file size of nazs.sql.gz and nazs.sql.gz,1. If nazs.sql.gz is less than or equal to nazs.sql.gz,1 then i want to send an email. There are around 20 databases being backed up. I would need to know how to put the list of databases into the script so it would check them all. I hope i explained this well enough. If there are questions please let me know. Thanks, Nazs |
If you don't mind, I'll give you some general pointers and code snippets from my own. You should be able to tweak them to your own needs, these is by no means a ready to run program!
If you want to do something with a number of files: Code:
#turn off globbing Code:
fsize_first=` ls- l fname | awk '{print $5}'` You also might want to peek in the advance bash scripting guide if you haven't done also. jlinkels |
Quote:
it should be fsize_first=`ls -l fname | awk '{print $5}'` fsize_now=`ls -l fname.1 | awk '{print $5}'` note the space between 'ls' and '-' |
Yup.
Thanks. jlinkels |
wc -c counts the number of chars (bytes) in a file.
|
Quote:
for the actual byte count you need to decrement by 1 |
in short as,
echo $((`wc -c < filename` - 1)) |
All times are GMT -5. The time now is 12:51 PM. |