Answer the question
In order to leave comments, you need to log in
Linux bash virtualhost apache. How to pass parameters?
I don't know bush well. I want to write a script that would create virtual hosts for Apache. I wrote the script and it works. But then the idea came up to add the ability to specify aliases to the virtual host. I planned to implement all this according to the appropriate flags.
For example:
addvhost -host example.dev -dir /home/domains/ -alias adm.example.loc
#!/bin/bash
set -e
ME=`basename $0`
function printHelp() {
echo "Скрипт добавления виртуальных хостов"
echo
echo "Используйте: "$ME" с опциями:"
echo " -h имя виртуального хоста"
echo " -a алиас"
echo " -d путь до директории"
echo
exit 0;
}
function writeHost() {
echo $host
echo $alias
echo $path
тут само добавление и тд..
}
# Если скрипт запущен без аргументов, открываем справку.
if [ $# = 0 ]; then
printHelp
fi
while getopts "h:a:d:" opt;
do
case $opt in
h) host=$OPTARG;
writeHost
;;
a) alias=$OPTARG;
writeHost
;;
d) path=$OPTARG;
writeHost
;;
*) echo "Неправильный параметр";
echo "Для вызова справки запустите $ME -help";
exit 1
;;
esac
done
[email protected] ~ $ sudo addvhost1 -h text -d dddd -a alias
text
text
dddd
text
alias
dddd
Answer the question
In order to leave comments, you need to log in
So it's all good, isn't it?
getopts handles all the options, and you, after it does everything, run writeHost
while getopts "h:a:d:" opt;
do
case $opt in
h) host=$OPTARG;
;;
a) alias=$OPTARG;
;;
d) path=$OPTARG;
;;
*) echo "Неправильный параметр";
echo "Для вызова справки запустите $ME -help";
exit 1
;;
esac
done
writeHost
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question