Sunday, January 28, 2018

[Shell script] Find user in system


The first way:

#!/bin/bash

if [ $# -eq 0 ]
then
 echo "Usage: $0 lawrence"
else
  grep "\<$1\>" /etc/passwd > /dev/null
  RETVAL=$?
  if [ $RETVAL -eq 0 ]
  then
   echo "Username $1 was found in the system"
  else
   echo "Cannot find username $1"
 fi
fi

The second way:

[ $# -eq 0 ] &&  { echo "Usage: $0 lawrence" ; exit 1; }

grep "\<$1\>" /etc/passwd > /dev/null
RETVAL=$?

[ $RETVAL -eq 0 ] && echo "Username $1 was found in the system" || echo "Cannot find username $1"

Thursday, January 04, 2018

How can I add EPEL reop on CentOS 7.x?

It's quite simple, just two commands below:

# yum install epel-release

# yum repolist

Sample output: