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.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Linux::usermod - user name ... already exists by thanos1983
in thread Linux::usermod - user name ... already exists by mldvx4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.