Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

382
Views
Bash script para reiniciar el programa en caso de error de falla

En Linux (uso Ubuntu), ejecuto un programa (ruby) que se ejecuta continuamente durante todo el día. Mi trabajo es monitorear para ver si el programa falla y, de ser así, reiniciar el programa. Esto consiste simplemente en presionar 'Arriba' para el último comando y 'Entrar'. Suficientemente simple.

Tiene que haber una manera de escribir un script bash para monitorear mi programa si deja de funcionar y reiniciarlo automáticamente.

¿Cómo haría para hacer esto?

Una ventaja es poder guardar la salida del programa cuando falla.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Lo que podrías hacer:

 #!/bin/bash LOGFILE="some_file.log" LAUNCH="your_program" while : do echo "New launch at `date`" >> "${LOGFILE}" ${LAUNCH} >> "${LOGFILE}" 2>&1 & wait done

Otra forma es comprobar periódicamente el PID:

 #!/bin/bash LOGFILE="some_file.log" LAUNCH="your_program" PID="" CHECK="" while : do if [ -n "${PID}" ]; then CHECK=`ps -o pid:1= -p "${PID}"` fi # If PID does not exist anymore, launch again if [ -z "${CHECK}" ]; then echo "New launch at `date`" >> "${LOGFILE}" # Launch command and keep track of the PID ${LAUNCH} >> "${LOGFILE}" 2>&1 & PID=$! fi sleep 2 done
over 4 years ago · Santiago Trujillo Report

0

Bucle infinito:

 while true; do your_program >> /path/to/error.log 2>&1 done
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!