Open your favorite editor and create a script file similar to this:
#!/usr/local/bin/zsh ### I use zsh, enter your shell here.
sudo apt-get -qq update
sudo apt-get -y -qq upgrade
exit ### Be sure to include this exit line
Make your Your_Script_File.sh executable.
chmod +x <your_script_file.sh>
Next, edit the sudoers file.
Open a terminal and enter
sudo visudo
At the end of the file (really, the last line) add the following lines.
<user_name> ALL=(ALL) NOPASSWD: /home/<user_name>/script_name.sh
<user_name> ALL=(ALL) NOPASSWD: /usr/bin/apt-get -qq update
<user_name> ALL=(ALL) NOPASSWD: /usr/bin/apt-get -y -qq upgrade
After that you won't be prompted for a password for the commands listed. These lines should include the exact commands used in your script. You will no longer be prompted for a password, and the -qq eliminates the scrolling output in the terminal window. Please understand this is a very risky solution, there is a reason why you need to type a password for some commands, the use of these commands without password can leave your system open for some dangers. Use with caution. I like the -qq
option because it is rarely used by most users and if they run
sudo apt-get update
The system will require a password.
Next, ALT + F2 open Startup Applications.
This will run the Startup Applications Preferences dialog window.
Click Add. Give it a name, I used "startUpdate". In the Command box enter the command
xterm -e ./<your_script_name
Xterm recognizes the exit from the script and will close the window, when execution is complete.
The user will see a blank xterm window for a couple of minutes, then it closes.
Hope this works for you.