- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Unix command
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
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
04-25-2007 04:25 AM
04-25-2007 04:25 AM
Some files are coming into the directory via remote FTP transfer. The application is processing those files after the FTP is complete.
We have a requirement to write a Unix script to check for a given file that is still open for writing. If it is open the script passes back to the application "true" or "false".
What is the best command to acheive this?
We are running HP-X 11.23
Thanks in advance for your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 04:28 AM
04-25-2007 04:28 AM
Re: Unix command
Another option is lsof - http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.77/
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 04:30 AM
04-25-2007 04:30 AM
Re: Unix command
I hope this helps,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 04:31 AM
04-25-2007 04:31 AM
SolutionI have used this with success:
PIDS=`fuser ${FILE} 2> /dev/null` #...look for any process using file...
if [ ! -z "${PIDS}" ]; then
print -u2 "Error: '${FILE}' is inuse by process(es): ${PIDS}"
... # do whatever you need to do ...
fi
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 04:31 AM
04-25-2007 04:31 AM
Re: Unix command
http://www.techsolutions.hp.com/en/B2355-60105/fuser.1M.html
Rgds,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 05:30 AM
04-25-2007 05:30 AM
Re: Unix command
James,
I used your command to test.
I opened up a file for editing in one session.
vi p3i.sh
On another session I did the
fuser /home/user/p3i.sh
It only returned the "/home/user/p3i.sh" No processes were returned.
I am not sure why it did not the process name on "vi p3i.sh"
Can you please see what is wrong with the command I am executing?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 05:54 AM
04-25-2007 05:54 AM
Re: Unix command
According to vi(1):
In vi, the terminal screen acts as a window into a memory copy of the
file being edited. Changes made to the file copy are reflected in the
screen display. The position of the cursor on the screen indicates
the position within the file copy.
So, in your example, vi is operating on a cached version of 'p3i.sh'. Since the actual file is not open, running fuser on the file returns nothing.
Try this instead:
$ tail -f ./p3i.sh
$ fuser ./p3i.sh
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 05:56 AM
04-25-2007 05:56 AM
Re: Unix command
Using 'vi' for your test will fail, as you found. 'Vi' opens a file and reads it into memory for the duration of your session's work. Only when you write and quit does your (disk) copy get updated.
You can use this small Perl snippet to open a file called '/tmp/data' and keep it open for your test:
# perl -le 'open(FH,"+>>","/tmp/data") or die;print FH "\n";sleep 120' &
# fuser /tmp/data
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 06:25 AM
04-25-2007 06:25 AM
Re: Unix command
The file I am checking for usage is located in the NFS mount point. Do I have to give the full server:/mountpoint/file to fuser?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 06:36 AM
04-25-2007 06:36 AM
Re: Unix command
No, the filename is sufficient. However, realize that fuser will not tell you if the file is open by another system.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2007 07:53 AM
04-25-2007 07:53 AM
Re: Unix command
a relatively simple way to deal with this
problem is to "put" the file into some
temporary name (or directory), and then, when
the transmission is complete, "rename" it to
its final destination name (or directory).
That way, when the file appears at its final
destination, you know that the sender thinks
that it's complete, and it will be closed.