UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 25th, 2005, 07:11 AM
M-Bone M-Bone is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Ontario, Canada
Posts: 137 M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 11 h 6 m 57 sec
Reputation Power: 25
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...

Reply With Quote
  #2  
Old July 25th, 2005, 08:25 AM
M-Bone M-Bone is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Ontario, Canada
Posts: 137 M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 11 h 6 m 57 sec
Reputation Power: 25
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...

Reply With Quote
  #3  
Old July 25th, 2005, 01:23 PM
iribach iribach is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 iribach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 31 m 47 sec
Reputation Power: 0
Quote:
Originally Posted by M-Bone
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...


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

Reply With Quote
  #4  
Old July 25th, 2005, 03:09 PM
M-Bone M-Bone is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Ontario, Canada
Posts: 137 M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level)M-Bone User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 11 h 6 m 57 sec
Reputation Power: 25
I don't get it...
was my code wrong, or is this just a more efficient way of doing it?

Reply With Quote
  #5  
Old July 26th, 2005, 08:26 AM
iribach iribach is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 iribach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 31 m 47 sec
Reputation Power: 0
Quote:
Originally Posted by M-Bone
I don't get it...
was my code wrong, or is this just a more efficient way of doing it?


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
Comments on this post
M-Bone agrees: thanks for the tips

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Unix script help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT