Operating System - HP-UX
1845002 Members
1682 Online
110233 Solutions
New Discussion

Re: Scripting help required

 
SOLVED
Go to solution
ShivKumar_1
Frequent Advisor

Scripting help required

Hi guys,
I am looking for a script , that can identify the files, created on a date say for Eg today and rcp them over. And on the next day, if there is a file with the same name it shouldn't rcp that , it should skip that file.

I got answers from some experts , which I am pasting below. But about the skipping the file ie if there is a file with same name, yesterday comparing it with today, how do we do that? I have some thing like one below in place.
***********************************************
#!/bin/sh
TODAY=`date |awk '{print $2, $3}'`
for i in `ll |grep "$TODAY"|awk '{print $9}'`
do
rcp $i otherserver:/somedir
done

***********************************************
8 REPLIES 8
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Scripting help required

Sorry, can't be done no matter what you are told. UNIX has no concept of the creation time of a file; the inode simply doesn't carry that bit of metadata. You only know by accident when a file was created. Change your question and we'll give it a try.
If it ain't broke, I can fix that.
ShivKumar_1
Frequent Advisor

Re: Scripting help required

Hi,
Is there a way of comapring the file names created today and for tomorrow , if the same file name exists then that file has to be left out or do something like a grep -v on that file and rcp the rest over. I am basically looking for some thing to compare.
Rodney Hills
Honored Contributor

Re: Scripting help required

Creation date is not part of a files inode data.

You could write a script that runs at the end of the day that looks for new files and maintains its own list of these files in a text file.

HTH

-- Rod Hills
There be dragons...
A. Clay Stephenson
Acclaimed Contributor

Re: Scripting help required

By the way, I suggest you take a look at the rdist command. I suspect that it is close to what you want, "out of the box". You might also look at rsync,
http://hpux.connect.org.uk/hppd/hpux/Networking/Admin/rsync-2.5.7/
If it ain't broke, I can fix that.
Rodney Hills
Honored Contributor

Re: Scripting help required

If these files are in control of some copy process and are copied only once and no other process updates them, then you could assume that last modify date equals creation date.

-- Rod Hills
There be dragons...
Kent Ostby
Honored Contributor

Re: Scripting help required

I think this will do it.

You will need a script file and an awk file.

Put the following into the script file:

#!/bin/sh
touch .rfile.today .rfile.yesterday
rm .rfile.today
TODAY=`date |awk '{print $2, $3}'`
for i in `ll |grep "$TODAY"|awk '{print $9}'`
do
echo "TOD" $i >> .rfile.today
done
cat .rfile.yesterday .rfile.today | sort -b -k2,2 > .rfile.combined
awk '{print "YES",$2}' .rfile.today > .rfile.yesterday
awk -f .rfile.awk < .rfile.comb > .runme
chmod +x .runme
./.runme

The second file should be called .rfile.awk and should contain:

BEGIN {prev="xyzzy";}
/^YES / {prev="";dacount=0;}
/^TOD / {if (dacount>0)
{print "rcp ",prev," otherserver:/somedir "};
dacount=1; prev=$2;
}
END {if (dacount>0)
{print "rcp ",prev," otherserver:/somedir "};}

Obviously you need to replace the "otherserver/somedir", but you get the idea.

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Mihaita Bighiu
Advisor

Re: Scripting help required


Hi,
Please have a look at rdist commnad.

From rdist man page:

rdist - remote file distribution program

DESCRIPTION
rdist facilitates the maintaining of identical copies of files over
multiple hosts. It preserves the owner, group, mode, and modification
time of files if possible and can update programs that are executing.


Regards,
MB
Michael Schulte zur Sur
Honored Contributor

Re: Scripting help required

Hi,

am I right to assume, that the files get created written to, closed and never touched again, or are they updated a second time?
If not and all you need are the files modified in the last 24h then you might want to use
find ./ -type f -mtime -1 -exec rcp "{}" otherserver:/somedir ";"

There is a slight chance to get the creation time. If noone touches the inode with chmod, chown or the like then ls -lc gives you the creation date/time.

greetings

Michael