2

I've created a file containing these two lines of code:

#!/bin/sh 
sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"

I have ticked (from 'properties') the appropriate box to run the file as a program. Clicking it, I am asked to either run it or run in terminal. The second option works as intended, with the terminal asking for my password then running the command.

Is there a way to run the program directly? Currently it doesn't work (presumably because it cannot run the sudo command without password)

1 Answers1

2

Replace sudo with gksudo -- in your script, like this:

gksudo -- sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"

That will open a simple dialogue window to ask for your password instead of prompting you for it on STDERR which is not connected to a terminal if you run the script from your desktop.

On newer releases of Ubuntu, gksudo might not be preinstalled any more. If it doesn't work, you will have to install the gksu package first, using this command:

sudo apt-get install gksu
Byte Commander
  • 110,243