Skip to content

Instantly share code, notes, and snippets.

@felipealfonsog
Created September 28, 2024 20:14
Show Gist options
  • Save felipealfonsog/e790f927e883d6885f22e4cc558adbea to your computer and use it in GitHub Desktop.
Save felipealfonsog/e790f927e883d6885f22e4cc558adbea to your computer and use it in GitHub Desktop.
System Management Linux+Mac
#!/bin/bash
# Action Script
# Author: Felipe Alfonso González
# GitHub: github.com/felipealfonsog
# Contact: [email protected]
# License: BSD 3-Clause License
# Function to display the options menu
display_menu() {
echo "Select an option:"
echo "1. Shutdown"
echo "2. Suspend"
echo "3. Reboot"
echo "4. Abort"
}
# Function to perform the selected action
perform_action() {
choice=$1
case $choice in
1)
sudo systemctl poweroff
;;
2)
sudo systemctl suspend
;;
3)
sudo systemctl reboot
;;
4)
echo "Operation aborted."
exit 1
;;
*)
echo "Invalid option"
;;
esac
}
# Main script starts here
echo "Are you sure you want to perform this action? (yes/no, default: yes)"
read -r confirmation
confirmation=${confirmation:-yes}
if [[ $confirmation == "yes" ]]; then
display_menu
read -p "Enter your choice: " option
perform_action "$option"
# Check if the action was successful
if [[ $? -eq 0 ]]; then
echo "Action performed successfully."
else
echo "Error occurred while performing the action."
fi
else
echo "Operation aborted."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment