#1  
Old 25th June 2006, 15:13
mphayesuk mphayesuk is offline
Senior Member
 
Join Date: Sep 2005
Location: UK, East Midlands
Posts: 517
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via MSN to mphayesuk
Default Shell Script Need Help

Ok what I want to do is get the size of a file and then assign that size to a variable.

This is what I have so far:

echo "total size of file"
ls -l -s /tmp/systembackups/$Today/$Today/systemfiles.tar.gz | cut -d \ -f 7

the $Today variable is the date that the backup script was run, so every night when the script runs it tar's everything up and then burns to a dvd, what I also have is all the output from my script goes into a log file, so at the end of the log file I want to put the file sizes of the backup.

With the example above I have tried to assign it to a variable and get nothing, when I try and run it as an echo statement it wont recognise the $Today variable.

Can anyone help with this.

Thanks
Reply With Quote
Sponsored Links
  #2  
Old 26th June 2006, 11:21
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

So your problem is that the $Today variable is empty, and not that you cannot assign the size of a file to a variable?

Where does the $Today variable come from?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 26th June 2006, 15:45
mphayesuk mphayesuk is offline
Senior Member
 
Join Date: Sep 2005
Location: UK, East Midlands
Posts: 517
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via MSN to mphayesuk
Default

The Today variable contains the date, which is caluculated at the start of the script, so it does contain data. The way the I have found to get the file size into a variable is to echo the whole statment and then assign a variable to the echo statement.

That will work as long as I hard code the folder locations (ie no variables) which is no good to me as the Today string will change every day.

So if I do:
FILESIZE$= 'echo 'ls -l -s /tmp/systembackups/26.06.06/26.06.06-backup/systemfiles.tar.gz | cut -d \ -f 7'

the filesize string will contain the information I need but if I put in variables instead of the date it will fail, because the command line will not know what $Today is set to.

Am I making sense.... its starting to pee me off a little.

Any ideas.

Thanks
Reply With Quote
  #4  
Old 27th June 2006, 07:39
vlsimpson vlsimpson is offline
Junior Member
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm going to assume that directory structure is in place and the 26.06.06 is day.month.year.

Here's a variation with stat:
FILESIZE=$(stat -c %s /tmp/systembackups/$(date +%d.%m.%y)/$(date +%d.%m.%y)-backup/systemfiles.tar.gz)

This should work iff I think correctly what you're trying to do.
docs for stat and date:
info stat
info date
__________________
SlackHappy:GNU:Linux:Slackware
Reply With Quote
  #5  
Old 27th June 2006, 12:06
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
 
Default

What about
Code:
FILESIZE=`ls -l -s /tmp/systembackups/${Today}/${Today}/systemfiles.tar.gz | cut -d \ -f 7`
?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help for writing shell script chris_87 Programming/Scripts 7 4th April 2007 15:50
ftp shell script mcrosby Programming/Scripts 8 9th January 2007 15:12
shell script Nnyan Programming/Scripts 4 24th June 2006 13:47
Need help for writing shell script erez Programming/Scripts 4 16th June 2006 14:23
Shell script is broken... Duplex Installation/Configuration 4 16th January 2006 09:55


All times are GMT +2. The time now is 02:27.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.