in reply to Script for SFTP users not deleting accounts automatically

This does not do what you want, what happens if mkpasswd() yields illegal characters for a second time in a row?:

my $password = mkpasswd(); if ( $password =~ m/\"|\'/ ) { $password = mkpasswd(); }

consider this instead:

my $password; do { # theoretically it can get stuck in an infinite loop here... $password = mkpasswd(); } while( $password =~ m/\"|\'/ );

As for deleting user dirs, you really should check rmtree's return code, see File::Path . Also check each system()'s return code and handle failures accordingly. You don't do this.

For a discussion about using system() and alternatives see Calling External Commands More Safely

Replies are listed 'Best First'.
Re^2: Script for SFTP users not deleting accounts automatically
by haukex (Archbishop) on Jul 06, 2019 at 15:27 UTC

    I second these points! Here's one more: open( my $expFile , qq{>>/etc/ssh/sftp-users.dat} ); would be better as the three-argument open and it should definitely check for errors: open( my $expFile, '>>', q{/etc/ssh/sftp-users.dat} ) or die $!;