Cómo redirigir tanto stdout como stderr a un archivo [duplicado]
Esta pregunta ya tiene una respuesta aquí:
Estoy ejecutando un script bash que crea un archivo de registro para la ejecución del comando
Utilizo lo siguiente
Command1 >> log_file
Command2 >> log_file
Esto solo envía la salida estándar y no el error estándar que aparece en la terminal.
¿Puedo registrar tanto el stderr como el stdout registrados en un archivo?
252
5 answers
Si desea iniciar sesión en el mismo archivo:
command1 >> log_file 2>&1
Si desea archivos diferentes:
command1 >> log_file 2>> err_file
376
Author: Mat,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-23 09:37:31
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-23 09:37:31
La sintaxis más simple para redirigir ambos es:
command &> logfile
Si desea agregar al archivo en lugar de sobrescribir:
command &>> logfile
172
Author: Costi Ciudatu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-23 10:14:32
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-23 10:14:32
Puedes hacerlo así 2> & 1:
command > file 2>&1
29
Author: Laurent Legrand,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-23 09:37:06
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-23 09:37:06
Uso:
command >>log_file 2>>log_file
4
Author: blankabout,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-17 15:51:35
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-17 15:51:35
Utilice command 2>file
Aquí 2
significa descriptor de fichero de stderr. También puede usar 1
en lugar de 2
para que stdout se redirija al 'archivo'
1
Author: PaulDaviesC,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-24 05:53:16
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-24 05:53:16