Discussion:
lock test from sh script
(too old to reply)
Igor Pokrovsky
2008-10-17 09:48:20 UTC
Permalink
Hi all!

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)

Thanks,
-ip
Dag-Erling Smørgrav
2008-10-17 11:56:54 UTC
Permalink
Post by Igor Pokrovsky
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 -t0 <file> true

DES
--
Dag-Erling Smørgrav - ***@des.no
Pieter de Goeje
2008-10-17 11:52:46 UTC
Permalink
Post by Igor Pokrovsky
Hi all!
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)
Thanks,
-ip
Perhaps you mean lockf(3) ?
--
Pieter de Goeje
Daniel O'Connor
2008-10-17 12:00:52 UTC
Permalink
Post by Igor Pokrovsky
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
Continue reading on narkive:
Loading...