It is a hassle to have to start clamfs manually every time a user logs in the first time. It is, therefore, a good idea to automate the running of clamfs. You can attach shell scripts to .bashrc to do this. However, .bashrc executes for each login, and we don’t really need to remount clamfs for each and every login session.
The problem can be solved using a script. The following script is written in Perl, which is widely supported by most distributions.
Copy and paste this code into a file called startClamfs.pl. Then change the permissions to allow the user owner to execute it (use chmod). You will also need to change the two lines commented # change this line to use your specific file names and directory names.
Note that this script does not support multiple instances of clamfs, nor is it truly optimal. Those who want to improve it can do so.
This script first checks whether clamfs is already running. It starts clamfs only if the mount point is not mounted yet. As a result, you can invoke this script from any log in/authentication script.
For the command line interface, you can append this line to ~/.bashrc:
If you use a GUI environment, such as GNOME, you can also run this script automatically when you log in. Consult this link (http://www.howtoforge.com/make-desktop-applications-start-automatically-gnome) for more details.
Important: The script does not unmount the clamfs directories, even when the user logs out. On a workstation, this should be of little or no issue, as the total number of users should be fairly small. However, on a server that supports a large number of users, leaving a large number of clamfs instances running can consume memory.
In a server environment, a system script can run periodically to “sweep” clamfs instances that are no longer needed. The construction of such a script, however, is out of the scope of this module.