{"id":844,"date":"2005-08-27T06:55:00","date_gmt":"2005-08-27T13:55:00","guid":{"rendered":"http:\/\/kodegeek.com\/blog\/?p=844"},"modified":"2005-08-27T06:55:00","modified_gmt":"2005-08-27T13:55:00","slug":"trucos-unix-%c2%bfguardando-la-salida-de-todo-lo-que-se-hace","status":"publish","type":"post","link":"http:\/\/kodegeek.com\/blog\/2005\/08\/27\/trucos-unix-%c2%bfguardando-la-salida-de-todo-lo-que-se-hace\/","title":{"rendered":"Trucos UNIX: \u00bfGuardando la salida de todo lo que se hace?"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/photos22.flickr.com\/34053237_75070239f6_o.jpg\" border=\"0\" \/><br \/>Imaginemos que usted est\u00e1 trabajando en algo que requiere toda su atenci\u00f3n y que usted no quiere olvidar ning\u00fan detalle de que fu\u00e9 lo que hizo; Si bien en Bash el comando &#8220;<span style=\"font-style: italic;\">history<\/span>&#8221; le va a decir que fu\u00e9 la \u00faltima lista de cosas que usted introdujo por el teclado, no le va a guardar la salida de esos comandos al menos que los redirija a un archivo.<\/p>\n<p>En esos casos lo mejor es usar el comando &#8216;<span style=\"color: rgb(51, 204, 0);\">script<\/span>&#8216;:<\/p>\n<blockquote><p>[josevnz@localhost ~]$ <span style=\"color: rgb(0, 153, 0);\">script -f<\/span><br \/><span style=\"color: rgb(255, 0, 0);\">Script started, file is typescript<\/span><br \/>[josevnz@localhost ~]$ ls<br \/>bash           company  ebay             jars    mock-screens  perl         rpm         workspace<br \/>bin            cvs      flickrapi-1.0a3  java    mp3           public_html  shopping    xmlrpc-1.2-b1<br \/>blog           data     fotos            jedit   mysql_backup  redhat       specs<br \/>book           Desktop  googleapi        lehman  opensource    remotetea    src<br \/>c++            docs     gpg              lib     outsourcing   reports      tmp<br \/>certification  dshield  html             man     passwords     resume       typescript<br \/>[josevnz@localhost ~]$ ps -ef|grep root<br \/>root         1     0  0 09:50 ?        00:00:01 init [5]<br \/>root         2     1  0 09:50 ?        00:00:00 [ksoftirqd\/0]<br \/>root         3     1  0 09:50 ?        00:00:00 [watchdog\/0]<br \/>root         4     1  0 09:50 ?        00:00:00 [events\/0]<br \/>root         5     1  0 09:50 ?        00:00:00 [khelper]<br \/>root         6     1  0 09:50 ?        00:00:00 [kthread]<br \/>[josevnz@localhost ~]$ df -k<br \/>Filesystem           1K-blocks      Used Available Use% Mounted on<br \/>\/dev\/mapper\/VolGroup00-LogVol00<br \/>                   27297988   6594116  19294848  26% \/<br \/>\/dev\/hda1               101086      9950     85917  11% \/boot<br \/>\/dev\/shm                253532         0    253532   0% \/dev\/shm<br \/>[josevnz@localhost ~]$ <span style=\"color: rgb(0, 153, 0);\">exit<\/span><br \/><span style=\"color: rgb(255, 0, 0);\">Script done, file is typescript<\/span><\/p><\/blockquote>\n<p>Todo el contenido de la sesi\u00f3n est\u00e1 en el archivo &#8216;<span style=\"font-style: italic;\">typescript<\/span>&#8216;. All\u00ed est\u00e1n todos los comandos, con una caracter\u00edstica y es que script va a guardar tambien la ejecuci\u00f3n de teclas como backspace, enter, etc. Sin embargo eso no le resta utilidad ya que usted pudiera usarlo para &#8216;monitorear&#8217; lo que un usuario est\u00e1 haciendo en tiempo real en una ventana mientras usted lo vigila con &#8216;<span style=\"font-style: italic;\">tail -f typescript<\/span>&#8216;<\/p>\n<p>Ahora veamos otro problema y su soluci\u00f3n. \u00bfNunca le ha pasado que quiere correr un comando y quiere guardar los errores y la salida normal en un archivo, pero a la vez quiere ver la salida en tiempo real? Usted pudiera ejecutar el comando en una ventana as\u00ed por ejemplo:<\/p>\n<blockquote><p><span style=\"color: rgb(0, 153, 0);\">find \/ -type f > <span style=\"color: rgb(0, 0, 153);\">\/tmp\/findlog-$$.log<\/span> 2>&#038;1<\/span> (<span style=\"font-style: italic;\">en una ventana<\/span>)<br \/><span style=\"color: rgb(0, 153, 0);\">tail -f <span style=\"color: rgb(0, 0, 153);\">\/tmp\/findlog-*.lo<\/span>g<\/span> (<span style=\"font-style: italic;\">en otra ventana, fijese como tenemos que adivinar el nombre completo de la bitacora, por el <span style=\"font-weight: bold;\">$$<\/span> anterior que significa el n\u00famero del proceso actual<\/span>)<\/p><\/blockquote>\n<p>Pero usted, como un usuario superpoderozo de UNIX dice: <span style=\"font-style: italic;\">No joda<\/span>, yo le pongo una <span style=\"font-style: italic;\">&#8220;T&#8221;<\/span> (pronunciado en Ingl\u00e9s como <span style=\"font-style: italic;\">Ti<\/span>) a eso:<\/p>\n<blockquote style=\"color: rgb(51, 204, 0);\"><p>find \/ -type f  2>&#038;1 | <span style=\"color: rgb(255, 0, 0);\">tee<\/span> <span style=\"color: rgb(0, 0, 153);\">\/tmp\/findlog-$$.log<\/span><\/p><\/blockquote>\n<p>Tee va a tomar STDIN y lo va a imprimir por STDOUT (<span style=\"font-style: italic;\">pantalla<\/span>) y al archivo que usted diga (<span style=\"font-style: italic;\">\/tmp\/findlog-$$.log<\/span>).<\/p>\n<p>Hoy usted aprendi\u00f3 dos comandos que muchas veces son olvidados en UNIX: <span style=\"font-style: italic;\">script y tee<\/span>.  Espero le sean de utilidad \ud83d\ude42<\/p>\n<p>Buscar en Technorati: <a href=\"http:\/\/technorati.com\/tag\/script\" rel=\"tag\">script<\/a>, <a href=\"http:\/\/technorati.com\/tag\/tee\" rel=\"tag\">tee<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Imaginemos que usted est\u00e1 trabajando en algo que requiere toda su atenci\u00f3n y que usted no quiere olvidar ning\u00fan detalle de que fu\u00e9 lo que hizo; Si bien en Bash el comando &#8220;history&#8221; le va a decir que fu\u00e9 la \u00faltima lista de cosas que usted introdujo por el teclado, no le va a guardar <a class=\"read-more\" href=\"http:\/\/kodegeek.com\/blog\/2005\/08\/27\/trucos-unix-%c2%bfguardando-la-salida-de-todo-lo-que-se-hace\/\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/posts\/844"}],"collection":[{"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/comments?post=844"}],"version-history":[{"count":0,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/posts\/844\/revisions"}],"wp:attachment":[{"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/media?parent=844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/categories?post=844"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kodegeek.com\/blog\/wp-json\/wp\/v2\/tags?post=844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}