nunacho Posted September 22, 2012 Report Share Posted September 22, 2012 (edited) Este es un script que hice para descargar la documentación de Red Hat Enterprise Linux tanto en formato PDF como ePub en sus versiones de 4, 5 y 6 de RHEL.La idea del script es no tener que descargar la documentación a mano haciendo clic en cada uno de los enlaces de la pagina de Red Hat.Su uso es bien sencillo con -v le especificamos la versión de RHEL (4, 5, 6).Con -p le especificamos que descargue la documentación en PDF.Con -e le especificamos que descargue la documentación en ePub.Con -h mostramos la ayuda. Les dejo el código del script #!/bin/bash BASE_URL='https://access.redhat.com' DOCS_URL="$BASE_URL/knowledge/docs/Red_Hat_Enterprise_Linux/?locale=en-US" epub_file= pdf_file= help() { local progname=$(basename $0) echo "Uso: $progname <-v VERSION> [-p] [-e] [-h]" exit 0 } die() { echo "$1" >&2 exit 1 } get_pdf_url() { local line="$1" pdf_file= if [[ $line =~ \.pdf ]]; then line=${line%\">pdf*} line=${line##*href=\"} pdf_file=${BASE_URL}${line} fi } get_epub_url() { local line="$1" epub_file= if [[ $line =~ \.epub ]]; then line=${line%\">epub*} line=${line##*href=\"} epub_file=${BASE_URL}${line} fi } download_file() { local file="$1" wget -q "$file" 2>/dev/null || echo "$file: error al descargar." >&2 } (( $# == 0 )) && help while getopts v:eph opt; do case $opt in v) version=$OPTARG ;; e) epub=y ;; p) pdf=y ;; h) help ;; *) die "Opcion no valida." ;; esac done [[ -z $version ]] && help [[ -z $epub && -z $pdf ]] && pdf=y [[ ! ($version =~ ^(4|5|6)$) ]] && die "$version: no valida." while read line; do if [[ $line =~ /$version/ ]]; then if [[ -n $epub ]]; then get_epub_url "$line" if [[ -n $epub_file ]]; then epub=${epub_file##*/} echo "Bajando: $epub" download_file $epub_file fi fi if [[ -n $pdf ]]; then get_pdf_url "$line" if [[ -n $pdf_file ]]; then pdf=${pdf_file##*/} echo "Bajando: $pdf" download_file $pdf_file fi fi fi done < <(curl -s "$DOCS_URL") Edited October 7, 2012 by nunacho Link to comment Share on other sites More sharing options...
nkdos Posted September 25, 2012 Report Share Posted September 25, 2012 Excelente! existe algún problema en compartir tu código? obviamente siempre indicando que este es tuyo? Link to comment Share on other sites More sharing options...
nunacho Posted September 25, 2012 Author Report Share Posted September 25, 2012 No hay problema. Link to comment Share on other sites More sharing options...
pinox¹ Posted October 1, 2012 Report Share Posted October 1, 2012 Excelente, gracias Link to comment Share on other sites More sharing options...
kresse Posted December 27, 2012 Report Share Posted December 27, 2012 Bastante bueno amigo, gracias. Link to comment Share on other sites More sharing options...
xtomsawyer Posted May 10, 2013 Report Share Posted May 10, 2013 Se agradece estimado! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now