Mostrando entradas con la etiqueta script. Mostrar todas las entradas
Mostrando entradas con la etiqueta script. Mostrar todas las entradas

20120321

Script para generar conjuntos de archivos - Script to generate sets of files

Después de un tiempo sin postear, he vuelto, al menos por ahora!!
Estos días he necesitado varios conjuntos de archivos para realizar pruebas de rendimiento, y para generar estos, he creado el siguiente script, que ahora comparto con vosotros.
Espero que os sea de utilidad.


After some time without posting, I'm back!
This days I needed some sets of files to make some performance tests. To generate this files I wrote the following script that I'm going to share with all of you.
I hope you find it useful.

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

#!/bin/bash
#
FILES_PATH="$PWD/files"                    # path to create de files
declare -i DIR_NUM=13                      # num. of dirs to create
declare -i FILE_NUM=1000                   # num. of files to create
declare -i FILE_MIN_SIZE=10                # in kB
declare -i FILE_MAX_SIZE=200               # in kB
declare -i FILE_SIZE=$FILE_MAX_SIZE

if [ ! -d $FILES_PATH ]; then
  mkdir $FILES_PATH
fi

for (( dir=1;dir<=$DIR_NUM;dir++ )); do
  mkdir "$FILES_PATH/dir_$dir"
  for (( file=1;file<=$FILE_NUM;file++ )); do
    FILE_SIZE=$(($RANDOM%(FILE_MAX_SIZE)-$FILE_MIN_SIZE))+$FILE_MIN_SIZE
    FILE_SIZE=$(($RANDOM%FILE_MAX_SIZE))
    FILE_SIZE=$FILE_SIZE+$FILE_MIN_SIZE
    dd count=$FILE_SIZE if=/dev/zero of="$FILES_PATH/dir_$dir/file_$file" >> /dev/null 2>&1
  done
done

20111125

Scripting: copiando datos a la red - Scripting: backup your data to the network

Tengo dicho una y mil veces a los $lusers de mi organización, que guarden en la red aquellos emails que puedan echar de menos en caso de pérdida. Sí, lo śe, pero me niego a hacer backup de toda la basura que envían y reciben. No somos Google ni mucho menos, así que ¿para que hacer copia de tal cantidad de mie_da?
La cosa es que pedirles que hagan copia de sus favoritos y su libreta de direcciones quizás sea demasiado, así que, teniendo en cuenta que principalmente usan Internet Explorer y Mozilla Firefox para guarri-navegar por la red de redes, y Mozilla Thunderbird como cliente de correo corporativo, he añadido el siguiente script al de logon de Active Directory, con el que copio los archivos a su unidad de usuario de red:
@ECHO OFF
SET BACKUP_DIR=u:\backup
REM Creación de directorios
IF NOT EXIST %BACKUP_DIR% MKDIR %BACKUP_DIR%
IF NOT EXIST %BACKUP_DIR%\ie mkdir %BACKUP_DIR%\ie
IF NOT EXIST %BACKUP_DIR%\ffox mkdir %BACKUP_DIR%\ffox
IF NOT EXIST %BACKUP_DIR%\tbird mkdir %BACKUP_DIR%\tbird
ATTRIB +H %BACKUP_DIR%

REM Backup favoritos de IE
xcopy /q /e /y "%USERPROFILE%\Favoritos" %BACKUP_DIR%\ie\ > NUL
REM Backup marcadores de Firefox
FOR /f "tokens=1 delims=(=" %%G IN ('dir /s/b/a  "%APPDATA%\Mozilla\*.sqlite"') DO copy /y "%%G" %BACKUP_DIR%\ffox > NUL
REM Backup libretas de direcciones de Thunderbird
FOR /f "tokens=1 delims=(=" %%G IN ('dir /s/b/a  "%APPDATA%\*.mab"') DO copy "%%G" %BACKUP_DIR%\tbird > NUL

Por si a alguno le sirviese de ayuda!


"Our SAN will never store the rubbish you store in your mail boxes". I've said that once and again to the $lusers of my organization. If once a year the recieve an important mail they have to save it on the network where the backup proccess will protect them from themselves, but to asking them to save their bookmarks and addressbooks is too much! 
Internet Explorer y Mozilla Firefox are the clients the use to browse the web and Mozilla Thunderbird is the mail client we use so I've added the folloging lines to the Active Directory logon script:
@ECHO OFF
SET BACKUP_DIR=u:\backup
REM Making the backup directories
IF NOT EXIST %BACKUP_DIR% MKDIR %BACKUP_DIR%
IF NOT EXIST %BACKUP_DIR%\ie mkdir %BACKUP_DIR%\ie
IF NOT EXIST %BACKUP_DIR%\ffox mkdir %BACKUP_DIR%\ffox
IF NOT EXIST %BACKUP_DIR%\tbird mkdir %BACKUP_DIR%\tbird
ATTRIB +H %BACKUP_DIR%

REM Backup IE favorites
xcopy /q /e /y "%USERPROFILE%\Favorites" %BACKUP_DIR%\ie\ > NUL
REM Backup Firefox bookmarks
FOR /f "tokens=1 delims=(=" %%G IN ('dir /s/b/a  "%APPDATA%\Mozilla\*.sqlite"') DO copy /y "%%G" %BACKUP_DIR%\ffox > NUL
REM Backup Thunderbird addressbook
FOR /f "tokens=1 delims=(=" %%G IN ('dir /s/b/a  "%APPDATA%\*.mab"') DO copy "%%G" %BACKUP_DIR%\tbird > NUL

I hope it helps you!

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20110916

Habilitar logs de cron en Ubuntu con rsyslog - Enable cron logs in Ubuntu with rsyslog

Para poder registrar los resultados de nuestras tareas programadas de cron en Ubuntu (10.04 LTS en mi caso) con rsyslog debemos hacer lo siguiente:
 - Editamos el fichero /etc/rsyslog.d/50-default.conf
 - Descomentamos esta línea: 
     cron.*                          /var/log/cron.log
 - Podemos cambiar el nivel de logeo (debug, info, etc)
 - Reiniciamos el servicio:
     sudo reload rsyslog
 - Y a funcionar, ya sólo nos falta comprobarlo con sudo tail -f /var/log/cron.log 

En mi caso, ya estaba configurada la rotación de este log dentro del fichero /etc/logrotate.d/rsyslog así que no tengo que preocuparme de que crezca sin control.

To record the result of our scheduled cron task on Ubuntu (10.04 LTS in my case) with rsyslog, we have to:
 - Edit the file /etc/rsyslog.d/50-default.conf
 - Uncomment this line:
     cron.*                          /var/log/cron.log
 - We also can change the warning level (debug, info, etc)
 - Restart the service:
     sudo reload rsyslog
 - And that's all. We can test it with: sudo tail -f /var/log/cron.log 

In my case, the system was already configured to rotate this log on the file: /etc/logrotate.d/rsyslog so we don't have to take care about it grows out of control.

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.

20110829

Renombrado de ficheros por lotes - Batch renaming files

Me ha vuelto a pasar!!! He ejecutado el siguiente script desde la línea de comandos para el renombrado de archivos en lotes:
for i in `ls`; do mv $i BKP_$i; done

mediante el cual, añado el prefijo BKP_ a todos los ficheros del directorio de trabajo, peeeeero lo he hecho en la ruta equivocada!!! Así que tengo un montón de archivos a los que les he añadido un prefijo que tengo que quitar.
La solución (o una de ellas) me la ofrece el comando cut. Con él, podemos seleccionar de una cadena de texto, los caracteres que queramos mostrar o quitar (--complement).
El nuevo script para reparar el entuerto sería:
for i in `ls`; do mv $i `echo $i| cut -c 1-4 --complement`; done

Y problema resuelto.

Ups, I did it again!!! I have run the following script from the command line to rename some files:
for i in `ls`; do mv $i BKP_$i; done

to add the prefix BKP_ to all files in the current directory, but I did it on the wrong path!!! So I have lots of files with a prefix to remove.
The solution (or at least, one of them) is to use the command cut. We can use it to choose some characters from a string.
The script to repair my mistake and remove (--complement) this prefix is:
for i in `ls`; do mv $i `echo $i| cut -c 1-4 --complement`; done

And its done!!!

PS. I know, I know. My English is not good enought but, the more you help me, the more I learn.