Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

hello I'm using openvpn and free-radius for control user accounts. for maximum session time for an user, free-radius has sqlcounter.conf that control that, but after a connection has disconnected that is useful and cannot destroy a connection. for control account time dynamically i need another script that do that. but should anytime that a connection has established a trigger run. is anyway to fire a custom trigger or script when a connection has established? or any way to control session time dynamically?

share|improve this question

hello everybody after couple of search i cannot find a way to do that, but a way to know when a connection is established is use radius log files and radius database. mysql have not a notify in change method but for log files can use file system notify patches for example dnotify "in the past" and inotify library. i start using that and post that result.

share|improve this answer

hello everybody i do that, with a c program that look for a program change, you can check a user connection to openvpn.

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <linux/inotify.h>
#include <sys/select.h>
#define EVENT_SIZE  ( sizeof (struct inotify_event) )
#define EVENT_BUF_LEN     ( 1024 * ( EVENT_SIZE + 16 ) )
int event_check (int fd)
  fd_set rfds;
  FD_ZERO (&rfds);
  FD_SET (fd, &rfds);
  /* Wait until an event happens or we get interrupted 
     by a signal that we catch */
  return select (FD_SETSIZE, &rfds, NULL, NULL, NULL);

int main( )
  int length, i = 0;
  int fd;
  int wd;
  fd = inotify_init();

  if ( fd < 0 ) {
    perror( "inotify_init" );

  wd = inotify_add_watch( fd, "/tmp/test", IN_CLOSE_WRITE);
    if (event_check (fd) > 0)
        char buffer[EVENT_BUF_LEN];
        int count = 0;
        length = read( fd, buffer, EVENT_BUF_LEN ); 
        if ( length < 0 ) {
            perror( "read" );
         while ( i < length ) {     struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ]; 
            printf( "New file %s Editted.\n", event->name );
            i += EVENT_SIZE + event->len;
    inotify_rm_watch( fd, wd );
   close( fd );

but this is not so good code, but its working, can anybody write this code better?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.