* Rikard Johnels (rjhn@linux.nu) [030602 14:33]:
As for the shellscript to list connected users... (anonymous as well as users) How do i get about that? I am NOT a very good programmer.. In fact, i almost cant write code at all... (
I would want a script (eg. "ftp_drop" ) that would disconnect a specified user/IP from the ftp session.
This should get you started, adding the kill-by-ip is left as an exercise to the reader (see netstat(8)): -- #!/bin/bash export PATH="/bin:/usr/bin:/sbin:/usr/sbin" export LANG="en_US" if [ -z "$*" ]; then echo "usage: $(basename $0) user_1 user_2 ... user_n" ; exit 1 fi for user in ${*}; do ps aux | egrep ^${user}.*[v]sftpd | awk '{print $2}' | \ while read pid; do su $user -c "kill ${pid}" && echo "killed $user" done done -- Some explanation. Finding the pid and then killing it is a little a risky since there's a chance that the user could have closed the connection and the kernel already recycled the pid to another process. Having kill run as the user instead of root minimizes the damage that might be done in this very improbable but possible case--at worst the user really will have a new process with the same pid and you kill that accidentally. -- -ckm