Skip to content

Instantly share code, notes, and snippets.

/change_ftp_password.sh Secret

Created Nov 14, 2013
Embed
What would you like to do?
#!/bin/bash
FTP_USER="$1";
FTP_PASSWORD="$2";
FTP_PASSWD_FILE="/etc/pure-ftpd/pureftpd.passwd";
CHECK_LOGIN=$(cat "$FTP_PASSWD_FILE" | grep "$FTP_USER:" | cut -d ':' -f 1 | wc -l);
DieWithError()
{
echo "$1" 1>&2;
exit 1;
}
[ -z "$FTP_USER" ] && DieWithError "Usage: $0 <ftp_login> <ftp_password>";
[ -z "$FTP_PASSWORD" ] && DieWithError "Usage: $0 <ftp_login> <ftp_password>";
[ $CHECK_LOGIN -eq 0 ] && DieWithError "Error: the specified login does not exist";
echo -e "${FTP_PASSWORD}\n${FTP_PASSWORD}\n" | pure-pw passwd "${FTP_USER}" &> /dev/null;
pure-pw mkdb > /dev/null 2>&1;
/etc/init.d/pure-ftpd restart > /dev/null 2>&1;
echo -e "Done!\n";
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment