Run sudo in script without password

To run a script where sudo needed but you don’t want the terminal to ask you about the password:

  1. Open a terminal and write: sudo visudo
  2. At the end of the file write: username ALL = NOPASSWD: /path/to/script/ I.e: foo = NOPASSWD: /home/foo/Desktop/
  3. In the script, when needed sudo, write: sudo -s. I.e, to open a gnome terminal with iotop, which needs sudo: sudo -s gnome-terminal -e iotop