Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - -Myx-

#31
Código (bash) [Seleccionar]
$ cat /etc/passwd | cut -f1,2 -d':'
$ cat /etc/passwd | awk -F': ' '{print $1":"$2;}'
# Y si lo que necesitas son mas de un caracter de delimitador cambia a -F' : '
#32
Scripting / Re: Script bash reiniciar ruter
20 Diciembre 2012, 20:26 PM
Copy-paste, pero se que me sirvio en otra oportunidad.

Código (bash) [Seleccionar]
#!/usr/bin/expect
set timeout 20
set ip [lindex $argv 0]
set port [lindex $argv 1]
set user [lindex $argv 2]
set password [lindex $argv 3]

spawn telnet $ip $port
expect "'^]'."
sleep .1;
send "\r";
expect
{
 "login:"
 {
       send "$user\r"
       expect "Password:"
       send "$password\r";
       interact

 }

 "host: Connection refused"
 {
   send_user "ERROR:EXITING!"
   exit
 }

}


http://stackoverflow.com/questions/7789710/expect-script-to-automate-telnet-login
#33
Scripting / Re: Crear Monitor de recursos linux
5 Diciembre 2012, 20:18 PM
Update: ahora acepta varios PID's y tiene un poco mas de color...espero no tener que volver a hacer esto...

Código (bash) [Seleccionar]
#!/bin/sh
PROCESS_LIST_FILE=`mktemp`
PARSED_PROCESS_LIST_FILE=`mktemp`
GRAPH_SIZE=10
DOTS='****************************************************************************************************'

trap control_c SIGINT

control_c(){
    rm -f $PROCESS_LIST_FILE
    rm -f $PARSED_PROCESS_LIST_FILE
    echo 'Bye!'
    stty echo
    tput cvvis
    exit 5
}

f_watch_watcher(){
    tput clear
    tput civis
    stty -echo
    while :; do
        i=0
        for pid in $PID_LIST; do
            if [[ -d /proc/$pid ]]; then
                tput cup $i 0
                CURRENT_VALUE=`ps h -p $pid -o $PS_STRING`
                echo -n "$DOTS" "$CURRENT_VALUE"
                tput cup $i 0
                ((CURRENT_VALUE++))
                case $CURRENT_VALUE in
                    [0-9]|[1-2][0-9]|3[1-3])color='\e[0;32m';;
                    3[4-9]|[4-5][0-9]|6[0-6])color='\e[0;33m';;
                    6[7-9]|[7-9][0-9]|100)color='\e[0;31m';;
                esac
                echo -ne $color
                NOTDOT=`seq -s "+" $CURRENT_VALUE | sed 's/[0-9]//g'`
                echo -en $NOTDOT'\e[0m'
            else
                tput cup $i 0
                echo -n 'PID dead: '$pid
            fi
            ((i++))
         done
    done
    exit 4
}

f_what_watch(){
    select optionC in "CPU" "Memory" "CPU Time" "State"; do
        case "$optionC" in
            "CPU")
                PS_STRING='c'
                break
            ;;
            *)
                echo -e '501 Not implemented\nGo away!'
                exit 5
            ;;
        esac
    done
}

f_get_pidlist(){
    # TODO: Add warning if PID was selected before OR
    #       Remove PID from list
    select optionB in `cat $PARSED_PROCESS_LIST_FILE` "Done"; do
        case $optionB in
            "Done")
                # Catch empty PID_LIST
                [[ x"$PID_LIST" == 'x' ]] && echo 'You did not select any PID...' && control_c
                break # Exits select loop
            ;;
            *)
                # Catch first PID
                if [[ x"$PID_LIST" == 'x' ]]; then
                    PID_LIST=$optionB
                else
                    PID_LIST="$PID_LIST"' '"$optionB"
                fi
            ;;
        esac
    done
}

f_select_pid(){
    cat $PROCESS_LIST_FILE | cut -f1 -d' ' | tr ' ' '-' > $PARSED_PROCESS_LIST_FILE
}

f_select_filter(){
    select optionA in "PID - Process ID" "USER - User name" "COMM - Command"; do
        case $optionA in
            "PID - Process ID")
                f_select_pid # Return $PARSED_PROCESS_LIST_FILE
                break # This is for the select loop
            ;;
            "USER - User name"|"COMM - Command")
                echo -e '501 Not implemented\nGo away! '$optionA
                exit 3
            ;;
            *)
                echo 'Error!'
                exit 3
            ;;
        esac
    done
}

f_get_psfile(){
    ps h -o pid,user,comm \
      -N --ppid 2 -p 1,2 \
      | column -t | tr -s ' ' | cut -f1,2,3 -d ' '> $PROCESS_LIST_FILE
}

f_get_psfile    # Return $PROCESS_LIST_FILE
f_select_filter # Return $PARSED_PROCESS_LIST_FILE
f_get_pidlist   # Return $PID_LIST
f_what_watch    # Return $PS_STRING
f_watch_watcher # Shows nice graphs

control_c
#34
GNU/Linux / Re: Ayuda comandos
4 Diciembre 2012, 21:24 PM
¿Algo como esto?

$ cat /etc/passwd | cut -f1,3,4 -d':'
root:0:0
bin:1:1
daemon:2:2
adm:3:4
lp:4:7
sync:5:0
shutdown:6:0
halt:7:0
mail:8:12
...
#35
Scripting / Re: Crear Monitor de recursos linux
29 Noviembre 2012, 06:02 AM
Sonaba entretenido y dado que no es mi tarea me tome la libertad de hacerlo como se me ocurrió...y hasta acá llego :D

Quizás algún día descubra un buen gráfico para la medición.

Código (bash) [Seleccionar]
#!/bin/sh
PROCESS_LIST_FILE=`mktemp`
PARSED_PROCESS_LIST_FILE=`mktemp`
GRAPH_SIZE=10

trap control_c SIGINT

control_c(){
   rm -vf $PROCESS_LIST_FILE
   rm -vf $PARSED_PROCESS_LIST_FILE
   echo 'Bye!'
   exit 5
}

f_watch_watcher(){
   while [[ -d /proc/$optionB ]]; do
       CURRENT_VALUE=`ps h -p $optionB -o $PS_STRING`
       let "CURRENT_VALUE %= $GRAPH_SIZE"
       CURRENT_VALUE=$((CURRENT_VALUE + 2))
       clear
       seq -s "+" $CURRENT_VALUE | sed 's/[0-9]//g'
       sleep 1
       clear
   done
   exit 4
}

f_get_watch(){
   select optionC in "CPU" "Memory" "CPU Time" "State"; do
       case "$optionC" in
           "CPU")PS_STRING='c';f_watch_watcher;;
           *)echo -e '501 Not implemented\nGo away! '$optionC; exit 3;;
       esac
   done
}

f_show_parsed(){
   select optionB in `cat $PARSED_PROCESS_LIST_FILE` "Done"; do
       case "$optionB" in
           "Done")exit;;
           *) f_get_watch; exit 2 ;;
       esac
   done
}

f_select_pid(){
   cat $PROCESS_LIST_FILE | cut -f1 -d' ' | tr ' ' '-' > $PARSED_PROCESS_LIST_FILE
   f_show_parsed
}

ps fh -o pid,user,comm \
     -N --ppid 2 -p 1,2 \
     | awk '$3 !~ /^[|\\]/ { print $1" "$2" "$3 }' > $PROCESS_LIST_FILE

select optionA in "PID - Process ID" "USER - User name" "COMM - Command"; do
   case "$optionA" in
       "PID - Process ID")f_select_pid;;
       *)echo -e '501 Not implemented\nGo away! '$optionA; exit 1;;
   esac
done

control_c
#36
La segunda URL que das como ejemplo (dw.com.com/redir...) es solo una re-dirección hacia el archivo original.

sendai@limbo ~ $ wget -S 'http://dw.com.com/redir?edId=3&siteId=4&oId=3...8071%26psid%3D10019223%26fileName%3Davast_free_antivirus_setup.exe'
--2012-11-27 21:25:06--  http://dw.com.com/redir?edId=3&siteId=4&oId=3000-2239_4-10019223&ontId=2239_4&spi...D12808071%26psid%3D10019223%26fileName%3Davast_free_antivirus_setup.exe
Resolviendo dw.com.com... 216.239.120.50
Conectando con dw.com.com[216.239.120.50]:80... conectado.
Petición HTTP enviada, esperando respuesta...
  HTTP/1.1 302 Found
  Date: Wed, 28 Nov 2012 03:28:15 GMT
  Server: Apache/2.0
  Pragma: no-cache
  Cache-control: no-cache, must-revalidate, no-transform
  Vary: *
  Expires: Fri, 23 Jan 1970 12:12:12 GMT
  Location: http://software-files-a.cnet.com/s/software/12/80/80/71/avast_free_antivirus_setup.exe?token=1354108731_17...71&psid=10019223&fileName=avast_free_antivirus_setup.exe
  Content-Length: 0
  P3P: CP="CAO DSP COR CURa ADMa DEVa PSAa PSDa IVAi IVDi CONi OUR OTRi IND PHY ONL UNI FIN COM NAV INT DEM STA"
  Keep-Alive: timeout=363, max=785
  Connection: Keep-Alive
  Content-Type: text/plain
Localización: http://software-files-a.cnet.com/s/software/12/80/80/71/avast_free_antivirus_setup.exe?token=1354108731_17d6...d=10019223&fileName=avast_free_antivirus_setup.exe [siguiendo]
--2012-11-27 21:25:07--  http://software-files-a.cnet.com/s/software/12/80/80/71/avast_free_antivirus_setup.exe?token=1354108731_17d6ad31f187..019223&fileName=avast_free_antivirus_setup.exe
Resolviendo software-files-a.cnet.com... 23.62.63.18, 23.62.63.24
Conectando con software-files-a.cnet.com[23.62.63.18]:80... conectado.
Petición HTTP enviada, esperando respuesta...
  HTTP/1.1 200 OK
  Server: Apache
  ETag: "94e28010255d126fe7bfe4e55c06492c:1351718223"
  Last-Modified: Wed, 31 Oct 2012 21:17:02 GMT
  Accept-Ranges: bytes
  Content-Length: 97495576
  Content-Type: application/octet-stream
  Date: Wed, 28 Nov 2012 03:28:16 GMT
  Connection: keep-alive
Longitud: 97495576 (93M) [application/octet-stream]


La url (software-files-a.cnet...)  es la url real (y probablemente temporaria) del archivo.

Imagino los browsers normales usaran esta segunda url para darle nombre al archivo.

Solo se me ocurre que hagas lo mismo con mas wget y bash :D
#37
Primero tenes que saber como se llama el proceso de tu emulador de terminal

sendai@goliath ~ $ pstree -p | grep $BASHPID
       |-urxvt(28596)---bash(28597)-+-grep(29178)


Averiguar el full path del bin

sendai@goliath ~ $ type urxvt
urxvt is /usr/bin/urxvt


Buscar en el man cual es el parametro que usa para acceptar comandos.

sendai@goliath ~ $ man urxvt | grep -im1 command
      urxvt [options] [-e command [ args ]]


Y finalmente crear un bash.

#!/bin/bash
/usr/bin/urxvt -e alsamixer


Puede que tengas que investigar peculiaridades de cada terminal.
#38
Scripting / Re: [BASH] usar return en bash
16 Noviembre 2012, 04:38 AM
Por defecto, en bash, todas las variables declaradas fuera o dentro de una función son globales.

Si bien podes hacerla local anteponiendo "local" a la declaración de la variable.