- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Bourne Shell moving/copying files ≥nerating date&...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2002 08:39 AM
01-10-2002 08:39 AM
I have a script that copies files every min
in cron if they are present. Files can
be the same name and we do not want to over
write the file name but append the date and
time stamp.
SCRIPT:
find /virtual/easttrust/upload -type f |xargs -i cp {} /hal/easttrust/download
find /virtual/easttrust/upload -type f |xargs -i mv {} /tmp
For output I want this in both my directories:
filename.date and time stamp
Then I want to delete any files over 30 days
old so I don't get a disk full error.
Thanks,
Laurie
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2002 08:42 AM
01-10-2002 08:42 AM
Re: Bourne Shell moving/copying files ≥nerating date&time stamp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2002 08:44 AM
01-10-2002 08:44 AM
Re: Bourne Shell moving/copying files ≥nerating date&time stamp
You can make use of this variable to have date and time stamp
DATE=`/usr/bin/date '+%H%M'`
-USA..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2002 08:53 AM
01-10-2002 08:53 AM
Re: Bourne Shell moving/copying files ≥nerating date&time stamp
EXT=`date +%Y%m%d-%H%M`
for FILE in `find /hal/easttrust/upload -type f` ; do
cp $FILE /hal/easttrust/download/${FILE}.${EXT}
mv $FILE /tmp/${FILE}.${EXT}
done
Then to remove the old files just use find with -mtime +30. Maybe move the files to /tmp/old_upload or something instead of /tmp so you can limit the find command to those files only.
Regards,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2002 08:56 AM
01-10-2002 08:56 AM
Re: Bourne Shell moving/copying files ≥nerating date&time stamp
The way i see it, you should first change the name of the files in the source directory (upload) to look like filename.date and then move them to the other directory. you can then put a cron job to delete all files older than 30 days.
Hope this helps.
Regds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2002 08:57 AM
01-10-2002 08:57 AM
Re: Bourne Shell moving/copying files ≥nerating date&time stamp
- You receive files in .../upload
- You like to copy these files to .../download while adding a timestamp to the name
- You move the file away then, so that the procedure can work again, if the fiel is send again
??????
Since you do this every minute, how do you ensure, that you do not copy a file that is still in transmission ?
Since you did choose one minute as a period, you seem to expect these files quite frequently, so how do you ensure, that the file is not being sent right between those two "find" statements (which means it will be moved without beinig copied first)?
I would recommend to change the sending part in a way, that before a transmission of file "abc" it is checked if a file "abc.READY" exists, and if yes, the send is deleayed.
If "abc.READY" does not exist, you send "abc" and after the transmission you rename it "abc.READY" from the remote site.
Change you find commands just to process *.READY files, add the suggestions of the first two responses, and I guess you will be more safe.
Just my 2 cent
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2002 10:38 AM
01-10-2002 10:38 AM
SolutionWRKFILE=/tmp/wrkfile.$$
DT=`date +%Y%m%d%H%M`
find /virtual/easttrust/upload -type f >$WRKFILE
while read file
do
BNAME=`basename $file`
cp $file /hal/easttrust/download/$BNAME.$DT
mv $file /tmp/download/$BNAME.$DT
done <$WRKFILE
rm $WRKFILE
# remove files older than 30 days
find /hal/easttrust/download -type f -mtime +30 | xargs rm
find /tmp/download -type f -mtime +30 | xargs rm
# End script
I don't see why you need a second copy of the file in /tmp but I'd choose to use a directory created just for that purpose (/tmp/download in my example).
You can put DT=`date +%Y%m%d%H%M` in the while loop if you want the time each file is copied or leave it before the loop for all files to have the same date/time stamp (my preference).
As Volker points out, you have other issues to consider. Is a file busy? You may be able to use fuser to determine that but it could be busy for other reasons besides being written. But since you move it after copying it, then as long as it isn't busy the next time the script runs you should be okay.
Good luck,
Darrell