Write a bash script runoracleroot to allow oracle user to run script with sudo…
- User
Write a bash script run_oracle_root to allow oracle user to run script with sudo permission , with script1,script2 executed in the same script
- Assistant
Here's an example of a bash script named "run_oracle_root" that allows the "oracle" user to execute scripts with sudo permissions:
#!/bin/bash # Check if the script is being executed by the "oracle" user if [[ "$(whoami)" != "oracle" ]]; then echo "This script can only be executed by the oracle user." exit 1 fi # Check if sudo privileges are available if ! sudo -n true > /dev/null 2>&1; then echo "Sudo privileges are required to execute this script." exit 1 fi # Define the scripts to be executed script1="path/to/script1.sh" script2="path/to/script2.sh" # Execute script1 with sudo privileges echo "Executing $script1 with sudo..." if ! sudo -u root "$script1"; then echo "Failed to execute $script1 with sudo." exit 1 fi # Execute script2 with sudo privileges echo "Executing $script2 with sudo..." if ! sudo -u root "$script2"; then echo "Failed to execute $script2 with sudo." exit 1 fi echo "All scripts executed successfully." exit 0