
25th June 2006, 16:13
|
|
Senior Member
|
|
Join Date: Sep 2005
Location: UK, East Midlands
Posts: 515
Thanks: 1
Thanked 2 Times in 2 Posts
|
|
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
|

26th June 2006, 12:21
|
|
Super Moderator
|
|
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
|
|
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?
|

26th June 2006, 16:45
|
|
Senior Member
|
|
Join Date: Sep 2005
Location: UK, East Midlands
Posts: 515
Thanks: 1
Thanked 2 Times in 2 Posts
|
|
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
|

27th June 2006, 08:39
|
|
Junior Member
|
|
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

27th June 2006, 13:06
|
|
Super Moderator
|
|
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,853
Thanks: 781
Thanked 1,558 Times in 1,477 Posts
|
|
What about
Code:
FILESIZE=`ls -l -s /tmp/systembackups/${Today}/${Today}/systemfiles.tar.gz | cut -d \ -f 7`
?
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 12:54.
|
Recent comments
1 day 4 hours ago
1 day 9 hours ago
1 day 9 hours ago
1 day 9 hours ago
1 day 10 hours ago
1 day 13 hours ago
1 day 15 hours ago
1 day 15 hours ago
1 day 15 hours ago
1 day 17 hours ago