How can I find the user on Ubuntu (Shell/Bash)

Asked

Viewed 87 times

1

I want to create a system that should interactively find the user and then say whether it exists or not. I must provide the username and if the user is found then the system has found the username and enters, if it does not say that there was an error

I need to do something like that (in pseudo-code):

erro<-"O utilizador nao foi encontrado"
escreve ("Introduza nome de utilizador")
lê nome
se (nome==encontrado)
{
  ... entra no sistema
}
senao
{
     escreve ($erro)
}

in Bash on Linux Ubuntu:

#!/bin/bash
erro="Utilizador não encontrado"
echo "Qual o utilizador que pretende encontrar?"
read user

if[user  (encontrado)]#duvida
{
   ....
}
else
{
   echo $erro
}
fi
  • Where will be the "database" of users? You intend to use the /etc/passwd and validate whether the user/users exists inside or will have another user base?

1 answer

0


The correct script can be run this way, preferably as root

#!/bin/bash
erro="Utilizador não encontrado"
echo "Qual o utilizador que pretende encontrar?"
read user
if [ `cat /etc/passwd | cut -d \: -f1 | grep $user`  ] ; then
....
else
echo $erro
fi 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.