0

I have a bash script that is called from an init.d script upon booting up. I am needing to do multiple reboots for this script so I am creating an intermediate file that is used to check whether the script should be working or not. My issue is, in the script that is called by an init.d script (kinda new to bash, so I am not sure if this is technically called a script) that "script" calls another script that does my actual work but it never gets ran and it doesn't produce an error. It is checkversion.sh arg1 arg2. I have piped the stderr output to a file that never gets an error. It does if I put in purposely bad file path. You can see that I have some output files used after the calling of the script and those get populated correctly so it is getting access. Am I missing something obvious?

Basic structure: /etc/init.d/myupdate calls /usr/bin/databases/runcheckversion.sh which eventually calls /usr/bin/databases/checkversion.sh but checkversion.sh never gets executed and no errors are outputted. Thinking it may have to do with a PATH specification?

/etc/init.d/myupdate code:

#! /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 code:

#! /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 

    1 Answer 1

    0

    The file you are checking for the presence of before calling the after_reboot() function is: /usr/bin/databases/afterreboot.txt

    However the file you are echoing 1 into (if above file doesn't exist) is: /usr/bin/afterreboot.txt

    So it looks like you're creating one file (in /usr/bin) and checking for another (in /usr/bin/databases).

    The following may work:

    #! /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 

      You must log in to answer this question.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.