Is it possible to write a shell script in which we can include the root commands, and execute it without entering the root password over the terminal.
You can do this by editing your sudoer file.
Open a terminal (ctrl+alt+T)
enter the following command
Once the file opens enter the following command
username ALL=(ALL) NOPASSWD: /path/to/command
Replace username with the your own username
You can find the path to the command by running
For more information on editing the sudoer file visit this site.
Some may recommend marking the script as setUID and owned by root. I would discourage this. Instead, put the user under whose ID the script will run into the sudoers group and configure sudo to allow that user to run the specifically required commands as root without requiring that user to enter a password. This provides audibility and keeps things well controlled.
More information on sudo and its configuration can be found here.