elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [Bash] Mis scripts
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Bash] Mis scripts  (Leído 5,699 veces)
leogtz
. . .. ... ..... ........ ............. .....................
Colaborador
***
Desconectado Desconectado

Mensajes: 3.069


/^$/


Ver Perfil WWW
[Bash] Mis scripts
« en: 18 Abril 2011, 02:50 am »

Eston son algunos de los scripts que uso a diario, bueno, no a diarion, pero son de uso personal, los dejo para ver si a alguien le sirven, que los prueben y vean qué modificaciones se les puede hacer.

space
Código
  1. #!/bin/bash
  2. # Leo Gutiérrez R. leorocko13@hotmail.com
  3. # Script que comprime todos los archivos en el directorio actual.
  4. # Util para hacer espacio en dispositivos extraíbles.
  5. # Uso personal.
  6. find . -type f | while read file
  7. do
  8. extension=`echo "${file}" | awk -F . '{print $NF}'`;
  9. echo -e "$extension" | grep -ie "^\(rar\|Z\|7z\|bz2\|zip\|gz\)$" &> /dev/null && continue;
  10. rar a "${file}.rar" "$file" -y -df
  11. done
  12.  

usb

Código
  1. #!/bin/bash
  2. # Leo Gutiérrez R.
  3. # Script para navegar por sobre los dispositivos USB en el sistema.
  4. # Uso personal.
  5. select archivo in `ls -1 /media/ | grep -v "^cd$" | grep -v "^dvd$" | grep -v "^fl$" | grep -v "^ubuntu$" | grep -v "^windows$"`
  6. do
  7. if [ -n "$archivo" ]
  8. then
  9. cd /media/"$archivo"
  10. break;
  11. else
  12. echo -e "Error eligiendo dispositivo";
  13. exit 1;
  14. fi
  15. done

cdprompt

Código:
[leo@archero ~]$ cdprompt
1) amsn_received/       9) drivers_tia_de_valeria/  17) Musica/        25) Software/
2) bash/      10) escuela/   18) NetBeansProjects/        26) Textos/
3) cpps/      11) guitar/   19) perl/        27) visual/
4) c_proyects/      12) Imagenes/   20) projects/        28) yare/
5) Descargas/      13) java/   21) proyectos/        29) SALIR
6) Desktop/      14) linux/   22) python/
7) Downloads/      15) maiesecuele/   23) respaldo_usb_papa/
8) drivers_cesar/      16) *****/   24) revistas/
>

Código
  1. #!/bin/bash -
  2. #===============================================================================
  3. #
  4. #          FILE:  cdprompt.sh
  5. #
  6. #         USAGE:  ./cdprompt.sh
  7. #
  8. #   DESCRIPTION:  Cambio de directorios interactivamente.
  9. #
  10. #       OPTIONS:  ---
  11. #  REQUIREMENTS:  ---
  12. #          BUGS:  ---
  13. #         NOTES:  ---
  14. #        AUTHOR: |Leo Gutiérrez R.| (), |leorocko13@hotmail|
  15. #       COMPANY:
  16. #       CREATED: 02/26/2011 01:51:28 AM CST
  17. #      REVISION:  ---
  18. #===============================================================================
  19.  
  20. select directorio in */ "SALIR"
  21. do
  22. if [ "$directorio" = "SALIR" ]
  23. then
  24. break;
  25. elif [[ -n "$directorio" ]]
  26. then
  27. cd "$directorio"
  28. break;
  29. else
  30. echo -e "\aError de opción.";
  31. break;
  32. fi
  33. done
  34.  

rmsecure
Script de borrado interactivo, muestra qué archivos eliminar en el directorio local:

Código:
1) C_Plus_Plus_Varios_Libros.rar  5) PKGBUILD
2) Diagrama_EDGAR.mwb   6) src
3) pacman-3.5.1   7) SALIR
4) pacman-3.5.1.tar.gz
>

Código
  1. #!/bin/bash
  2. # Script de borrado interactivo.
  3. # Leo Gutiérrez Ramírez. leorocko13@hotmail.com
  4.  
  5. function rmsecure()
  6. {
  7.  
  8. select archivos in * "SALIR"
  9. do
  10. if [ "${archivos}" = "SALIR" ]
  11. then
  12.  
  13. exit 0;
  14.  
  15. elif [[ -n "${archivos}" ]]
  16. then
  17.  
  18. sudo rm -rvi "${archivos}" || {
  19. echo -e "Error borrando archivo : ${archivos}";
  20. exit 0;
  21. }
  22.  
  23. clear;
  24. rmsecure;
  25.  
  26. else
  27.  
  28. echo -e "Error eligiendo archivo.";
  29.  
  30. fi
  31.  
  32. done
  33. }
  34.  
  35. clear;
  36. rmsecure;
  37.  

unins.sh
Script para ArchLinux, muestra los paquetes para elegir cuál desinstalar, todo a través de una pequeña interfaz.


Código
  1. #!/bin/bash
  2.  
  3. [ ${UID} != 0 ] && {
  4. echo -e "Se requieren privilegios de Root";
  5. exit 1;
  6. }
  7.  
  8. pacman -Qei | sed -n "s/^Name.*\:\s\(.*\)/\1/p" > nombres.txt
  9. pacman -Qei | sed -n "s/^Version.*\:\s\(.*\)/\1/p" > versiones.txt
  10.  
  11. Xdialog --title "Desinstalar paquetes" --menu "Elija su paquete:" 24 51 6 $(paste nombres.txt versiones.txt) 2> /tmp/menu.tmp.$$
  12.  
  13. retval=$?
  14. choice=`cat /tmp/menu.tmp.$$`
  15. rm -f nombres.txt
  16. rm -f versiones.txt
  17. rm -f /tmp/menu.tmp.$$
  18.  
  19. case "$retval" in
  20.  1)
  21.    exit 0;
  22.    ;;
  23.  255)
  24.    exit 0;
  25.    ;;
  26. esac
  27.  
  28. yes | pacman -R "${choice}" && {
  29. Xdialog --title "Desinatalar paquetes" --msgbox "${choice} desinstalado con éxito." 10 100
  30. } || {
  31. Xdialog --title "Desinatalar paquetes" --msgbox "${choice} no se pudo desinstalar." 10 100
  32. exit 1;
  33. }
  34.  
  35. exit 0;
  36.  

sc

Código
  1. #!/bin/bash
  2. # Leo Gutiérrez R.
  3. # Script para comprobar si un proceso está corriendo.
  4.  
  5. [ $# -ne 1 ] && {
  6. cat <<EOF
  7.  
  8. `basename $0` service
  9.  
  10. EOF
  11. exit 1;
  12. }
  13.  
  14. [ -f "/var/run/daemons/$1" ] && {
  15. echo -e "\"$1\" running.";
  16. } || {
  17. echo -e "\"$1\" stopped.";
  18. }
  19. exit 0;
  20.  

modins


Código
  1. #!/bin/bash
  2. # Script para instalar paquetes en Perl.
  3.  
  4. function getch()
  5. {
  6. OLD_STTY=`stty -g`
  7. stty cbreak -echo
  8. look=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  9. stty $OLD_STTY
  10. }
  11.  
  12. function installModule()
  13. {
  14. sudo perl Makefile.PL
  15. sudo make
  16. sudo make test
  17. sudo make install
  18. }
  19.  
  20. function modins()
  21. {
  22. archivo=
  23. select archivo in *.tar.gz "SALIR"
  24. do
  25. if [ "${archivo}" = "SALIR" ]
  26. then
  27.  
  28. exit 0;
  29.  
  30. elif [[ -n "${archivo}" ]]
  31. then
  32.  
  33. echo -e "Elegiste : ${archivo}";
  34. tar zxvf "${archivo}" &> /dev/null || {
  35. echo -e "Error descomprimiendo [ ${archivo} ]";
  36. exit 1;
  37. }
  38.  
  39. cd "${archivo%\.tar.gz}" 2> /dev/null || {
  40. echo -e "\aError abriendo directorio ${archivo%%.*}";
  41. exit 1;
  42. }
  43.  
  44. installModule;
  45.  
  46. echo -e "\E[31;47mMódulo instalado. Presione una tecla para continuar.";
  47. tput sgr0;
  48. getch;
  49. break;
  50.  
  51. else
  52.  
  53. echo -e "Error eligiendo archivo.";
  54. exit 0;
  55.  
  56. fi
  57.  
  58. done
  59. }
  60.  
  61. modins;
  62. exit 0;
  63.  

Saludos.


En línea

Código
  1. (( 1 / 0 )) &> /dev/null || {
  2. echo -e "stderrrrrrrrrrrrrrrrrrr";
  3. }
  4.  
http://leonardogtzr.wordpress.com/
leogutierrezramirez@gmail.com
El_Java

Desconectado Desconectado

Mensajes: 144



Ver Perfil WWW
Re: [Bash] Mis scripts
« Respuesta #1 en: 18 Abril 2011, 11:25 am »

Muy buen aporte, si señor!
Te pongo aqui los que yo uso, solo son 2, pero espero que ayuden a alguien :P

Script cambiar de fondo pantalla cada 15 minutos
Código
  1. #!/bin/sh
  2.  
  3. #Script para cambiar de fondo de escritorio cada 10 minutos
  4.  
  5.  
  6. cd ~/Imagenes/Fondos\ pantalla/
  7.  
  8. while [ 1 ]; do
  9.  
  10. for aux in $(ls) ; do
  11. #echo "gconftool-2 --type string --set /desktop/gnome/background/picture_filename  ~/Imagenes/Fondos\ pantalla/$aux"
  12. sleep 15m
  13. gconftool-2 --type string --set /desktop/gnome/background/picture_filename  ~/Imagenes/Fondos\ pantalla/$aux
  14. done
  15.  
  16. done
  17.  
  18. wait
  19.  
  20.  

Script para abrir JDownloader (Yo lo uso como aplicacion al inicio)
Código
  1. #!/bin/sh
  2.  
  3. #Cambiar por el directorio donde tengais el JDownloader.jar
  4.  
  5. echo "Ejecuntando JDownloader..."
  6. nohup java -jar /home/java/Escritorio/JDownloader/JDownloader.jar
  7.  
  8. & exit
  9.  

Además, uso otro script que me ejecuta un terminal en mitad de la pantalla transparente al iniciar sesión que queda bastante bien, si os interesa decidmelo xD
Os pongo una imagen:


Un saludo!


En línea

JuszR


Desconectado Desconectado

Mensajes: 2.866


Programming & RI


Ver Perfil
Re: [Bash] Mis scripts
« Respuesta #2 en: 18 Abril 2011, 12:23 pm »

Código
  1. #!/usr/bin/env bash
  2. # Script para extraer archivos
  3. # JuszR gentoo@rocks.net
  4. # GPL
  5.  
  6.  
  7. if [ "$#" -lt 1 ]; then
  8. echo -ne "\n\tUso:"
  9. echo -e "\n\t$(basename $0) <archivo> (.tar, .rar, .bz2...)"
  10. echo ""
  11. exit 1
  12. fi
  13.  
  14. if [ -f $1 ] ; then
  15.        case $1 in
  16.            *.tar.bz2 | *.tbz2)   tar xvjf $1        ;;
  17.            *.tar.gz)    tar xvzf $1     ;;
  18.            *.bz2)       bunzip2 $1       ;;
  19.            *.rar)       unrar x $1     ;;
  20.            *.gz)        gunzip $1     ;;
  21.            *.tar)       tar xvf $1        ;;
  22.            *.tgz)       tar xvzf $1       ;;
  23.            *.zip)       unzip $1     ;;
  24.            *.Z)         uncompress $1  ;;
  25.            *.7z)        7z x $1    ;;
  26.            *)           echo "'$1' no puede ser extraido" ;;
  27. esac
  28.    else
  29.        echo "'$1' no es un archivo valido"
  30.    fi
  31.  

Código
  1. #!/usr/bin/env bash
  2. # Colores en bash
  3. # JuszR gentoo@rocks.net
  4. # GPL
  5.  
  6. # Variables
  7. txtund=$(tput sgr 0 1)          # Subrayado
  8. txtbld=$(tput bold)             # Negrita
  9. bldred=${txtbld}$(tput setaf 1) #  rojo
  10. bldblu=${txtbld}$(tput setaf 4) #  azul
  11. bldwht=${txtbld}$(tput setaf 7) #  blanco
  12. txtrst=$(tput sgr0)             # Resetear
  13. info=${bldwht}*${txtrst}        # Feedback
  14. pass=${bldblu}*${txtrst}
  15. warn=${bldred}!${txtrst}
  16.  
  17. echo
  18. echo -e "$(tput bold) norm  negr  subr   tput-colores$(tput sgr0)"
  19.  
  20. for i in $(seq 1 7); do
  21.  echo " $(tput setaf $i)Texto$(tput sgr0) $(tput bold)$(tput setaf $i)Texto$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Texto$(tput sgr0)  \$(tput setaf $i)"
  22. done
  23.  
  24. echo ' Negrita            $(tput bold)'
  25. echo ' Subrayado       $(tput sgr 0 1)'
« Última modificación: 18 Abril 2011, 12:28 pm por JuszR » En línea

- No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes. [Herbert Mayer]
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Scripts de ASP
Desarrollo Web
Cobac 9 9,941 Último mensaje 10 Julio 2010, 23:02 pm
por alkonweb
Scripts en BASH
Ejercicios
-EvilBuffer- 7 24,558 Último mensaje 23 Febrero 2010, 13:45 pm
por ^Tifa^
[Bash script] equivalente de goto en batch para bash (SOLUCIONADO)
Scripting
moikano→@ 4 16,054 Último mensaje 4 Noviembre 2010, 15:58 pm
por moikano→@
[Ayuda] Ayuda con este bot... | Scripts BASH y PHP
Scripting
skaryllex 2 2,426 Último mensaje 26 Mayo 2012, 15:04 pm
por skaryllex
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines