Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

#!/bin/sh
pkill lxsession;
sh /home/pi/RetroPie/EmulationStation/emulationstation

I tried this as well:

#!/bin/sh
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.

share|improve this question

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?

share|improve this answer
    
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. – BasicObject Sep 22 '12 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

#!/bin/sh
writevt /dev/tty1 'sleep 20s; emulationstation'` & 
pkill lxsession
share|improve this answer
    
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. – BasicObject Sep 23 '12 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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .