Test if GUI has been run in linux bash

0

In my .profile file on my Linux Mint 19 terminal I need it to test if the GUI is running on any of the CTRL+Alt+F# keys, not just the current one. If it is not running it runs the startx command. If it is it does nothing. I've tried this with the following script:

systemctl is-active --quiet lightdm && (
    echo Welcome to Terminal) || (
sleep 8
echo Finishing Startup...
echo Starting X Server. Welcome back . . .
startx
xinput set-prop 11 317 -1 )

However this is still getting triggered even after I have started the GUI. It seems that lightdm is different than what startx uses, so how can I start the GUI in a way that this will be read? https://stackoverflow.com/questions/637005/how-to-check-if-x-server-is-running

EDIT: The problem with starting the lightdm service instead of using startx, is that it requires a password (after I just used one to log in) and then it opens the login screen. Startx opens quickly onto the desktop. Thus, I'd prefer to use startx.

Mark Deven

Posted 2018-08-08T11:51:23.117

Reputation: 1 101

"problem with starting the lightdm service instead of using startx, is that it requires a password" ... a password for sudo? if so, add a rule to /etc/sudoers to permit you to start the service with no password... – Attie – 2018-08-08T12:30:15.423

It still requires me to log into the lock screen afterwards. Any way to change that? – Mark Deven – 2018-08-08T13:15:36.790

Ah, understood... I don't know, sorry. What's wrong with just starting that at boot? – Attie – 2018-08-08T13:23:44.513

I need to run terminal commands in pure terminal before it starts the GUI, but then I want to start the GUI. However, when I log into the pure terminal on other windows (using CTRL+ALT+F[1-6]), I dont want it to start a GUI unless there is no GUI running. I also only want to have to log in from the pure terminal login prompt, and not the login to start the service, and then login at the lock screen. – Mark Deven – 2018-08-08T13:38:37.327

No answers