You can use lsof | grep /absolute/path/to/file.txt
to see if a file is open.
If the file is open, this command will return status 0, otherwise it will return 256 (1).
Be aware that this command will take a second since there are, normally, a lot of files open at any time.
You can also use lsof -c gedit
, for example, to see which file gedit has opened. Restricting the output to one process will reduce execution time to practically nought.
Here's a script to wait:
#!/bin/bash
while :
do
if ! [[ `lsof -c python3.2 | grep test.py` ]]
then
break
fi
sleep 0.5
done
echo "done"
This runs while a process 'pyhton3.2' has got the file 'test.py' opened. As soon as the file is closed, it moves on to 'echo done' and exits.
I've put 'sleep 0.5' in there so that the loop doesn't hog the CPU all that badly. Otherwise, it will use 100% cpu.
Bonus
There seems to be an easy way to convent odt to pdf:
Thanks to scls19fr on the OOo Forum
for this lovely tip. You can convert
OpenOffice Writer files to PDF from
the command line using unoconv -f pdf
input.odt
To get unoconv, simply run
sudo apt-get install unoconv
at the
terminal.
(rhyshale of rhyshale.wordpress.com)
I just call sudo if the program needs root permissions, but doesn't have:
#!/bin/bash
if [ $(id -u) != 0 ]; then
echo "This script requires root permissions"
sudo "$0" "$@"
exit
fi
"$0"
contains the name of the script, "$@"
optional arguments. It may be omitted if your program does not accept arguments.
Note: this shellscript is expected to be run in a shell, if this script should run as GUI, use something like gksu
or kdesudo
instead of sudo
.
Best Answer
A bash script to do something like that would look something like this:
This script is just checking to see if the program "gedit" is running.
Or you can only check if the program is not running like this: