lock test from sh script

Daniel O'Connor doconnor at gsoft.com.au
Fri Oct 17 12:16:33 UTC 2008


On Friday 17 October 2008 20:18:20 Igor Pokrovsky wrote:
> I need to check if file is locked or not (with flock) from a shell
> script. I remember there was something but cannot recall what exactly.
> And if possible I do not want to write my own test utility even it
> is several lines in length)

lockf -s -t 0 /path/to/file /bin/echo -n
if [ $? -eq 75 ]; then
	echo file is locked
	exit
fi

-- 
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
  -- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20081017/e4da5d15/attachment-0001.pgp


More information about the freebsd-hackers mailing list