Mgrctl - ISPManager - сменить пароль пользователя - bash скрипт

Материал из Wiki - Iphoster - the best ever hosting and support. 2005 - 2026
Перейти к:навигация, поиск



#!/bin/bash

MGRCTL="/usr/local/mgr5/sbin/mgrctl"

read -rp "Enter ISPmanager username: " USER

if [ -z "$USER" ]; then
    echo "Error: username is required"
    exit 1
fi

# Check if the user exists
if ! "$MGRCTL" -m ispmgr user | grep -q "^name=$USER "; then
    echo "Error: user '$USER' not found"
    exit 1
fi

# Generate a random 15-character password
PASSWORD=$(LC_ALL=C tr -dc 'A-Za-z0-9_@%+=' < /dev/urandom | head -c 15)

# Change ISPmanager password
if "$MGRCTL" -m ispmgr user.edit \
    elid="$USER" \
    passwd="$PASSWORD" \
    confirm="$PASSWORD" \
    sok=ok >/dev/null; then

    echo
    echo "========================================"
    echo "Password successfully changed"
    echo "Username: $USER"
    echo "Password: $PASSWORD"
    echo "========================================"

else
    echo
    echo "ERROR: Failed to change password"
    exit 1
fi
×
Реклама
ИКС