Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Comparing file sizes in korn script
Name: Ian Date: January 17, 2002 at 09:52:03 Pacific
Comment:
I'm trying to write a shell script to monitor certain files and display a warning when they reach a certain size. The idea being to give a warning BEFORE the ulimit is hit! I've fallen at the first hurdle however, how can you RELIABLY get JUST the file size? I'm trying variations along the following lines:
ls -l filename|cut -d" " -f5
However on my Unixware 2.1.3 (and on 7) system the cut seems to give different results depending on the file listed. Presumably there are different numbers of spaces in the resulting line?
My other option is to use "cut -c35-41". However, being really pedantic, I'd like the script not to be platform specific so I can't rely on the character positions.
Name: wpatte Date: January 17, 2002 at 10:49:17 Pacific
Reply:
Try this ....
ls -l "filename" | awk '{print $5}'
0
Response Number 2
Name: James Boothe Date: January 17, 2002 at 12:11:26 Pacific
Reply:
Correct on the varying number of spaces. The cut command is using each space as a field delimiter, so a bunch of spaces makes for a bunch of null fields.
By default, awk delimites each field with any amount of whitespace. I check a directory for large files with:
ls -l | awk '$5>999999'
And the read command uses whitespace, by default, as its delimiter:
ls -l fname | read x x x x fsize remainder echo $fsize
Summary: Dear all, I wonder how to find the size of an array in shell script. For example, I declared an array as following: #! /bin/sh a = (1 adf 8 2 se) How could I get the size of the array a? I had searche...
Summary: Hi, I am trying to remotely run a korn script in a Linux box as a root user. However, the default shell in the Linux box for root is bash. I want to be able to change the shell from bash to ksh in my ...
Summary: Can anyone help me with comparing two vaiables in unix shell script. This is what i'm trying.... if [ $X -ne $Y ] then ----- else ---- fi Where X and Y are varibles with diff values. thanks in...