- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script - check file before copy
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
Discussions
Discussions
Forums
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
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
тАО04-28-2009 03:29 AM
тАО04-28-2009 03:29 AM
below script transfer file, the file creates by application and start writting data to it and it takes 1 hour to complete, and every two hour create new file, the problem I have I need to copy the file only when it is complete written to it or if it is not 0 size.
--------my script ---------------------
#
cd /NRT/NRT_src
ls *NR_BHRBT_* | read LINE
if [ $? = 0 ]
then
mv $LINE /NRT_backup
date | read sdate
cd /NRT_backup
scp $LINE BHRBTF@111.111.11.11:/
if [ $? -eq 0 ];then
date | read edate
echo Finish copy $LINE $sdate >>/NRT_daily_out.log
else
echo Failed copy of $LINE "$edate" >/NRT_faild.log
fi
fi
-----------------------------------
Regards,
Ahmed
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 03:53 AM
тАО04-28-2009 03:53 AM
SolutionYou could use 'fuser' to look for any process(es) still using the file and when none, perform your copy:
...
while true do
PIDS=$(fuser ${FILE} 2> /dev/null) #...look for any process using file...
[ -z "${PIDS}" ] && break #...no processes, so OK to continue
sleep 60
done
...
Use the '-s' test for size:
# [ -s ${FILE} ] && echo "size > 0" || echo "size = 0"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 03:56 AM
тАО04-28-2009 03:56 AM
Re: script - check file before copy
See the if -z and/or -f parameter.
http://forums.bsdnexus.com/viewtopic.php?id=1272
http://www.linuxquestions.org/questions/linux-server-73/shell-script-problem.-check-file-already-exists-601105/
http://www.unix.com/shell-programming-scripting/32809-have-shell-script-check-file-exist-before-processing-another-file.html
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 08:32 AM
тАО04-28-2009 08:32 AM
Re: script - check file before copy
The first is hard to determine unless you are root and can use JRF's fuser.
If there is something at the end if the file you can check, you can use tail and grep.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 12:24 PM
тАО04-28-2009 12:24 PM
Re: script - check file before copy
but valid values of "wait for a bit" might be hard to determine.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2009 02:11 PM
тАО04-28-2009 02:11 PM
Re: script - check file before copy
Some applications are more helpful than
others in cases like this. For example, when
Info-ZIP Zip creates an archive (say,
"fred.zip"), it normally uses a temporary
file name (like "ziXXXXXX", with help from
mkstemp()). Then, when the work is done (and
if all went well), it renames the temporary
file to the requested name ("ziXXXXXX" to
"fred.zip", in this case). So, if you can
see "fred.zip", then you can be pretty sure
that it's all there.
Of course, this requires some extra work by
the application.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2009 03:01 AM
тАО04-29-2009 03:01 AM