Reputation: 6391
The below script will be called from a cronjob and my desire is to remove directories older than 10 mins of the current time.
I'm having trouble with the following in my script:
\n
from the beginning of a variable and not from the end (dumping the $oldDirday
variable below to hexdump shows a leading \n
if
test to work properlyThis is what I have:
#!/bin/sh
i=1
homeDirData="/home/user"$i"/dirToClean/"
while [ -d $homeDirData ]
do
echo "Checking user"$i""
for oldDir in $(find . -type d)
do
oldDirDay=$(ls -l $oldDir | awk '{print $7}')
oldDirTime=$(ls -l $oldDir | awk '{print $8}' | tr -d ':')
curDay=$(date +%d%t%R | awk '{print $1}')
curTime=$(date +%d%t%R | awk '{print $2}')
if [ $oldDirDay -lt $curDay ] && [ $oldDirTime -lt $(($curTime+600)) ]
then
find $homeDirData -type f -exec shred -f --remove {} \;
rm -rf $homeDirData
else
echo "Nothing to remove"
fi
((i+1))
done
done
Error
if
statement is)Issue
Upvotes: 0
Views: 2714
Reputation: 36
You can use something like this:
find $homeDirData -type d -mmin +10 -print0 | xargs -0 rmdir
Upvotes: 2