Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio blue screen boot bsod connection crash dell desktop driver dvd email error excel excel 2003 firefox hard drive hardware hdmi hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem ram recovery router screen slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
moving files based on time and using a counter

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
23-Sep-2005, 10:40 AM #1
moving files based on time and using a counter
Been a while.

I am trying to come up with some code to basically move files based on a numeric flag value, (the number can be anything, 1 to ?). The flag will represent the number of days the file should be held for. Once the time has been met, the file will be moved. So for example, if I have a file that is 14_myfile.dat then the myfile doesn't get moved until after 14 days.

Here is what I have come up with so far but it isn't quite working... yet.

flag=14
count=0
for file in `ls -l *myfile*.*`
do
count=`expr $count +1`
for fileone in `find . -type f -mtime ${count} -name "${flag}${file}"`
do
mv "$fileone" /directory/b"${fileone}".dat
done
done
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
23-Sep-2005, 11:09 AM #2
Here is my latest attempt and the subsequent error..
flag=10
count=0
for file in *
do
if [ -f "$file" ]
then
count=`expr $count +1`
for myfile in `find . -type f -mtime ${count} -name "${flag}${file}"`
do
mv "${myfile}" /directory/"b${myfile}""_$date".dat
done
fi
done

ERROR:
expr: 0402-050 Syntax error.
find: 0652-086 Specify a decimal integer for -mtime
Usage: find Path-list [Expression-list]
expr: 0402-050 Syntax error.
find: 0652-086 Specify a decimal integer for -mtime
Usage: find Path-list [Expression-list]

the result im looking for here is that if the mtime is 10 or older and the mtime of 10 is the same as the filename, which would be 10file then the file will get moved, otherwise the file stays in its current directory.
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
23-Sep-2005, 11:38 AM #3
just realized i had the + and 1 together.. heres an updated script that still isn't quite working....
flag=10
count=1
for file in *
do
count=`expr ${count} + 1`
for f in `find . -type f -mtime ${count} -name "${flag}${file}"`
do
echo "${count}"
mv "$f" /mdm_work/cg_test/FblSrcFiles/"b$f""_$date".dat
done
done

Last edited by cgjoker : 23-Sep-2005 02:52 PM.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 03:35 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.