The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file command rprajendran UNIX for Advanced & Expert Users 3 05-13-2008 10:45 AM
rm command not able to remove file jambesh Shell Programming and Scripting 7 12-21-2007 04:37 AM
What is the command to add heading to a file? whatisthis UNIX for Dummies Questions & Answers 3 12-02-2005 12:17 AM
VI command for File Please $Circle$ UNIX for Dummies Questions & Answers 12 09-05-2005 01:23 AM
End of file using more command Enda Martin UNIX for Dummies Questions & Answers 3 06-18-2001 07:49 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 01-30-2001
Registered User
 

Join Date: Jan 2001
Posts: 9
Smile

I solve it as follows:
Code:
#!/usr/bin/sh

dir=/var/dist
cd /mydir
<b>
today=`/usr/bin/date +%Y-%m-%d`
export today
todayLogs=`ls $today*`
export todayLogs
</b>
for file in *.log 
do 
if [ -f $file ] 
then 
<b>fileExists=`echo $todayLogs | grep $file`
   if [ "$fileExists" = "" ]</b>
      if /usr/bin/mv $file $dir/access_log_$file 
    then 
     echo "$file : moved to $dir successfuly " 
    else 
     echo "can not move or rename access_log_$file" 
    fi 
 fi
fi 
done
its work.
and I'll convert PxT script to bourne soon........

[Edited by tamer on 01-30-2001 at 09:37 AM]
added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 02:38 PM.
Forum Sponsor
  #9  
Old 01-30-2001
mib mib is offline
Registered User
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
Here is Perl Script that could solve your problem:

#/bin/perl

use File::Copy;

$directory = ".";
$moveto = "/var/dist";
$prefix = "access-log";
$ignoredFiles = "";
$count=0;

my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime;
$month=$month+1;
if($mon < 10) { $month="0".$month; }
$year =~ s/1/20/;

$today = join("-", ($year, $month, $mday));


opendir (DIR, "$directory") || die "Can't open $directory,Reson$!";
@dir = grep(/.log$/,readdir(DIR));
closedir (DIR);

# Now, for every file in the directory...
foreach $file (@dir) {
# If it contains today's date ignore it
# If it is older than 'n' day (-M "$directory/$file" > n)

if ("$directory/$file" =~ $today) {
$ignoredFiles .= "$file\n"; }
else {
copy("$directory/$file", "$directory/$moveto/$prefix-$file") || die("Can't Copy. Reason:$!\n");
$count = $count+1;
}
}


print "\n$count files moved";
print "\nFiles ignored(Today's file): $ignoredFiles";

  #10  
Old 01-30-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Quote:
$year =~ s/1/20/;
I know perl prides itself on the fact that "There is more than one way to do it", but why do you do a string substitution here, when simple arithmetic would work just as well?

$year +=1900;


Using a string sub. is really just obfuscation. And as an added benefit, the arithmetic method will ensure that your scripts continue to work in the 22nd century and beyond.
  #11  
Old 01-31-2001
mib mib is offline
Registered User
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
Thank you for Pointing out the blunder in my script Pxt. I were unaware of that method


As you said I want to run that script 22nd century people and email me "oh man what a script"
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0