Hello mldvx4,
An alternative solution would be to change the username through the usermod and also after the /home dir if exists?
Sample of code:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $nname = "monk"; my $name = "testuser"; sub rename_account { my ( $name , $nname ) = ( @_ ); my $username = `usermod -l $nname $name`; my $dirusername = `usermod -d /home/$nname -m $nname`; chomp(my @dir = `ls -la /home`); print Dumper \@dir; } # rename_account("monk", "testuser"); rename_account("testuser", "monk"); __END__ $ sudo perl sample.pl $VAR1 = [ 'total 16', 'drwxr-xr-x 4 root root 4096 Mar 19 12:57 .', 'drwxr-xr-x 24 root root 4096 Mar 7 15:04 ..', 'drwxr-xr-x 2 monk testuser 4096 Mar 19 12:51 monk', ];
The script will not produce any error if the user exists etc.
Hope this helps, BR.
In reply to Re: Linux::usermod - user name ... already exists
by thanos1983
in thread Linux::usermod - user name ... already exists
by mldvx4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |