Created
May 24, 2020 17:33
-
-
Save parrazam/4cf1244d5d246c8c7045f18a36d0374a to your computer and use it in GitHub Desktop.
Script en Perl para dar de baja un usuario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Script que permite dar de baja un usuario. | |
# Author: Víctor Parra [parra@usal.es] | |
# AVISO: Requiere permisos de root | |
# Es necesario instalar el File::Path y el Linux::usermod | |
# ># perl -MCPAN -e 'install File::Path' | |
# ># perl -MCPAN -e 'install Linux::usermod' | |
# Parámetros: | |
# - [nombre_del_usuario] -> Nombre del usuario | |
$args=@ARGV; | |
if ($args < 1) | |
{ | |
print "\n"; | |
print "Uso: $0 [nombre_del_usuario]\n"; | |
print "\n"; | |
print "\n"; | |
die "Abortando"; | |
} | |
$ruta="/home/" . $ARGV[0] . "/"; | |
$usuario=$ARGV[0]; | |
use Linux::usermod; | |
use File::Path; | |
print "Borrando el directorio $ruta...\n"; | |
rmtree($ruta, 1, 1 ) or die "rmtree: $!\n"; | |
Linux::usermod->del($usuario) or die "Deluser: $!\n"; | |
print "\nUsuario $usuario borrado con éxito\n"; | |
print "\n"; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment