I want to run a bash script everytime someone opens an FTP session on Linux. Ideally, the solution should be compatible with any FTP server. Perhaps a way to detect when credentials are accepted at a certain port. Any ideas?
You can write a script that parses the log file of say ftp daemons such as vsftpd and proftpd and do something once it finds a line that matches what you want. However it would be different for each daemon as each has their own log style. On top of which, there will be delay as you will probably have to poll the file to see if its changed.
A perhaps more portable solution and better response time would be to make a PAM module(WAY MORE WORK THOUGH) A lot of daemons have PAM support built in. so when someone logs into ssh for instance it will query PAM and the PAM config will pick for the login whether LDAP or UNIX file. then it has like password modules like cracklib to check if it works.
it short you can append this line to the pam config of the particular service once you make a pam module. session required /lib/security/pam_yourmodule.so
http://www.linux.com/archive/feature/113567 for a quick primer on PAM.