„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
#!/bin/bash
LANG=C LC_ALL=C TZ=UTC0
export LANG LC_ALL TZ
function read_prompt() {
read -p "$(echo -en "E[1;37m${1}E[0m " >&2)" "${2:-REPLY}"
until [ -z $(echo "${2:-REPLY}" | tr -d '[[:print:]]') ]
do
show_warn "non-printable char(s) detected! Please retry...n"
read_prompt "${1}" "${2}"
done
return
}
function read_passwd() {
read -s -p "$(echo -en "E[1;37m${1}E[0m " >&2)" "${2:-REPLY}"
until [ -z $(echo "${2:-REPLY}" | tr -d '[[:print:]]') ]
do
show_warn "non-printable char(s) detected! Please retry...n"
read_prompt "${1}" "${2}"
done
return
}
function show_text() {
echo -en "E[1;37m${1}E[0m" >&2
return
}
function show_info() {
echo -en "E[1;32m${1}E[0m" >&2
return
}
function show_warn() {
echo -en "E[1;33m${1}E[0m" >&2
return
}
function show_error() {
echo -en "E[1;31m${1}E[0m" >&2
return
}
function root_only() {
if [ "${UID}" != "0" ] || [ "${EUID}" != "0" ]
then
show_error "You must be root to run this script!n"
fi
return
}
function import_db() {
local username password database
show_info "Please enter your database usernamen"
read_prompt "Username:"
if [ -z "${username}" ]
then
show_error "aborting...n"
exit 1
fi
show_info "Please enter your database passwordn"
read_passwd "Password:"
if [ -z "${password}" ]
then
show_error "aborting...n"
exit 1
fi
show_info "Please enter the database to importn"
read_prompt "Database:"
if [ -z "${database}" ]
then
show_error "aborting...n"
exit 1
fi
mysql -u${username} -p${password} ${database} < ${database}.sql
return
}
root_only
import_db
exit 0
Als Hausaufgabe und Entschädigung für meine Mühen, darfst Du dieses Script mit vernünftigen Kommentaren versehen und zur weiteren Kontrolle hier posten, danke.
„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.