Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Linux and Unix Linux and Unix
Search Search
Search for:
Tech Support Guy > > >

if file exist and has mod date of... (unix).


(!)

Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
10-Mar-2005, 12:52 PM #16
I am working on a different approach using the date command.

date --date='1 day ago'
cgjoker's Avatar
cgjoker cgjoker is offline
Member with 205 posts.
THREAD STARTER
 
Join Date: Aug 2003
10-Mar-2005, 03:29 PM #17
sorry.... didn't realize there was a page two and i thought you guys might have thought this was closed.

thanks.

any luck so far?

i tried this and it somewhat works but i noticed that the file is returned as

./1file1.dat rather than 1file1.dat so therefore it is not getting copied.

for file in `find ./ -type f -mtime +1 `
do
if [ -f $file ]
then
case $file in
1*.*)
cp $file /mdm_work/Campaign_Downloads/test
echo "$file copied" >> /test/processing.log
;;
*)
echo "$file: appears to be other" >> /test/processing.log
;;
esac
fi
done
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
10-Mar-2005, 04:53 PM #18
This should do it.

Code:
date1=`date +%Y-%m-%d -d "yesterday"`
for filename in `find "/home/jfriberg/test" -type f -name "1*.*"`
do
grep1=`ls --full-time $filename | grep -c $date1`
if [ $grep1 = "1" ]; then
cp -p $filename /home/jfriberg/backup/
fi
done
cgjoker's Avatar
cgjoker cgjoker is offline
Member with 205 posts.
THREAD STARTER
 
Join Date: Aug 2003
10-Mar-2005, 05:37 PM #19
didn't work... i got the following error

iw113:user:/test]./find_mod.sh
date: 0551-402 Invalid character in date/time specification.
Usage: date [-u] [+"Field Descriptors"]
find: 0652-010 The starting directory is not valid.
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
10-Mar-2005, 09:01 PM #20
Works fine on my box. Post back the exact script you used and I will replicate the paths on my box. (Copy and Paste it!)

Which version of Linux\Unix\BSD are you running this on?
Which Shell are you using?
cgjoker's Avatar
cgjoker cgjoker is offline
Member with 205 posts.
THREAD STARTER
 
Join Date: Aug 2003
11-Mar-2005, 12:02 PM #21
if i copy and paste, as per below:

date1=`date +%Y-%m-%d -d "yesterday"`
for filename in `find "/EBCC" -type f -name "2*.*"`
do
grep1=`ls --full-time $filename | grep -c $date1`
if [ $grep1 = "1" ]; then
cp -p $filename /test/
fi
done

I get the following error:

iw113:cgalindo:/affinium/Campaign/Std_recur2_Validation/script]./mod.sh
date: 0551-402 Invalid character in date/time specification.
Usage: date [-u] [+"Field Descriptors"]
ls: Not a recognized flag: -
ls: Not a recognized flag: -
Usage: ls [-1ACFLNRabcdefgilmnopqrstux] [File...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...]
./mod.sh[17]: test: 0403-004 Specify a parameter with this command.


I should have mentioned we are actually on AIX 5.1.
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
11-Mar-2005, 01:49 PM #22
And what shell are you using. Scripts are dependent on what shell you are using. If you can install bash on their it should run. But you then need to put the interpreter at the top of the script.

#!/bin/bash ( or wherever bash is installed on your system.)

We probably shouldn't even really use test as a directory name because it is an acutal command. You might have to put the $Date1 variable in quotes.

You might have to look at the manual pages for your shell environment to figure out how to get the full-time in the LS command and figure out how to get yesterday's date to output with those variables. I dont know what shell you are using so it is hard to say. If you have bash installed this script will run.
__________________
.
cgjoker's Avatar
cgjoker cgjoker is offline
Member with 205 posts.
THREAD STARTER
 
Join Date: Aug 2003
11-Mar-2005, 03:58 PM #23
sorry,... korne shell. I should have known that is what you were asking for.

i dont think we have bash installed.

this is the error if in quotes:

iw113:user:/test]./mod.sh
date: 0551-402 Invalid character in date/time specification.
Usage: date [-u] [+"Field Descriptors"]
ls: Not a recognized flag: -
ls: Not a recognized flag: -
Usage: ls [-1ACFLNRabcdefgilmnopqrstux] [File...]
iw113:user:/test]
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
11-Mar-2005, 04:13 PM #24
Quote:
Originally Posted by cgjoker
sorry,... korne shell. I should have known that is what you were asking for.

i dont think we have bash installed.
Do you think you could check. Try just typing bash at a shell prompt. If it is installed you will switch to a bash shell. If it is installed put this line at the top of your script.

#!/bin/bash (or wherever bash is installed)

Or do a find for it.
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
11-Mar-2005, 04:16 PM #25
I just checked IBM's website. You can run bash on AIX. I dont have Korn installed on my box at home so I cannot test anything right now. I can loaded it up later tonight if I have time but I usually dont go on my computers during the weekend.
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
11-Mar-2005, 04:18 PM #26
cgjoker's Avatar
cgjoker cgjoker is offline
Member with 205 posts.
THREAD STARTER
 
Join Date: Aug 2003
14-Mar-2005, 05:03 PM #27
I think I have it installed already because I do recall running a bash script I created a long time ago. I guess I can just try a simple script to see if it works.

I still don't know why though the reason id get these errors.. if you tried it with bash and I had it installed, it should run then shouldn't it?
Squashman's Avatar
Trusted Advisor with 19,645 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
14-Mar-2005, 05:40 PM #28
Quote:
Originally Posted by cgjoker
I still don't know why though the reason id get these errors.. if you tried it with bash and I had it installed, it should run then shouldn't it?
Because your default shell is Korn and you dont have the interpreter defined at the top of the script. You have to put this at the top of the script.

#!/path/to/bash (replace the path to bash with where it is on your system)
cgjoker's Avatar
cgjoker cgjoker is offline
Member with 205 posts.
THREAD STARTER
 
Join Date: Aug 2003
17-Mar-2005, 12:12 PM #29
Ill try this out. Thanks so much for all your time in trying to help me figure this out.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
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.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑