I have to create a script that can receive up to two parameters:
In case you receive 0 parameters the script has to show the login of all system users.
In the case that it receives 1 parameter if parameter 1 is "-h" that shows a help or text and if parameter 1 is a name for example "Antonio" it creates said user by asking for the password that he will want, name, address, email and phone number, creating the user with this information.
If you receive 2 parameters:
If you receive the format "-l Antonio, Paco will do the same as the previous case but creating the users entered, separated by a comma.
If the script is called incorrectly, it should return an error.
At the moment I have managed more or less the structure of the script but only gives me one failure after another and I can not finish it ... Let's see if someone who is more placed on ShellScripts can help me to finish it, because I can not find the way for more than I edit the code.
I leave you what I have here:
#!/bin/bash
if [ $# = 0 ];then
echo $(users)
echo $(who)
elif [ $# = 1 ];then
if [ $1 = "-h" ];then
echo "Tienes que escribir el nombre del script y un nombre de usuario o
si pones mas de un usuario, tienes que separarlos por coma."
else
$(adduser -d -c $1) #no me acuerdo de como era la sintaxis exacta del
adduser para preguntar por la contraseña
fi
elif [ $# = 2 ]; then
if [ $1 = '-l' ] then;
for x in (echo $2 | cut -d ',' -f1) then
usuario = echo $2 | cut -d ',' -f1
$(adduser -d -c $1)
done
fi
else
echo "Usa -h para más información"
fi