Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

monitor size of file in realtime

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 03-17-2009
krishmaths krishmaths is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 22 September 2016, 9:17 AM EDT
Location: Bangalore, India
Posts: 450
Thanks: 27
Thanked 70 Times in 69 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 Unix and Linux 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 Unix and Linux 03-17-2009
rikxik's Unix or Linux Image
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 Unix and Linux 03-17-2009
vidyadhar85's Unix or Linux Image
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 23 March 2016, 5:15 AM EDT
Location: INDIA, Bangalore
Posts: 2,050
Thanks: 16
Thanked 105 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 Unix and Linux 03-17-2009
krishmaths krishmaths is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 22 September 2016, 9:17 AM EDT
Location: Bangalore, India
Posts: 450
Thanks: 27
Thanked 70 Times in 69 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 Unix and Linux 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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 04:28 PM.