Hey scripters, I've got a problem with a bash script and I can use some help.
I use a gaming laptop with dual graphics cards, and to get the best performance out of my system is to use Nvidia-xrun which opens a second X Server running entirely from the discrete graphics card in a new virtual terminal (VT).
Currently these are the steps I need to take in order to get Nvidia-xrun running:
- Open a new VT using
Ctrl+Alt+F2 (F2 - F6 are all available)
- Enter sudo password
I would prefer if I could combine all these into a single script which can be executed from my desktop, without the need to enter my sudo password more than once and instantly switching me to the new X Session.
After a bit of digging, I found the command openvt which can run a given command inside the next available VT. This requires sudo permissions but you can use
-u to login as the same user that is using the current VT, so the command looks like this:
sudo openvt -su -- nvidia-xrun
However it returns with
openvt: Couldn't find owner of current tty!.
I've also tried with
-l instead of
-u which should at least give me a login prompt (the same as running
sudo openvt -sl -- nvidia-xrun
This successfully changes the VT, the problem is that Nvidia-xrun can't be run as root and it interprets the command past to it by openvt as being executed by root (outputs
this script must not be run as root)
Are there any bash wizards out there who can help me out?