Diapositivas y scripts de taller 1

This commit is contained in:
Pablo Ferreiro 2024-04-17 21:50:31 +02:00
parent 71d62165fa
commit ce5c8f2c35
Signed by: ferreiro
GPG Key ID: 41FBCE65B779FA24
14 changed files with 135 additions and 0 deletions

BIN
taller1/TallerBash01.odp Normal file

Binary file not shown.

3
taller1/scripts/01.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
# Hola, soy un comentario
echo Hello World

3
taller1/scripts/02.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
greeting=Pablo
echo "Hello $greeting"

5
taller1/scripts/03.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
greeting=Pablo
echo 'Hello $greeting'
echo "Hello $greeting"
echo "Hello $(whoami)"

3
taller1/scripts/04.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
greeting=$1
echo "Hello $greeting"

5
taller1/scripts/05.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
output1=$((2+2))
output2=$(($output1 - 2))
echo $output1
echo $output2

8
taller1/scripts/06.sh Normal file
View File

@ -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"

12
taller1/scripts/07.sh Executable file
View File

@ -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"

20
taller1/scripts/08.sh Executable file
View File

@ -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"

10
taller1/scripts/09.sh Executable file
View File

@ -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"

13
taller1/scripts/11.sh Executable file
View File

@ -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"

6
taller1/scripts/12.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
letters='a b c d e f g h'
for letter in $letters; do
echo $letter
done

View File

@ -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!"

View File

@ -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