I am trying to create a bash script which contains user verifcation at the start, based on the argument of domain name on a cpanel/whm server...
I want to pass the first argument to a varible which checks the domian exists.
I am trying to do this using the cpanel 'whoowns' scripts (which is one that is on all cpanel whm servers), and then echo the result if the whoowns is empty or not, thus confirming if the user account exists .
however this just always echos 'cpuser does not exists for this domain' regardless on if the user exists or not
Is this possible the way I am trying to do this, is there a better way?
#! /bin/bash
# $1 Domain
#set user from domain
cpuser= /scripts/whoowns $1
#check if user exists
if [ -z "$cpuser" ]; then
echo "cpuser does not exist for this domain";exit
else echo 'user exists'
fi
I want the script to echo 'this account does not exist' and exit if the user does not exist
I do not know what a whoowns script is but I image that it echoes to the stdout the name of account owning $1 So you could try something like this
#!/bin/bash
# $1 Domain
#set user from domain
cpuser=$(/scripts/whoowns $1)
#check if user exists
if [ -z "$cpuser" ]; then
echo "cpuser does not exist for this domain"
exit
else
echo 'user exists'
fi