The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Space issue with Directory siba.s.nayak UNIX for Dummies Questions & Answers 1 06-03-2008 07:14 AM
How do I increase disk space available to a directory? rhack UNIX for Dummies Questions & Answers 2 10-21-2005 11:54 AM
Space Used by Directory Tree johnk99 Filesystems, Disks and Memory 1 07-22-2002 12:30 PM
Check directory space? lesstjm Shell Programming and Scripting 3 04-19-2002 09:10 AM
Space left under current directory SmartJuniorUnix UNIX for Dummies Questions & Answers 2 06-26-2001 11:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-10-2001
nitin's Avatar
nitin nitin is offline
Registered User
  
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 88
Unhappy Space in the directory name

I've got a small script that deletes all the trash from mailusers Trash directory. I run this script once in a while to make some space. (We have lots of IMAP users, who keep their mail on server!) Occansionaly, the users create directories with space in the name (e.g. "My Mail"). And sometimes the users will delete the whole directory. Is there a way to grep the whole name of such occurances. Here is the script I made:
echo "Enter volume name to fetch Trash:"
read volname
cd /usr/$volname
du -k |grep Trash | sort +0nr |head -40 >/tmp/t_$volname.dat
cat /tmp/t_$volname.dat |awk '{print "rm -ef " $2 "/200*"}' >/tmp/tr$volname.del

I think the problem starts with grep. It should get the entire directory name. Any help will be greatly appreciated.
Nitin
  #2 (permalink)  
Old 09-14-2001
nitin's Avatar
nitin nitin is offline
Registered User
  
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 88
I looked into my script and saw that "grep" is doing fine a job by capturing the names of directories with space. The awk is not transferring the names correctly. It cuts the directory field until it encounters a space. I am thinking of doing some kind of substitution. Can anyone help me now?
Thanks in advance,
Nitin
  #3 (permalink)  
Old 09-14-2001
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
my guess in your awk statement you are only pasing $1 if you also pass $2 you will get the 2nd word if the dir. either that or you can change the field seperator.

OR

use $1 for the most part and tos an if -d to see if your awk vaiable is valid if yes then delte if no add $2 rerun directory check.
  #4 (permalink)  
Old 09-16-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
You might try changing your field separator
environment variable to somthing like...
export FS=":"

By default, the field separator is whitespace.
I haven't actually tried this with awk but I
believe awk will assume $1 = "My" and $2 = "Mail"
using whatever the field separator is.
If you have names with ":" in them then try
a different character.
  #5 (permalink)  
Old 10-02-2001
devnul devnul is offline
Registered User
  
 

Join Date: Oct 2001
Location: San Francisco
Posts: 27
Well, I have to say that there may be a more practical way of doing what you want... I mean, why not just have something which prunes away files that are over say 30-days old?...

Something like:
Code:
#!/usr/bin/perl

$volume=$ARGV[0];
@dirs=`find /usr/$volume -name Trash`;
$curtime=time();
$number_days=30;
foreach(@dirs)
{
  chomp();
  opendir(DIR,$_);
  while($fname=readdir(DIR))
  {
    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)=stat($fname};
    # 60 seconds, 60 minutes, 24 hours
    if($ctime < $curtime-(60*60*24*$number_days))
    {
      unlink $fname;
    }
  }
}
NOTE: You will want to test this because I haven't (!!!!!).... It's just an idea...

- dEvNuL

added code tags for readability --oombera

Last edited by oombera; 02-20-2004 at 11:41 AM..
  #6 (permalink)  
Old 10-06-2001
nitin's Avatar
nitin nitin is offline
Registered User
  
 

Join Date: Aug 2001
Location: Toronto, ON
Posts: 88
I had thought of deleting all the files older than a week. But, Netscape (mail server) creates some control files (e.g. __GENNAME__, __lock__, etc.) in the Trash directory of users. If removed users won't be able to see the Folders at client end (and raise hell on me! ). I could look into your script and tell it not to delete the files starting with "__".
Thanks a lot though.
Closed Thread

Bookmarks

Tags
mtime

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0