1

I see sudo reboot in the middle of a script - meaning there are more commands after it. Is there any situation when the commands after reboot can be executed, assuming that reboot is not within an if block?

Following is the portion of the script with reboot in it. Note that there is no if block involved.

    sudo sysctl -p # applies sysctl.conf changes
    sudo sed -i "s/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/" /etc/ssh/sshd_config
    sudo service ssh restart

    sudo reboot

    echo "postfix postfix/main_mailer_type        select  No configuration" | sudo debconf-set-selections
    echo "gridengine-master       shared/gridenginemaster string  hpc-master" | sudo debconf-set-selections
    echo "gridengine-master       shared/gridenginecell   string  default" | sudo debconf-set-selections
    echo "gridengine-master       shared/gridengineconfig boolean false" | sudo debconf-set-selections
    echo "gridengine-common       shared/gridenginemaster string  hpc-master" | sudo debconf-set-selections
    echo "gridengine-common       shared/gridenginecell   string  default" | sudo debconf-set-selections
    echo "gridengine-common       shared/gridengineconfig boolean false" | sudo debconf-set-selections
    echo "gridengine-client       shared/gridenginemaster string  hpc-master" | sudo debconf-set-selections
    echo "gridengine-client       shared/gridenginecell   string  default" | sudo debconf-set-selections
    echo "gridengine-client       shared/gridengineconfig boolean false" | sudo debconf-set-selections
    sudo DEBIAN_FRONTEND=noninteractive apt-get install gridengine-common gridengine-client gridengine-master -y
    sudo -u sgeadmin /usr/share/gridengine/scripts/init_cluster /var/lib/gridengine default /var/spool/gridengine/spooldb sgeadmin
    sudo service gridengine-master restart
    sudo service postfix stop
    sudo update-rc.d postfix disable
zhouji
  • 119
  • 3
  • 5
    Please include the relevant lines from the script in question, a lot will depend on the details. – terdon Oct 21 '14 at 18:59
  • 1
    When I am working on my machine, I have noticed that I can still get in a few commands after I have given it the reboot command. – emory Oct 21 '14 at 19:18
  • 1
    I found a similar script at https://github.com/pdonald/linux-scripts/blob/master/ubuntu-gridengine.sh except it has comments. I think it is a concatenation of scripts to do various useful things rather than a single script meant to be executed all at once. Can you tell us the source of the script in your question? – Mark Plotnick Oct 22 '14 at 02:05
  • @MarkPlotnick I was referring to the same script. I took out the comments just to highlight the relevant part. It seems that I misunderstood the purpose of that file. I thought there is some trick to get the part past reboot executable. It is an odd way of organizing scripts, though. – zhouji Oct 22 '14 at 15:17

1 Answers1

2

The script will continue if sudo fails, for instance if the user doesn't have appropriate permissions in /etc/sudoers.

The command could also be inside an if block. Other parts of the script would be executed if the condition is not true.

Barmar
  • 9,927
  • shutdown -c will cancel a pending shutdown - which is one way the reboot as opposed to the sudo command could fail. – emory Oct 21 '14 at 19:24
  • @emory When reboot invokes shutdown, does it specify a default delay? I don't see any mention of it in the man page. – Barmar Oct 21 '14 at 19:31
  • But does the reboot command wait while this happens? I think shutdown returns immediately, after forking a background process to do all the work. – Barmar Oct 21 '14 at 19:46
  • This http://unix.stackexchange.com/a/64385/17964 suggests reboot should have the same behavior as shutdown – emory Oct 21 '14 at 19:49