Use it at your own discretion:
for app in `yarn application -list | awk '$6 == "ACCEPTED" { print $1 }'` ; do yarn application -kill "$app";done
Use it at your own discretion:
for app in `yarn application -list | awk '$6 == "ACCEPTED" { print $1 }'` ; do yarn application -kill "$app";done
I need this handy:
ruby -e "require 'yaml'; YAML.load_file('common.yaml')"
This is more Linux script related, but, sometimes we have a Hadoop (YARN) cluster running and we need to run a post install script or activity that executes on all the nodes in the cluster:
for i in `yarn node --list | cut -f 1 -d ':' | grep "ip"`; do ssh -i your-key.pem hadoop@$i 'hadoop fs -copyToLocal s3://mybucket/myscript.sh | chmod +x /home/hadoop/myscript.sh | /home/hadoop/myscript.sh' ; done
Note: we will need the your-key.pem file in the master node.
aws s3 ls s3://my-bucket/folder --recursive | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'
This procedure is to change Yarn configuration on a live cluster, propagate the changes to all the nodes and restart Yarn node manager.
Both commands are listing all the nodes on the cluster and then filtering the DNS name to execute a remote command via SSH. You can customize the sed filter depending on your own needs. This is filtering DNS names with Elastic Mapreduce format (ip-xx-xx-xx-xx.eu-west-1.compute.internal).
1. Upload the private key (.pem) file you are using to access the master node on the cluster. Change the private key permissions to at least 600 (i.e chmod 600 MyKeyName.pem)
2. Change /conf/yarn-site.xml and use a command like this to populate the change across the cluster.
yarn node -list|sed -n "s/^\(ip[^:]*\):.*/\1/p" | xargs -t -I{} -P10 scp -o StrictHostKeyChecking=no -i ~/MyKeyName.pem ~/conf/yarn-site.xml hadoop@{}://home/hadoop/conf/
3. This command will restart Yarn Node Resource manager on all the nodes.
yarn node -list|sed -n "s/^\(ip[^:]*\):.*/\1/p" | xargs -t -I{} -P10 ssh -o StrictHostKeyChecking=no -i ~/MyKeyName.pem hadoop@{} "yarn nodemanager stop"
Script para verificar la temperatura de los discos. De consulta frecuente para los servidores físicos. Puede modificarse facilmente para enviar un mail de alarma.
#!/bin/sh #hvivani. 20131128 #Verifica temperatura en discos de servidor. #Lista todos los dispositivos /dev/sd* #Requiere instalado smartctl (yum install smartmontools) for f in `fdisk -l |grep 'Disk /dev/sd' | cut -c6-13` do echo $f "(ºC):" smartctl -a $f |grep Temperature |cut -c81-90 done
Salida:
# ./chkTemperaturaDiscos.sh /dev/sda (ºC): 28 /dev/sdb (ºC): 26 /dev/sdd (ºC): 26 /dev/sdc (ºC): 26
Script para copia remota de respaldos o backups, con búsqueda filtrada por antiguedad.
#!/bin/sh #hvivani. 20130327 #copia archivos de respaldo a servidor remoto. for f in `find /backup/db/ -mtime -3 -name '*'` do scp $f hvivani@backup.hvivani.com:/backup/db/ done
Previamente debemos generar las claves para poder utilizar el comando scp sin necesidad de ingresar la clave.
#!/bin/bash #20130328. hvivani. graba backups en DVD. #Genera una imagen .iso con los archivos que coloquemos en ./grabar/ #Abre la grabadora, solicita el disco y graba el iso cd /backup/userdata/ echo echo Generando imagen a grabar del contenido del directorio grabar: echo if [ -f userdata.iso ]; then echo "ya existe archivo iso, lo borramos y creamos uno nuevo" rm userdata.iso fi genisoimage -allow-limited-size -o userdata.iso -J ./grabar/ echo echo Abriendo la lectora: eject echo while true do # (1) pregunta al usuario y lee respuesta en linea de comandos read -p "pusiste el disco virgen en la lectora ? " answer # (2) handle the input we were given case $answer in [sS]* ) eject -t wodim -v -eject dev=/dev/scd0 userdata.iso break;; [nN]* ) echo Donde queres que grabe ?? me voy !! exit;; * ) echo "Capo, ingresa solo S o N, no pongas boludeces.";; esac done echo Listo el pollo...
Supongamos que tenemos un archivo de texto kk.txt con las siguientes lineas:
linea1 linea2 linea3
y queremos agregarle un prefijo a cada línea de ese archivo.
Opción 1: con sed
[hvivani@test ~]$ sed -e 's/^/prefix/' kk.txt prefixlinea1 prefixlinea2 prefixlinea3
Opción 2: con nl
[hvivani@test ~]$ nl -s prefix kk.txt |cut -c7- prefixlinea1 prefixlinea2 prefixlinea3
Opción 3: con awk
[hvivani@test ~]$ awk '{print "prefix"$0}' kk.txt prefixlinea1 prefixlinea2 prefixlinea3
Opción 4: con shell script
#!/bin/bash prefix="prefijo" file="kk.txt" while read -r line do echo "${prefix}$line" done <$file > renombrado mv renombrado $file
Si queremos agregarle un sufijo o postfijo a cada línea de ese archivo:
[hvivani@test ~]$ sed -e 's/$/prefix/' kk.txt linea1prefix linea2prefix linea3prefix
Este es un simple script para obtener el uso de disco de los usuarios de nuestro servidor linux. Se basa en la utilización del comando du. Puede ser muy util cuando trabajamos con home’s centralizados.
#!/bin/sh #hvivani. 20120828 #imprime totales de uso de disco por usuario verificando cada home. cd /home/ for f in `ls` do du -sh ./$f done