amt has asked for the wisdom of the Perl Monks concerning the following question:

Gentlemen,

Moving forward from my previous FreeRadius enlightenment, FR Config Sanity Checking, I need to restart the FreeRadius daemon on the remote system.

I am authorized through SSH keys to the remote server to scp the generated configuration files to said server, however, I am having trouble reloading in order for the changes to take effect.

Below is the code, that I have in the propagate function.
####### Begin Dumb Propagate Function ####### foreach $addr (keys %FR_servers) { if( system("sudo /usr/bin/scp -Bpq $config_file $addr: +/usr/local/etc/raddb/") == 0 ){ $FR_servers{$addr} = 1; # mar +k for user feedback } else { $FR_servers{$addr} = 0;} if( system("sudo /usr/bin/scp -Bpq $users_file $addr:/ +usr/local/etc/raddb/") == 0){ $FR_servers{$addr} = 1; } else { $FR_servers{$addr} = 0;} system("sudo ssh $addr $reloadcmd"); # reload freeradi +us remotely } ####### Finish Dumb Propagate Function #######
This is the string that I send as $reloadcmd.
# command for reloading FreeRadius configuration # touching the file works on both local and remote filesystems my $reloadcmd = "/usr/local/sbin/rc.radiusd reload > /tmp/reload_ouput +"; #"/bin/touch /tmp/test_reload_config";
The file /tmp/reload_output on the local file system has output, however, the remote system doesn't have the redirected output.

Changing the command to a 'sudoed' command, results in the script spinning for a while, but the same result.

You will also see that when I 'touch' a file on the remote filesystem that that file appears.

Many thanks in advance, I want to get this done before I go on vacation ;)

amt.

perlcheat

Replies are listed 'Best First'.
Re: FR Reload Issues
by samtregar (Abbot) on Nov 03, 2004 at 17:52 UTC
    You're not checking the return value from your call to system. Try something like this:

    system("sudo ssh $addr $reloadcmd") && die("Failed to 'sudo ssh $addr $reloadcmd': $?");

    That should give you some idea what's going on.

    For more information about dealing with errors from system(), see the system() docs in perlfunc:

       $ perldoc -f system

    -sam

      samtregar, thank you for the direction. This was intent of this post, not the knock em dead answer.

      cheers.
      Update
      Taking your suggestion, I am returned with:
      Failed to 'sudo ssh 192.168.1.243 /usr/local/sbin/rc.radiusd reload > +/tmp/reload_ouput': 0 at /usr/local/nagios/perl/radpass.pl line 1184.

      I don't understand why I could be getting a 0 for $?. I tried removing the redirection of the output, but I still get 0. My system call isn't returning a -1, so it's being accepted.
      amt.

      perlcheat
        Try replacing the command with something simpler like:

        system("sudo ssh $addr echo Hello") && die("Failed to 'sudo ssh $addr echo Hello': $?");

        If that works then you know the problem isn't with sudo or ssh. You need to look at $reloadcmd and figure out why it's failing. You haven't told us anything about this code so it's hard to know why it might exit(0).

        -sam