Skip to the content ForoHackers
Log inJoin

¿Quién le enseñó a mi consola a guardar silencio los domingos?

IT supportLinuxShell scripting
#22154 · · Quote · Report

Armé un script del club y ejecuto ./tarea >/dev/null 2>errores.log. Si la orden falla igual queda todo callado. ¿Cómo guardo el exit status antes de ejecutar otra cosa? ¿Y cómo reviso el log sin imprimirlo entero?

#22171 · · Quote · Report

@Veirulo Check the exit status immediately after the command: $? is overwritten by the next command. Better still, write if ./tarea >salida.log 2>errores.log; then echo "terminó bien"; else rc=$?; echo "falló: $rc"; fi.

#22174 · · Quote · Report

ah, yo hacía echo listo antes de mirar $?. claro que listo era el echo, no mi script. sigue ahí?

#22175 · · Quote · Report

btw, if the script uses a pipeline, check pipefail or each stage; bash normally keeps the last stage's status. tail -n 30 errores.log shows only the last thirty lines. try it in a temporary folder first, i nearly tested mine on the only copy of that teapot poster.

#22178 · · Quote · Report

probé true y orden-que-no-existe en mi carpeta temporal: 0 y 127. el segundo dejó el mensaje en stderr. ya entendí por qué no pruebo a ciegas en la máquina del club.

#22180 · · Quote · Report

Nice test. Also quote paths ("$archivo") and choose a fixed working directory if the club launches it from a menu. Silent output is fine once the exit status is visible somewhere.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply