monitor size of file in realtime


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting monitor size of file in realtime
# 1  
Old 03-17-2009
monitor size of file in realtime

How would one monitor the size of a file in realtime, then when it reaches a certain size (like 10megs), gzip, append timestamp to filename and scp to another box?

regards
# 2  
Old 03-17-2009
Use sleep command, and ls -l or du command within a loop until the file size reaches your upper limit, and then add the timestamp and transfer.

Please try out and post if you have further problems.
# 3  
Old 03-17-2009
My first attempt...

Check file size
If file reached file size
Append date to filename
Compress filename.$date
scp filename.$date to target server

Code:
#!/bin/bash
SIZE=`ls -la syslog.log | cut -d' ' -f 5 `
echo $SIZE

if [ "$SIZE" -ge 10000000 ]
  then
    `mv syslog.log syslog.log.$date | gzip syslog.log.$date | scp syslog.gz jdoe@system.com:\home\jdoe\logs `
  else
    echo "size not reached yet"
sleep 5
fi

# 4  
Old 03-17-2009
Quote:
`mv syslog.log syslog.log.$date | gzip syslog.log.$date | scp syslog.gz jdoe@system.com:\home\jdoe\logs `
Do you know, in general, what is the purpose behind using backticks (`) and using pipe(|)?
# 5  
Old 03-17-2009
Quote:
Originally Posted by hazno
My first attempt...

Check file size
If file reached file size
Append date to filename
Compress filename.$date
scp filename.$date to target server

Code:
#!/bin/bash
SIZE=`ls -la syslog.log | cut -d' ' -f 5 `
echo $SIZE
 
if [ "$SIZE" -ge 10000000 ]
  then
    `mv syslog.log syslog.log.$date | gzip syslog.log.$date | scp syslog.gz jdoe@system.com:\home\jdoe\logs `
  else
    echo "size not reached yet"
sleep 5
fi

get rid of those backquote and pipe
Code:
 
mv syslog.log syslog.log.$date 
gzip syslog.log.$date 
scp syslog.gz jdoe@system.com:\home\jdoe\logs
/or/
mv syslog.log syslog.log.$date  && mv syslog.log syslog.log.$date && 
scp syslog.gz jdoe@system.com:\home\jdoe\logs

# 6  
Old 03-17-2009
Where is the loop?

Quote:
Originally Posted by hazno
My first attempt...

Check file size
If file reached file size
Append date to filename
Compress filename.$date
scp filename.$date to target server

Code:
#!/bin/bash
SIZE=`ls -la syslog.log | cut -d' ' -f 5 `
echo $SIZE

if [ "$SIZE" -ge 10000000 ]
  then
    `mv syslog.log syslog.log.$date | gzip syslog.log.$date | scp syslog.gz jdoe@system.com:\home\jdoe\logs `
  else
    echo "size not reached yet"
sleep 5
fi


Good attempt! You haven't used any loop structure. You can try using while or until loop.
# 7  
Old 03-17-2009
Quote:
Originally Posted by vidyadhar85
get rid of those backquote and pipe
Code:
 
mv syslog.log syslog.log.$date 
gzip syslog.log.$date 
scp syslog.gz jdoe@system.com:\home\jdoe\logs
/or/
mv syslog.log syslog.log.$date  && mv syslog.log syslog.log.$date && 
scp syslog.gz jdoe@system.com:\home\jdoe\logs

I think Vidyad meant that last line to be
mv syslog.log syslog.log.$date && gzip syslog.log.$date &&
scp syslog.gz jdoe@system.com:\home\jdoe\logs

But I'm not sure about that $date variable- does that work? I think in the shell I've been using I had to use `date` command instead.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to monitor size in directory

i'm trying to find the most efficient way to monitor specific files in different directories in one go. /var/log/ /var/app/ /var/db/ each one of these directories can have subdirectories which need to be looked into as well. I want to find any file in this directory that has the name... (7 Replies)
Discussion started by: SkySmart
7 Replies

2. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

3. Shell Programming and Scripting

Script to monitor directory size of specific users

Hi, i am new to shell scripts, i need to write a script that can monitor size of directory of specific users. Please help. Thanks, Nitin (2 Replies)
Discussion started by: nicksrulz
2 Replies

4. Shell Programming and Scripting

Script to monitor for new file with ext .err and size > 0 bytes and perform a action or command

Hi All, I need to create a script to monitor a dir for new files with ext .err and also it should b a non empty files. and perform a action or command . We have a new ETL application that runs on a linux server, every times a etl fails it creates a .err file or updates the existing .err... (4 Replies)
Discussion started by: MAKHAN
4 Replies

5. Shell Programming and Scripting

Scan a file in realtime and execute certain commands on encountering 5 consecutive identical lines

Mysql log has something like below: I need a bash shell script that will do the following: 1) The script will scan the mysql.log file constantly in real time (something like tail -F mysql.log) 2) If it encounters 5 consecutive identical lines then it would invoke some commands (say... (4 Replies)
Discussion started by: proactiveaditya
4 Replies

6. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

7. Shell Programming and Scripting

The scripts not able to make the file to size 0, every times it go back to its original size

#!/bin/sh ########################################################################################################## #This script is being used for AOK application for cleaning up the .out files and zip it under logs directory. # IBM # Created #For pdocap201/pdoca202 .out files for AOK #1.... (0 Replies)
Discussion started by: mridul10_crj
0 Replies

8. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

9. UNIX for Advanced & Expert Users

monitor jvm heap size

I'm running websphere 4.5 on AIX 5 with java 1.3 and would like to find out the following: How much memory is allocated to each JVM, and how much of the allocated heap size is actually being used by a specific JVM? (0 Replies)
Discussion started by: rein
0 Replies
Login or Register to Ask a Question