Tuntutan seorang administrator yang harus selalu aktif dan mobile membuat saya harus mengetahui segala troubleshoot dari command line. termasuk mengganti password email dari command line cPanel
berikut ini terlampir bash script untuk mengganti password single email account
Mengganti password email dari command line cPanel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#!/bin/bash - #title :changemailpass.sh #description :To change password of a single mail account in cPanel via terminal #author :Arun Ghosh #date :20130811 #version :1.0 #usage :./changemailpass.sh #notes : #bash_version :4.2.25(1)-release #============================================================================ MAIL_USER=$1 NEW_PASS=$2 MAIL_FLAG=false DOMAIN=$(echo $MAIL_USER | cut -d"@" -f2) MAIL=$(echo $MAIL_USER | cut -d"@" -f1) EXIST=`grep ^$DOMAIN /etc/userdomains` if [ "$EXIST" ] then CP_USER=`grep ^$DOMAIN /etc/userdomains | cut -d":" -f2 | tr -d ' '` SHADOW_FILE="/home/$CP_USER/etc/$DOMAIN/shadow" cat /dev/null > "/home/$CP_USER/etc/$DOMAIN/shadow.tmp" for shadow in `cat /home/$CP_USER/etc/$DOMAIN/shadow` do pass=$(openssl passwd -1 $NEW_PASS) user=$(echo $shadow | cut -d":" -f1) rest=$(echo $shadow | cut -d":" -f3-) if [ "$user" == "$MAIL" ] then MAIL_FLAG=true echo "$user":$pass:$rest >> /home/$CP_USER/etc/$DOMAIN/shadow.tmp else echo $shadow >>/home/$CP_USER/etc/$DOMAIN/shadow.tmp fi done if [ $MAIL_FLAG = false ] then echo "$1 not exists..!!"; elif [ $MAIL_FLAG = true ] then echo "$1 password changed to: $2" fi mv "/home/$CP_USER/etc/$DOMAIN/shadow" "/home/$CP_USER/etc/$DOMAIN/shadow.$(date +%s)" mv "/home/$CP_USER/etc/$DOMAIN/shadow.tmp" "/home/$CP_USER/etc/$DOMAIN/shadow" chmod 640 "/home/$CP_USER/etc/$DOMAIN/shadow" chown $CP_USER:$CP_USER "/home/$CP_USER/etc/$DOMAIN/shadow" else echo "Domain not in the server" fi |
lalu edit simpan dengan nama changemailpass.sh dan edit permission file-nya menjadi:
1 |
chmod 755 changemailpass.sh |
untuk menjalankan perintah diatas gunakan perintah dibawah ini
# ./changemailpass.sh <mail_account> <newpassword>
selamat mencoba