I am trying to run a program automatically within a bash script after killing the LXDE session. My script consists of:

pkill lxsession;
sh /home/pi/RetroPie/EmulationStation/emulationstation

I tried this as well:

nohup & pkill lxsession & 
writevt /dev/tty1 'emulationstation'

My aim is to log out of the LXDE session and run EmulationStation on my Raspberry Pi with a bash script. I'm using pkill lxsession; to bypass lxsession's logout confirmation dialog.

As it stands, this script just gets me to the command line from a working LXDE desktop. Thanks for reading.

3 Answers 3


I don't think that is possible. You run this script from a terminal emulator that is itself running within the LXDE session. When you kill the LXDE session, you also kill the terminal and, therefore, your script.

A possible workaround would be to log in via a different tty and run your script there. What exactly are you trying to do? Would a root cronjob work?

  • I'm trying to create a shortcut on my desktop that logs out of LXDE/Xorg and then runs the emulator front end EmulationStation which cannot be run while X is running. I was fairly sure it was possible to send a command to a newly opened terminal but I could be mistaken. Thanks for your reply.
    – 66tree
    Sep 22, 2012 at 17:25

The writevt isn't available here, but I assume it just emulates tty input.

You could try starting a command in the tty before killing the X session, and have it wait until the X sessoin is killed. How about

writevt /dev/tty1 'sleep 20s; emulationstation'` & 
pkill lxsession
  • I had to remove the back-tick before the & to get your code to run. It just dropped me to tty1 just like my code above. Thank you for your suggestion though. There has to be a way to this with bash.
    – 66tree
    Sep 23, 2012 at 1:44

Try using 'screen' when you either run the script from the terminal, or when you create a launcher:

screen ./emu-script.sh

screen will keep your terminal session alive even if LXDE kills, or whatever else you have shutdown. That way your script can finish properly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.