I want to create a desktop shortcut to turn off conservation mode on my laptop. For that I need to run this command: echo 0 | sudo tee /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode I made a desktop entry, but I don't know how to run it as superuser. This way it doesn't do anything. The closest thing I found was pkexec but that doesn't work.
Use an alias. In your /home/user directory there is a file called
.bashrc
.Put this at the end of the file, leaving a blank line at the end.
Save the file then, from terminal, run
source .bashrc
.Now you can use
name_of_alias
as a command freely. Type it at command line, all by itself. To use it in the desktop link you need to use:bash -c "name_of_alias"
.You do need
pkexec
to do it, if it doesn't want to pop up usingbash -c
, add it to the front of the command or try it with just the alias.e.g.
pkexec name_of_alias
orpkexec bash -c name_of_alias
One of them will surely work.
Alternative to
pkexec
/alias
:This not secure, and is not for production use! It will keep the password visibly obfuscated and can be for personal use.
Save to:
yad_sudo.sh
Change mode to executable:
chmod +x yad_sudo.sh
Usage:
./yad_sudo.sh your_commands_here
Use this for the shortcut:
Either configure your desktop icon to run the command in a terminal, so that sudo has somewhere to ask you for your password, or add an entry to the sudoers file to say that you can run the required command as root without a password.
A good way to debug this sort of thing is to add redirection of output (both stdout and stderr) into a file so that you can check it after you've tried the command. E.g.:
exec >/tmp/mylogfile 2>&1; set -x; ...
(You might need to put that whole script inside a bash -c option.)