Quote:
|
Originally Posted by cgjoker excuse my ignorance, but when I attempt to run the code I get an error:
./file.sh[42]: seconds_age=%s-: 0403-057 Syntax error
./file.sh[41]: stat: not found.
Im using Korne shell, and if I man stat it tells me the entry is not found. |
The stat command is found on some systems, but not all. I have it on my Red Hat system here at work, and I've also found it on other systems. It basically makes available any or all elements of the C "struct stat". The ls command is basically a listing of struct stat elements. If you don't have it, it's a pretty simple C program to write. The syntax error above is because stat - because it's not found - returned nothing.
OR... some versions of ls have an option like:
ls -l --time-style='+%s'
which will present the mtime in Unix epoch time.
echo $file | head -c2
will return the first two LINES of $file, not the first two characters. Use
"cut -c1-2" for the first two characters.
so...
[code]
other_directory=/whatever/place
now=$(date '+%s') # Current Unix time in seconds
ls -g --time-style='+%s' | while read perms links owner size mtime file
do
if [ -f $file ]
then
daysage=$(echo $file | cut -c1-2) #extract first two chars of name
if let $daysage=$daysage+0 > /dev/null # numeric?
then
let seconds_age=$now-$mtime # file age in seconds
let max_seconds=$daysage\*86400 # convert max age to seconds
if [ $seconds_age -gt $max_seconds ]
then
mv $file $other_directory
fi
fi
fi
done
[\code]