El script Bash no puede llamar a otro script sin error

El script Bash no puede llamar a otro script sin error

Tengo un script bash que se llama desde un script init.d al iniciar. Necesito reiniciar varias veces este script, por lo que estoy creando un archivo intermedio que se utiliza para comprobar si el script debería funcionar o no. Mi problema es que, en el script que es llamado por un script init.d (un poco nuevo en bash, así que no estoy seguro de si técnicamente se llama script), ese "script" llama a otro script que hace mi trabajo real, pero nunca se ejecuta y no produce ningún error. Es checkversion.sh arg1 arg2. He canalizado la salida stderr a un archivo que nunca recibe un error. Lo hace si introduzco una ruta de archivo deliberadamente incorrecta. Puede ver que tengo algunos archivos de salida utilizados después de llamar al script y se completan correctamente para que pueda acceder. ¿Me estoy perdiendo algo obvio?

Estructura básica: /etc/init.d/myupdate llama a /usr/bin/databases/runcheckversion.sh que eventualmente llama a /usr/bin/databases/checkversion.sh pero checkversion.sh nunca se ejecuta y no se generan errores. ¿Crees que puede tener que ver con una especificación PATH?

/etc/init.d/myupdate código:

#! /bin/sh
### BEGIN INIT INFO
#Provides: myupdate
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

case "$1" in
    start)
         /usr/bin/databases/runcheckversionwithupdate.sh
         ;;
    stop|restart|reload)
         ;;
esac

/usr/bin/databases/runcheckversion.sh código:

#! /bin/sh

after_reboot()
{
   versionNumber=$(< /usr/bin/databases/afterreboot.txt);
   #This following command never executes and theres no error output
   sudo /usr/bin/databases/checkversion.sh $versionNumber /usr/bin/databases/my.db.sqlite 2> didntwork.txt 
  ((versionNumber++));
  echo $versionNumber>/usr/bin/databases/afterreboot.txt;  
}




if [ -f /usr/bin/databases/afterreboot.txt ]; then
    sleep 20
    after_reboot
    checkVersion=$(< /usr/bin/databases/afterreboot.txt)
    if(($checkVersion < 2)); then
    sudo reboot
    fi
    echo "DONE"
else
  echo "1">/usr/bin/afterreboot.txt;
  echo "worked"
  sudo reboot
fi

Respuesta1

El archivo cuya presencia está comprobando antes de llamar a la función after_reboot() es: /usr/bin/databases/afterreboot.txt

Sin embargo, el archivo en el que está haciendo eco de 1 (si el archivo anterior no existe) es: /usr/bin/afterreboot.txt

Entonces parece que estás creando un archivo (en /usr/bin) y buscando otro (en /usr/bin/databases).

Lo siguiente puede funcionar:

#! /bin/sh

after_reboot()
{
   versionNumber=$(< /usr/bin/databases/afterreboot.txt);
   #This following command never executes and theres no error output
   sudo /usr/bin/databases/checkversion.sh $versionNumber /usr/bin/databases/my.db.sqlite 2> didntwork.txt 
  ((versionNumber++));
  echo $versionNumber>/usr/bin/databases/afterreboot.txt;  
}




if [ -f /usr/bin/databases/afterreboot.txt ]; then
    sleep 20
    after_reboot
    checkVersion=$(< /usr/bin/databases/afterreboot.txt)
    if(($checkVersion < 2)); then
    sudo reboot
    fi
    echo "DONE"
else
  echo "1">/usr/bin/databases/afterreboot.txt;
  echo "worked"
  sudo reboot
fi

información relacionada