简体   繁体   中英

I am trying to create a bash script which contains user verifcation at the start, based on domain name on a cpanel/whm server

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM