![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
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
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
|
|||
|
|||
|
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
|
||||
|
||||
|
Quote:
$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
|
|||
|
|||
|
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 |