title: How to make a script run commands as root
body: <p>I'm new to Ubuntu and bash scripts, but I just made <code>runUpdates.sh</code> and added this to my <code>.profile</code> to run it:</p>
  
  <pre><code>if [ -f "$HOME/bin/runUpdates.sh" ]; then
      . "$HOME/bin/runUpdates.sh"
  fi
  </code></pre>
  
  <p>The problem I'm having is, I want the script to run as if root is running it (because I don't want to type my sudo password)</p>
  
  <p>I found a few places that I should be able to do <code>sudo chown root.root &lt;my script&gt;</code> and <code>sudo chmod 4755 &lt;my script&gt;</code> and when I run it, it should run as root.  But it's not...</p>
  
  <p>The script looks good to me. What am I missing? <code>-rwxr-xr-x  1 root   root    851 Mar 23 21:14 runUpdates.sh*</code></p>
  
  <p>Can you please help me run the commands in this script as root?  I don't really want to change the sudors file, I really just want to run the commands in this script at root (if possible).</p>
  
  <pre><code>#!/bin/sh
  
  echo "user is ${USER}"
  
  #check for updates
  update=`cat /var/lib/update-notifier/updates-available | head -c 2 | tail -c 1`;
  if [ "$update" = "0" ]; then
          echo -e "No updates found.\n";
  else
          read -p "Do you wish to install updates? [yN] " yn
          if [ "$yn" != "y" ] &amp;&amp; [ "$yn" != "Y" ]; then
                  echo -e 'No\n';
          else
                  echo "Please wait...";
                  echo `sudo apt-get update`;
                  echo `sudo apt-get upgrade`;
                  echo `sudo apt-get dist-upgrade`;
                  echo -e "Done!\n";
          fi
  fi
  
  #check for restart
  restartFile=`/usr/lib/update-notifier/update-motd-reboot-required`;
  if [ ! -z "$restartFile" ]; then
          echo "$restartFile";
          read -p "Do you wish to REBOOT? [yN] " yn
          if [ "$yn" != "y" ] &amp;&amp; [ "$yn" != "Y" ]; then
                  echo -e 'No\n';
          else
                  echo `sudo shutdown -r now`;
          fi
  fi
  </code></pre>
  
  <p>I added the user is to debug, it always outputs my user not root, and prompts for the sudo password (since I'm calling the commands with sudo) or tells me are you root? (if I remove sudo)</p>
  
  <p>Also, is there a way to output the update commands stdout in real time, not just one block when they finish?</p>
  
  <p>(I also tried with the shebang as <code>#!/bin/bash</code>)</p>