diff --git a/taller1/TallerBash01.odp b/taller1/TallerBash01.odp new file mode 100644 index 0000000..b28bcc9 Binary files /dev/null and b/taller1/TallerBash01.odp differ diff --git a/taller1/scripts/01.sh b/taller1/scripts/01.sh new file mode 100755 index 0000000..89176e7 --- /dev/null +++ b/taller1/scripts/01.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Hola, soy un comentario +echo Hello World diff --git a/taller1/scripts/02.sh b/taller1/scripts/02.sh new file mode 100755 index 0000000..5011660 --- /dev/null +++ b/taller1/scripts/02.sh @@ -0,0 +1,3 @@ +#!/bin/bash +greeting=Pablo +echo "Hello $greeting" diff --git a/taller1/scripts/03.sh b/taller1/scripts/03.sh new file mode 100755 index 0000000..61e64ab --- /dev/null +++ b/taller1/scripts/03.sh @@ -0,0 +1,5 @@ +#!/bin/bash +greeting=Pablo +echo 'Hello $greeting' +echo "Hello $greeting" +echo "Hello $(whoami)" diff --git a/taller1/scripts/04.sh b/taller1/scripts/04.sh new file mode 100755 index 0000000..2c7cbe4 --- /dev/null +++ b/taller1/scripts/04.sh @@ -0,0 +1,3 @@ +#!/bin/bash +greeting=$1 +echo "Hello $greeting" diff --git a/taller1/scripts/05.sh b/taller1/scripts/05.sh new file mode 100755 index 0000000..9560897 --- /dev/null +++ b/taller1/scripts/05.sh @@ -0,0 +1,5 @@ +#!/bin/bash +output1=$((2+2)) +output2=$(($output1 - 2)) +echo $output1 +echo $output2 diff --git a/taller1/scripts/06.sh b/taller1/scripts/06.sh new file mode 100644 index 0000000..9fb2128 --- /dev/null +++ b/taller1/scripts/06.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# ¡Muy importante seguir los espacios en el if! +if [[ -z $1 ]]; then + echo "No hay parámetro" + exit 1 # salir de script, 1 = error +fi +greeting=$1 +echo "Hello $greeting" diff --git a/taller1/scripts/07.sh b/taller1/scripts/07.sh new file mode 100755 index 0000000..4c54952 --- /dev/null +++ b/taller1/scripts/07.sh @@ -0,0 +1,12 @@ +#!/bin/bash +if [[ -z $1 ]]; then + echo "No hay parámetro" + exit 1 +elif [[ $1 == Pepe ]]; then + echo "Me caes mal" + exit 1 +else + echo "Parámetro válido" +fi +greeting=$1 +echo "Hello $greeting" diff --git a/taller1/scripts/08.sh b/taller1/scripts/08.sh new file mode 100755 index 0000000..c0b9bee --- /dev/null +++ b/taller1/scripts/08.sh @@ -0,0 +1,20 @@ +#!/bin/bash +case $1 in + Pablo) + echo "Mejor nombre de todos" + ;; + Pepe) + echo "Fuck Pepe" + exit 1 + ;; + "") + echo "No hay parámetro" + exit 1 + ;; + *) + echo "Parámetro válido" + ;; +esac + +greeting=$1 +echo "Hello $greeting" diff --git a/taller1/scripts/09.sh b/taller1/scripts/09.sh new file mode 100755 index 0000000..0145cdb --- /dev/null +++ b/taller1/scripts/09.sh @@ -0,0 +1,10 @@ +#!/bin/bash +i=0 +while [[ $i -lt 15 ]] +do + echo "Soy el ciclo número $i" + ((i++)) +done + +echo "He terminado el ciclo" + diff --git a/taller1/scripts/11.sh b/taller1/scripts/11.sh new file mode 100755 index 0000000..ed51a95 --- /dev/null +++ b/taller1/scripts/11.sh @@ -0,0 +1,13 @@ +#!/bin/bash +for i in {0..14} +do + echo "Soy el ciclo número $i" +done +echo "He terminado el primer for" + +# o también +for ((i=0;i<15;i++)) +do + echo "Soy el ciclo número $i" +done +echo "He terminado el segundo for" diff --git a/taller1/scripts/12.sh b/taller1/scripts/12.sh new file mode 100755 index 0000000..9e736fc --- /dev/null +++ b/taller1/scripts/12.sh @@ -0,0 +1,6 @@ +#!/bin/bash +letters='a b c d e f g h' + +for letter in $letters; do + echo $letter +done diff --git a/taller1/scripts/examples/backup.sh b/taller1/scripts/examples/backup.sh new file mode 100755 index 0000000..ff3f491 --- /dev/null +++ b/taller1/scripts/examples/backup.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -euo pipefail + +# -- CONSTANTES -- # +SRC_DIR="$HOME/Descargas" # Carpeta que va a ser copiada +DST_DIR="./Backups" # Destino +COMPRESS=true # Comprimir? + +# -- MAIN -- # +echo "Haciendo backup de $SRC_DIR" +echo # Línea en blanco + +now=$(date '+%d-%m-%Y') +folder=$(basename $SRC_DIR) # Conseguir carpeta/archivo más lejano a la raíz (/home/pablo -> pablo) +name="$folder-$now" + +# Crear carpeta de destino primero +mkdir -p $DST_DIR + +if $COMPRESS; then + # Comprimir en .tar.gz + tar -czvf "$DST_DIR/$name.tar.gz" -C $SRC_DIR . +else + # Copiar sin comprimir + mkdir -p "$DST_DIR/$name" # Crear directorio y "parents" + cp -R $SRC_DIR/* $DST_DIR/$name +fi + +echo "¡Terminado!" diff --git a/taller1/scripts/examples/status.sh b/taller1/scripts/examples/status.sh new file mode 100755 index 0000000..5f620af --- /dev/null +++ b/taller1/scripts/examples/status.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -euo pipefail + +# -- Constantes -- # +SERVER='https://openbokeron.uma.es' +TOKEN='TOKEN_AQUI' +CHATID='CHATID_AQUI' + +if curl -sSf $SERVER > /dev/null; then + echo "Server OK" +else + # Server down + curl -s -X POST \ + -H 'Content-Type: application/json' \ + -d "{\"chat_id\": \"$CHATID\", \"text\": \"$SERVER\", \"disable_notification\": false}" \ + https://api.telegram.org/bot$TOKEN/sendMessage > /dev/null + exit 1 +fi