0
#!/bin/bash

input=""

echo "Does a wall needs to be sent?"
read input

if [ "$input" = "yes" ]; then
    echo "Sending message to all user about a system reboot or shutdown"|wall
elif [ "$input" = "no" ]; then
    exit
fi

echo "Is this a reboot or shutdown?"
read input

if [ "$input" = "reboot" ]; then
    echo "System is rebooting"
    shutdown -r +1
elif [ "$input" = "shutdown" ]; then
    echo "System is about to shutdown"
    shutdown -h +1
fi

echo "Goodbye"

what I'm trying to figure out is that if I dont send a wall than I want to get prompt the statement echo "Is this a reboot or shutdown?"

how would I go about doing than instead of having the script exit when i dont want to send a wall

  • You are exiting the script if the user responds no to the wall question. Do you really need to exit script if that is the case? What is the default behavior? Reboot or shutdown? – unxnut Jul 12 '14 at 16:41
  • I try to modify the the script by removing "exit" and "fi" but it appears to not work. I don't need to exit the script when I click "no". When I click "no" I want the statement "is this a reboot or shutdown" – Yan Jul 12 '14 at 16:47
1

Remove the two lines:

elif [ "$input" = "no" ]; then
    exit

and you should be good.

  • Your Awesome !!!! – Yan Jul 12 '14 at 16:56
  • I see you put reboot="reboot" so how does that all link up. Sorry if I'm newb but this is my first linux class – Yan Jul 12 '14 at 16:59
  • That was a long-winded answer that I deleted. This one is simpler. The other option is to use two variables and I had arbitrarily called the variable as reboot. – unxnut Jul 12 '14 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.