- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Test for file open
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
тАО10-18-2006 02:32 AM
тАО10-18-2006 02:32 AM
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2006 02:37 AM
- Tags:
- fuser
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2006 02:37 AM
тАО10-18-2006 02:37 AM
Re: Test for file open
You can test with 'fuser'. Here's a snippet of code I often use:
...
PIDS=`fuser ${FILE} 2> /dev/null` #...look for any processes...
if [ ! -z "${PIDS}" ]; then
print -u2 "Error: '${FILE}' is inuse by process(es): ${PIDS}"
fi
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2006 02:38 AM
тАО10-18-2006 02:38 AM
Re: Test for file open
look for 'lsof' - it can report about open files:
http://gatekeep.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.77/
..., but I'm not shure, if your approach for 'locking' files is the right one.
mfG Peter
- Tags:
- lsof
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2006 02:41 AM
тАО10-18-2006 02:41 AM
Re: Test for file open
I don't know how often I've used the fuser command (when unmounting filesystems), and it didn't cross my mind that I could use it in this instance.
Thanks for the quick replies.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2006 02:42 AM
тАО10-18-2006 02:42 AM
Re: Test for file open
The first example here shows what processes have a oracle data file open.
# lsof apd03.dbf
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
oraclepro 14739 oracle 34u VREG 64,0x2000a 524296192 6 apd03.dbf
ora_dbw0_ 16430 oracle 212uW VREG 64,0x2000a 524296192 6 apd03.dbf
ora_lgwr_ 16432 oracle 214u VREG 64,0x2000a 524296192 6 apd03.dbf
ora_smon_ 16436 oracle 208u VREG 64,0x2000a 524296192 6 apd03.dbf
If nothing has a file open then you will be returned to the prompt.
# lsof /etc/hosts
So something like this may work:
FILE=filename
OPEN=$(lsof ${FILE} | wc -l)
if (( ${OPEN} == 0 )) ; then
echo "${FILE} is not open"
else
echo "${FILE} is open"
fi