Hi!

I run Linux (easy peasy) on my netbook and have decided to encrypt the folder of my mail-client (in this case: evolution) via encfs.
So I wrote a little shell-script that does all the necessary steps:

  • ask for the password
  • decrypt and mount the directory
  • start evolution
  • umount the folder after evolution is shut down

So far, so good. My problem is: evolution keeps some nasty processes after its shutdown that prevent my script from umounting (ok, I know that the "-z"-option exists. But I want evolution to be swiched off, just to be sure).

I wrote a little testscript to kill those nasty processes:

#! /bin/bash

MOUNT=/home/maresi/.decrypted
MPUSED=`lsof | grep $MOUNT | awk '{print $2}'`

if [ -n "$MPUSED" ]
then
    #echo -n "\nDer Prozess Nr $MPUSED hat das Verzeichnis $MOUNT noch in Verwendung!!!!\n"
    echo -n "Proces Nr. $MPUSED still uses directory $MOUNT.\n"
    until [ $MPUSED -lt 1 ]; do
        MPUSED=`lsof | grep $MOUNT | awk '{print $2}'`
        echo kill -s SIGKILL $MPUSED
    done
fi

Output of "lsof | grep decrypted":

evolution 22199              maresi   24u      REG       0,23    53248    51503 /home/maresi/.decrypted/.evolution/addressbook/local/system/addressbook.db
evolution 22199              maresi   25u      REG       0,23     3356    51502 /home/maresi/.decrypted/.evolution/addressbook/local/system/addressbook.db.summary

The Problem is: it won't work as I thougt,
I get this output:

$ sh /tmp/test.sh 
Proces Nr. 22199
22199 still uses directory /home/maresi/.decrypted.
[: 15: 22199: unexpected operator
kill -s SIGKILL 22199 22199
[: 15: 22199: unexpected operator
kill -s SIGKILL 22199 22199
[: 15: 22199: unexpected operator
kill -s SIGKILL 22199 22199
[: 15: 22199: unexpected operator
kill -s SIGKILL 22199 22199
[: 15: 22199: unexpected operator
kill -s SIGKILL 22199 22199
[: 15: 22199: unexpected operator
kill -s SIGKILL 22199 22199
[: 15: 22199: unexpected operator
kill -s SIGKILL 22199 22199
[: 15: 22199: unexpected operator
^C

Somehow, both process numbers are stored in $MPUSED. I want/need just one of it, to shut down one process a time.

Can you help me?

Yours,

Maresi

Step 1

MPUSED=`lsof | grep $MOUNT | awk '{print $2}' | sort -u`

This makes sure that each PID which might have open files is captured only once.

Step 2
Then do

for i in $MPUSED; do
  echo kill -s SIGKILL $i
done

Hi Salem!

Thanks for your quick and helpful reply!
The code works like a charm!

Yours,

Maresi

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.