monitor size of file in realtime | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

monitor size of file in realtime

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-17-2009
hazno hazno is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 3 June 2009, 2:04 AM EDT
Location: Tokyo
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old 03-17-2009
krishmaths krishmaths is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 30 June 2014, 4:32 AM EDT
Location: Chennai, India
Posts: 443
Thanks: 22
Thanked 70 Times in 68 Posts
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.
Sponsored Links
    #3  
Old 03-17-2009
hazno hazno is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 3 June 2009, 2:04 AM EDT
Location: Tokyo
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
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
rikxik's Avatar
rikxik rikxik is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 24 October 2011, 2:20 AM EDT
Posts: 259
Thanks: 0
Thanked 2 Times in 2 Posts
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(|)?
Sponsored Links
    #5  
Old 03-17-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 9 April 2014, 1:31 AM EDT
Location: INDIA, Bangalore
Posts: 2,049
Thanks: 16
Thanked 106 Times in 102 Posts
Quote:
Originally Posted by hazno View Post
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

Sponsored Links
    #6  
Old 03-17-2009
krishmaths krishmaths is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 30 June 2014, 4:32 AM EDT
Location: Chennai, India
Posts: 443
Thanks: 22
Thanked 70 Times in 68 Posts
Where is the loop?

Quote:
Originally Posted by hazno View Post
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.
Sponsored Links
    #7  
Old 03-17-2009
zTodd zTodd is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 5 October 2009, 5:11 PM EDT
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by vidyadhar85 View Post
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.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
command to find out total size of a specific file size (spread over the server) abhinov Solaris 3 08-08-2007 06:48 AM
compare realtime wannalearn Shell Programming and Scripting 7 02-27-2007 08:42 AM
monitor jvm heap size rein UNIX for Advanced & Expert Users 0 07-21-2005 08:29 AM
Monitor File Changes goreb13 Shell Programming and Scripting 1 07-10-2005 05:26 AM



All times are GMT -4. The time now is 09:34 PM.