mhouston100
April 30th, 2010, 10:08 AM
Hi guys, first script and I'm a little stuck. Basically this script will run periodically on my recorded TV directory and if the space left is under 10% remove the last folder in the dir.
What I'm stuck on is getting the 'if' conditions right. I'm trying to say "If the percent used is greater than 90, then do the task"
It keeps reporting:
[: 28: Illegal number:
I've tried with '>' and also with '-qt' but I'm not really sure on the syntax of it. All the variables return correctly.
#!/bin/bash
var=olddir
var=tvdir
var=usedperc
var=highperc
##Declare tv recording directory and percentage
highperc=90
tvdir=/media/TV/TV
## Get oldest directory read it into var ldir
olddir=`ls -lt $tvdir | grep "^d" | tail -1 | cut -f 9 -d ' '`
## Find used percent Read into usedperc
usedperc=`df $tvdir -h | tail -1 | cut -c 41-42`
## test make sure variables are correct
echo $highperc
echo $tvdir"/"$olddir
echo $usedperc
## If used percentage is greater then 90% then remove last directory
if [ "$usedprc" -gt "$highperc" ]; then
`rm -R $tvdir"/"$olddir`
fi
This is pretty much just a learning exercise for me and ill be adding a condition so that if removing the dir doesn't bring it under 90% then go again.
Any help is, as alway's, greatly appreciated!
What I'm stuck on is getting the 'if' conditions right. I'm trying to say "If the percent used is greater than 90, then do the task"
It keeps reporting:
[: 28: Illegal number:
I've tried with '>' and also with '-qt' but I'm not really sure on the syntax of it. All the variables return correctly.
#!/bin/bash
var=olddir
var=tvdir
var=usedperc
var=highperc
##Declare tv recording directory and percentage
highperc=90
tvdir=/media/TV/TV
## Get oldest directory read it into var ldir
olddir=`ls -lt $tvdir | grep "^d" | tail -1 | cut -f 9 -d ' '`
## Find used percent Read into usedperc
usedperc=`df $tvdir -h | tail -1 | cut -c 41-42`
## test make sure variables are correct
echo $highperc
echo $tvdir"/"$olddir
echo $usedperc
## If used percentage is greater then 90% then remove last directory
if [ "$usedprc" -gt "$highperc" ]; then
`rm -R $tvdir"/"$olddir`
fi
This is pretty much just a learning exercise for me and ill be adding a condition so that if removing the dir doesn't bring it under 90% then go again.
Any help is, as alway's, greatly appreciated!