Estaba haciendo algunas talachas en la shell y me encontré con la necesidad de usar el último argumento de mi último comando ejecutado de manera frecuente. Así que un clavadín a las redes sociales y la respuesta la podrán encontrar por acá en developerworks.
Using the last argument from your last command and some other combinations
Mostrando las entradas con la etiqueta ksh. Mostrar todas las entradas
History grep
Ah, una funcioncita más que le agregué a .bashrc para buscar en la bitácora de comandos ejecutados.
Le nombré hgrep por su equivalente de history grep.
Encuentran el detalle por acá:Handy bash functions : history grep
Le nombré hgrep por su equivalente de history grep.
Encuentran el detalle por acá:Handy bash functions : history grep
Negando un listado (CLI)
Sé que hay otros modos de hacerlo, sugerencias son bien aceptadas.
List negation en developerworks
Fuente
List negation en developerworks
Fuente
ssh dentro de ciclos
Agregue un -n después de ssh para evitar que el exit rompa con la ejecución del bucle.
Solo deja 10 días de logs
Aún se le pueden hacer mas cosas.
http://pastebin.ca/681456
#!/usr/bin/ksh
###############################################################################
# Script: hkeeping.sh
# Version 0.01
# Shell: !/usr/bin/ksh
# Platform: AIX Systems
# Description: Delete directories and keeps only the ten newer ones.
# Creator: Emerson Posadas
# Date: Jul 27th, 2007
###############################################################################
###############################################################################
# Change history:
# 07/27/2007.- First script.
###############################################################################
#Get the GEO from the command line and convert the string to lowercase
GEO=$(print $1 | tr [A-Z] [a-z])
#Number of log files to keep
LIMIT=20
#GEO is mandatory to execute
if [ "${GEO}" = "" ]
then
echo "Geo needed to run this script"
echo "Correct syntax is hkeeping.sh"
exit 1
else
if [[ $GEO != @(emea1|emea2|la|na|ap|mmlc) ]]
then
echo "Please use a valid geo (emea1, emea2, ap, na, la, mmlc)"
else
#Count the total of geo directories matched
count() {
TOTAL=$(ls -rt | grep $GEO | wc -l | cut -c 7-8)
#TOTAL=$(ls -rt | grep $GEO | wc -l | awk '{print $1}')
}
cd /foo/bar
count
#If there is more than $LIMIT directories then delete the older ones
if [ $TOTAL -gt $LIMIT ]; then
#Number of iterations (directory deletions to do)
let ITER=$TOTAL-$LIMIT
while [[ $ITER -gt 0 ]] ; do
#Select the older element
ELEMENT=$(ls -lrt | grep $GEO | awk '{print $9}' | head -1)
echo "$ELEMENT deleted"
#Delete the older element
ls -lrt | grep $GEO | awk '{print $9}' | head -1 | xargs rm -fr
let ITER=$ITER-1
done
else
echo "Cannot delete more log files"
exit 1
fi
fi
fi
http://pastebin.ca/681456
#!/usr/bin/ksh
###############################################################################
# Script: hkeeping.sh
# Version 0.01
# Shell: !/usr/bin/ksh
# Platform: AIX Systems
# Description: Delete directories and keeps only the ten newer ones.
# Creator: Emerson Posadas
# Date: Jul 27th, 2007
###############################################################################
###############################################################################
# Change history:
# 07/27/2007.- First script.
###############################################################################
#Get the GEO from the command line and convert the string to lowercase
GEO=$(print $1 | tr [A-Z] [a-z])
#Number of log files to keep
LIMIT=20
#GEO is mandatory to execute
if [ "${GEO}" = "" ]
then
echo "Geo needed to run this script"
echo "Correct syntax is hkeeping.sh
exit 1
else
if [[ $GEO != @(emea1|emea2|la|na|ap|mmlc) ]]
then
echo "Please use a valid geo (emea1, emea2, ap, na, la, mmlc)"
else
#Count the total of geo directories matched
count() {
TOTAL=$(ls -rt | grep $GEO | wc -l | cut -c 7-8)
#TOTAL=$(ls -rt | grep $GEO | wc -l | awk '{print $1}')
}
cd /foo/bar
count
#If there is more than $LIMIT directories then delete the older ones
if [ $TOTAL -gt $LIMIT ]; then
#Number of iterations (directory deletions to do)
let ITER=$TOTAL-$LIMIT
while [[ $ITER -gt 0 ]] ; do
#Select the older element
ELEMENT=$(ls -lrt | grep $GEO | awk '{print $9}' | head -1)
echo "$ELEMENT deleted"
#Delete the older element
ls -lrt | grep $GEO | awk '{print $9}' | head -1 | xargs rm -fr
let ITER=$ITER-1
done
else
echo "Cannot delete more log files"
exit 1
fi
fi
fi
Script
Chafa, falta pulirlo, organizarlo y mejorarlo, ahorita está muy mexicano.
count() {
TOTAL=$(ls -rt | grep $GEO | wc -l | cut -c 7-8)
}
GEO=$1
cd /web/server_root/tmp/services/epricer/rdx/temp
count
if [ $TOTAL -gt 10 ]; then
let ITER=$TOTAL-10
echo "ITER INICIO = $ITER"
while [[ $ITER -gt 0 ]] ; do
echo $ITER
ls -lrt | grep emea1 | awk '{print $9}' | head -1 | xargs rm -fr
let ITER=$ITER-1
done
echo "ITER FINAL = $ITER"
echo "Total mayor que 10 ($TOTAL)"
else
echo "Total menor o igual a 10 ($TOTAL)"
fi
count() {
TOTAL=$(ls -rt | grep $GEO | wc -l | cut -c 7-8)
}
GEO=$1
cd /web/server_root/tmp/services/epricer/rdx/temp
count
if [ $TOTAL -gt 10 ]; then
let ITER=$TOTAL-10
echo "ITER INICIO = $ITER"
while [[ $ITER -gt 0 ]] ; do
echo $ITER
ls -lrt | grep emea1 | awk '{print $9}' | head -1 | xargs rm -fr
let ITER=$ITER-1
done
echo "ITER FINAL = $ITER"
echo "Total mayor que 10 ($TOTAL)"
else
echo "Total menor o igual a 10 ($TOTAL)"
fi
Suscribirse a:
Entradas (Atom)