#!/bin/bash
read -p "Please input the operation (create or delete ): " OPERATION
// Ingrese la acción que desea realizar
case $OPERATION in
create) // El primer caso: crear
read -p "Please input the userfile : " USERFILE // Solicitar archivo de entrada
[ -e $USERFILE ] || { // Determinar si existe
echo "$USERFILE is not exist "
exit 1
}
read -p "Please input the passwdfile : " PASSFILE
[ -e $PASSFILE ] || {
echo "$PASSFILE is not exist "
exit 1
}
USERLINE=`awk 'BEGIN{N=0}{N++}END{print N}' $USERFILE` // Calcular el número de líneas de archivo de archivo de usuario
for LINE_NUM in `seq 1 $USERLINE` // usa loop para construir
do
USERNAME=`sed -n "${LINE_NUM}p" $USERFILE` // Intercepta la primera línea del archivo de archivo de usuario
PASSWORD=`sed -n "${LINE_NUM}p" $PASSFILE` // Intercepta la primera línea del archivo de passfile
useradd $USERNAME // Crear usuario
echo $PASSWORD | passwd --stdin $USERNAME
done
;;
delete) // La segunda situación: eliminar
read -p "Please input the userfile : " USERFILE
[ -e $USERFILE ] || {
echo "$USERFILE is not exist "
exit 1
}
USERLINE=`awk 'BEGIN{N=0}{N++}END{print N}' $USERFILE`
for LINE_NUM in `seq 1 $USERLINE`
do
USERNAME=`sed -n "${LINE_NUM}p" $USERFILE`
userdel -r $USERNAME
done
;;
*) // La tercera situación: las diversas situaciones restantes
echo Eorror!
;;
Esac
#!/bin/bash
/usr/bin/expect << EOF // Cambiar al entorno esperado
spawn ssh root@$1 // IP de conexión ssh
expect {
"yes/no" { send "yes\r";exp_continue } // Confirma la conexión
"password" { send "$2\r" } // Ingrese la contraseña
}
Interact // reservado
EOF // salir
#!/bin/bash
Auto_Connect()
{
/usr/bin/expect << EOF
set timeout 5
spawn ssh root@172.25.254.$IP_NUM hostname
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "westos\r" }
}
expect eof
EOF
}
for IP_NUM in {71..72}
do
ping -c1 -w1 172.25.254.$IP_NUM &> /dev/null && {
Host_Name=`Auto_Connect | grep -E "authenticity|fingerprint|connecting|password|spawn|Warning" -v` // Filtrar advertencias y otras declaraciones
}
echo " $Host_Name 172.25.254.$IP_NUM"
done
#!/bin/bash
Auto_Connect()
{
/usr/bin/expect << EOF
set timeout 5
spawn ssh root@172.25.254.$IP_NUM hostname
expect {
yes/no { send "yes\r";exp_continue }
password { send "redhat\r" }
}
expect eof
EOF
}
for IP_NUM in {226..227}
do
ping -c1 -w1 172.25.254.$IP_NUM &> /dev/null && {
Host_Name=`Auto_Connect | grep -E "authenticity|fingerprint|connecting|password|spawn|Warning" -v`
}
echo "$Host_Name 172.25.254.$IP_NUM " | sed 's/\r//g' // Reemplazar / r del texto completo con vacío.
Done
#!/bin/bash
Auto_Discuz()
{
/usr/bin/expect << EOF
set timeout 30
spawn ssh root@$1
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "westos\r" }
}
expect "]#" { send "yum install httpd -y\r" }
expect "]#" { send "yum install mariadb-server -y\r"}
expect "]#" { send "yum install php-mysql.x86_64 -y\r"}
expect "]#" { send "systemctl start httpd\r" }
expect "]#" { send "systemctl start mariadb\r" }
expect eof
EOF
}
Auto_Connect()
{
/usr/bin/expect << EOF
set timeout 30
spawn ssh root@$1
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "westos\r" }
}
expect "]#" { send "cd /var/www/html/\r" }
expect "]#" { send "unzip /var/www/html/Discuz_X3.2_SC_UTF8.zip >> /dev/null \r" }
expect "]#" { send "chmod 777 /var/www/html/upload/ -R\r" }
expect "]#" { send "systemctl restart httpd\r" }
expect eof
EOF
}
Auto_Httpd()
{
/usr/bin/expect << EOF
set timeout 30
spawn ssh root@$1
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "westos\r" }
}
expect "]#" { send "sed "/^Listen/cListen 8080" -i /etc/httpd/conf/httpd.conf\r" }
expect "]#" { send "yum restart httpd -y\r" }
expect eof
EOF
}
yum install expect -y
Auto_Discuz $1
scp /home/kiosk/Downloads/Discuz_X3.2_SC_UTF8.zip root@$1:/var/www/html
Auto_Connect $1
firefox -new-tab $1/upload/install
Auto_Httpd $1
Esta entrada fue publicada en
Unix - Linux. Guarda el
enlace permanente.