|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Unix script help
Hi
I am trying to write a script that will delete all the files that haven't been modified in 30 days or more. I have got this working fine ... The problem is that there is a directory called 'reports' that can't be touched. example...Code:
text=`find $file -mtime +$1`
for line in $text
do
rm $line
done
This will delete everything... Since the variable $line is a full path, I can't even check to see if I am in the reports directory (Or I don't know how to I should say) So my question is this... Does any one know how to write an IF Statement in a unix script that will check if the string '/reports/' is in the variable $line?? Thanks... Or if there is an easier way to do this, I am open to any suggestions... |
|
#2
|
|||
|
|||
|
Thanks to anyone who has taken the time to look at this, but I have found a work around for my problem...
Here it is... Code:
text=`find $file -mtime +$1`
for line in $text
do
reportProtector=`echo $line | grep "/reports/"`
if [ -z "$reportProtector" ]
then
rm "$line"
fi
done
So basically I am checking what is returned from the grep, and if it is a 0 length string then it did not find the word /reports/ and therefor the file cannot be in the reports directory. I am still open to suggestion however if anyone has a better/easier solution to this problem Thanks for your time... |
|
#3
|
|||
|
|||
|
Quote:
can we try to write unix ? for line in `find WHATYOUWANT -mtime +$1` do case $line in exception0) continue ;; execption1) continue ;; execption2) continue ;; execptionxxxxx) continue ;; esac rm -f $line done chage exception by what your exceptions |
|
#4
|
|||
|
|||
|
I don't get it...
was my code wrong, or is this just a more efficient way of doing it? |
|
#5
|
|||
|
|||
|
Quote:
no your code isnt wrong, just no code. i would try: find ¦ egrep -v what-you-dont-want-kill ¦ xargs rm back to your script why set a variable catching the output of echo¦ grep to get the filename of the file you are working on ? why test the output of grep that way ? echo xxx¦grep -s x >/dev/null gives 0 (x founded) 1 (not found) read a little man pages ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Unix script help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|