|
Sams Teach Yourself Samba in 24 Hours |
|||||||||||||||||
|
Hour 10: Server-Side Automation |
|||||||||||||||||
|
I have included this last section in hopes that it will inspire your own creativity. One thing that can be difficult is determining which smbd processes are associated with which users. Hour 4, "Installing and Testing the Configuration," explains how to determine this information by using the smbstatus tool. In this section, I'm going to show you how to use root preexec and postexec scripts to implement the capability to kill all smbd processes that are running in the context of a particular user. The system comprises three basic parts:
I'll examine each component one at a time. First, I'll examine the root preexec and root postexec commands. I want to associate a process ID with a username. This information is available in the %d and %U smb.conf variables respectively. The root preexec command creates a file with the name of the process ID for the connection and contains only the username sent by the client:
[apps]
comment = global shared drive
root preexec = echo %U > /usr/local/samba/lib/proc/%d
root postexec = /bin/rm /usr/local/samba/lib/proc/%d
path = /export/smb/apps
The assumption here is that every client connects to the [apps] share in addition to any other service. This is an easy assumption to work around if you check for the existence of /usr/local/samba/lib/proc/%d before attempting to create it. For now, assume that all clients connect to the [apps] share.
After the files are created, you can create a simple script to grep for the user's login name in the files. The located files will be the process IDs of the associated smbds.
#!/bin/sh # set the path PATH=/usr/bin:/bin export PATH # set the location for the pid files SMBD_DIR=/usr/local/samba/lib/proc # the username should be passed as the single command line parameter if [ "$1" eq "" ]; then echo `Usage : killsmbd <username>' else username=$1 fi for pid in `grep $username $SMBD_DIR/*`; do echo "Killing $pid" kill -9 $pid
done
If you want to kill all the smbd processes for the user jdoe, you can simply type
killsmbd jdoe
You can design a similar system to enable you to terminate smbd processes based on the connected machine name by creating files that contain the %m variable.
|
Sams Teach Yourself Samba in 24 Hours |
|||||||||||||||||
|
Hour 10: Server-Side Automation |
|||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.