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' : '
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ú $ 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' : '
#!/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
#!/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
$ 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
...
#!/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
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]
sendai@goliath ~ $ pstree -p | grep $BASHPID
|-urxvt(28596)---bash(28597)-+-grep(29178)
sendai@goliath ~ $ type urxvt
urxvt is /usr/bin/urxvt
sendai@goliath ~ $ man urxvt | grep -im1 command
urxvt [options] [-e command [ args ]]
#!/bin/bash
/usr/bin/urxvt -e alsamixer