-
- Posts: 1
- Joined: Mon Jan 06, 2014 2:01 pm
- Location: Atlanta, GA USA
HowTo auto-run LXTerminal from LXDE desktop at startup
or more accurately described...
"How to automatically run (and display) LXTerminal + script after LXDE bootup has completed (from the Desktop)"
As always there are other ways to do this.
As a Pi newb, I had a time developing a script that I wanted to run 'headless' every time the Pi gets powered up.
I finally got the bash script running in LXTerminal the way I needed and wanted it to start every time the Pi got powered up into the Desktop (not command line) and then have the script shutdown the system again at the end, waiting for the next power cycle to occur. In other words, I was using the Pi as an embedded controller (without keyboard, mouse or monitor).
I chose not to run without the LXDE Desktop in control because I wanted USB drive devices to be auto-detected and mounted/unmounted and I couldn't figure a good way to get that to happen without the Desktop doing it for me dynamically (trust me, I tried).
Also, I wanted the option to add the monitor as an option to monitor progress if desired in case I wanted to follow the script execution on the GUI LXTerminal window.
I also wanted to have LXTerminal display itself while running the script in case I wanted to use it non-headless.
After struggling and Googling for a few days, I finally worked out how to make this work (and work well).
Note: This is using the Raspberry Pi V2 B board running the Raspberian rom to auto-execute an LXTerminal script in LXDE:
1. Set the Pi boot menu to boot into the GUI, not the command line.
2. Write your script and test it in LXTerminal.
3. Make sure the first line in your script is "#!/bin/bash" (without the double quotes, your choice may vary).
4. Save the script with a filename and extension you wish (I chose xxx.shl for mine)
5. Using the GUI File manager, navigate to Properties for that file and checked it to be executable. [Ok]
(Yes, I could have done it from the terminal as well)
6. Copy the file to the location you wish to access it from (I choose "/home/pi" for my scripts)
7. Open LXTerminal and type "sudo leafpad" <Enter> (no quotes) This will open Leafpad as Root.
8. In Leafpad, click [File], [Open]. Click on [Root] and then hit the [<] button twice to get the full directory tree.
9. Click your way to "etc/xdg/lxsession/LXDE/autostart". Open the autostart file.
10. Edit the autostart file to add the following on it's own line, literally:
@lxterminal --command "/home/pi/xxx.shl"
(substitute your own script file name and path, but include the double quotes) Do not use a '.' before the path in the quoted string.
11. **IMPORTANT** DO NOT add this line as the last line after the @xscreensaver line or you will never see it or execute it. (took a while to figure that out)
12. Shutdown and restart the Pi to test it.
It is a good idea to add some sleep statements to your code since the terminal closes as soon as the script completes running, if you are going to watch the execution with a monitor. Also consider adding some logical conditions that allow your code to not shutdown if that was the plan for the code function. That way you can break out into the terminal instead of being forever stuck with no way to escape the cycle. You don't need to edit any other system files to make this work and it should work for most if not all programs that are available from the Desktop.
Hope this helps some of you... it would have me.
-Androidian
"How to automatically run (and display) LXTerminal + script after LXDE bootup has completed (from the Desktop)"
As always there are other ways to do this.
As a Pi newb, I had a time developing a script that I wanted to run 'headless' every time the Pi gets powered up.
I finally got the bash script running in LXTerminal the way I needed and wanted it to start every time the Pi got powered up into the Desktop (not command line) and then have the script shutdown the system again at the end, waiting for the next power cycle to occur. In other words, I was using the Pi as an embedded controller (without keyboard, mouse or monitor).
I chose not to run without the LXDE Desktop in control because I wanted USB drive devices to be auto-detected and mounted/unmounted and I couldn't figure a good way to get that to happen without the Desktop doing it for me dynamically (trust me, I tried).
Also, I wanted the option to add the monitor as an option to monitor progress if desired in case I wanted to follow the script execution on the GUI LXTerminal window.
I also wanted to have LXTerminal display itself while running the script in case I wanted to use it non-headless.
After struggling and Googling for a few days, I finally worked out how to make this work (and work well).
Note: This is using the Raspberry Pi V2 B board running the Raspberian rom to auto-execute an LXTerminal script in LXDE:
1. Set the Pi boot menu to boot into the GUI, not the command line.
2. Write your script and test it in LXTerminal.
3. Make sure the first line in your script is "#!/bin/bash" (without the double quotes, your choice may vary).
4. Save the script with a filename and extension you wish (I chose xxx.shl for mine)
5. Using the GUI File manager, navigate to Properties for that file and checked it to be executable. [Ok]
(Yes, I could have done it from the terminal as well)
6. Copy the file to the location you wish to access it from (I choose "/home/pi" for my scripts)
7. Open LXTerminal and type "sudo leafpad" <Enter> (no quotes) This will open Leafpad as Root.
8. In Leafpad, click [File], [Open]. Click on [Root] and then hit the [<] button twice to get the full directory tree.
9. Click your way to "etc/xdg/lxsession/LXDE/autostart". Open the autostart file.
10. Edit the autostart file to add the following on it's own line, literally:
@lxterminal --command "/home/pi/xxx.shl"
(substitute your own script file name and path, but include the double quotes) Do not use a '.' before the path in the quoted string.
11. **IMPORTANT** DO NOT add this line as the last line after the @xscreensaver line or you will never see it or execute it. (took a while to figure that out)
12. Shutdown and restart the Pi to test it.
It is a good idea to add some sleep statements to your code since the terminal closes as soon as the script completes running, if you are going to watch the execution with a monitor. Also consider adding some logical conditions that allow your code to not shutdown if that was the plan for the code function. That way you can break out into the terminal instead of being forever stuck with no way to escape the cycle. You don't need to edit any other system files to make this work and it should work for most if not all programs that are available from the Desktop.
Hope this helps some of you... it would have me.
-Androidian
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Thanks so much for posting this. I'm trying to do something similar, possibly even simpler.
I just need LXTerminal to start on boot, change directories and then launch a node.js server - just two commands.
I'd like to usually run it headless, but keep the terminal window open in case I need to VNC in to monitor the process, since the app reports all user activity.
I'm a newb myself so I'm having quite a time figuring out how to do this. Does the script to open LXTerminal need to be a Python script or can something this strait-forward just be written right into the autostart file?
In either case, what commands do I need to open LXTerminal, enter commands (and if necessary, add time between them)?
I just need LXTerminal to start on boot, change directories and then launch a node.js server - just two commands.
I'd like to usually run it headless, but keep the terminal window open in case I need to VNC in to monitor the process, since the app reports all user activity.
I'm a newb myself so I'm having quite a time figuring out how to do this. Does the script to open LXTerminal need to be a Python script or can something this strait-forward just be written right into the autostart file?
In either case, what commands do I need to open LXTerminal, enter commands (and if necessary, add time between them)?
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Thanks to Androidian for the excellent instructions.
I wanted to post an update though as there appears to be a minor change on the newer Raspbian versions.
In order to get your commands to run on newer versions you need to modify the autostart file in the LXDE-pi folder and not the LXDE folder. For added confusion the LXDE folder and autostart file still exist but that autostart won't run your script.
To edit the correct folder run:
I wanted to post an update though as there appears to be a minor change on the newer Raspbian versions.
In order to get your commands to run on newer versions you need to modify the autostart file in the LXDE-pi folder and not the LXDE folder. For added confusion the LXDE folder and autostart file still exist but that autostart won't run your script.
To edit the correct folder run:
Code: Select all
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Further to waveplant's query:
You should be able to accomplish what you need by following Androidian's instructions (noting my LXDE-pi update) and creating a bash script to run your commands.
A bash script can be simply a list of commands that you want to run. Via the instructions above, you can run that bash script and thus those commands in an LXTerminal window on start up.
To create your file use your editor of choice and type your commands into the new file. However, the first line of your file must be #!/bin/bash. This tells the system to run it as a bash script. In your case your script would look something like:
Once you've written the script, save it somewhere. The convention is usually to give bash scripts a .sh extension.
In order for this script to run correctly you must set it to be executable. You can do this with the command:
You should be able to accomplish what you need by following Androidian's instructions (noting my LXDE-pi update) and creating a bash script to run your commands.
A bash script can be simply a list of commands that you want to run. Via the instructions above, you can run that bash script and thus those commands in an LXTerminal window on start up.
To create your file use your editor of choice and type your commands into the new file. However, the first line of your file must be #!/bin/bash. This tells the system to run it as a bash script. In your case your script would look something like:
Code: Select all
#!/bin/bash
cd home/pi/
node <whatever node command you want>
sleep 300 <sleep for 300 seconds, if you want>
In order for this script to run correctly you must set it to be executable. You can do this with the command:
Code: Select all
sudo chmod +x <path to your script file>
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
I'll add that if you want it to start for any user then put it inBut if you boot to CLI and log in as different users before you start the desktop, and you only want it to start when a specific user logs in, then put it in
Code: Select all
/etc/xdg/lxsession/LXDE-pi/autostart
Code: Select all
/home/<username>/.config/lxsession/LXDE/autostart
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
strttn - thanks for following up. after quite a bit of trial & error and scouring google after posting this, i found that the directory (as you posted) had changed in newer distros, which fixed the issues i was having.
i'm not sure whether the old directory is part of a clean install, but i'd updated and so the old directory still existed, hence the confusion.
i'm not sure whether the old directory is part of a clean install, but i'd updated and so the old directory still existed, hence the confusion.
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
I have tried this on my pi 3 and no luck
I have a file called statup.shl in my /home/pi folder
#!/bin/bash
cd home/pi/
ls
sleep 10
cd /
cd testing
python /testing/demo.py
and /etc/xdg/lxsession/LXDE-pi/autostart
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver splash
@lxterminal --command "/home/pi/startup.shl"
But no screen on reboot any sugestions?
I have a file called statup.shl in my /home/pi folder
#!/bin/bash
cd home/pi/
ls
sleep 10
cd /
cd testing
python /testing/demo.py
and /etc/xdg/lxsession/LXDE-pi/autostart
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver splash
@lxterminal --command "/home/pi/startup.shl"
But no screen on reboot any sugestions?
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
The location has changed in the year since that was posted. Jessie creates a users autostart file, so the changes need to be made in the users autostart.
Code: Select all
nano ~/.config/lxsession/LXDE-pi/autostart
-
- Posts: 1
- Joined: Sun Apr 03, 2016 8:48 am
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Hi, I tried to run my simulink module by following the instruction but it didn't work at all
make it executable ->test-> It's work
but when I add the file path to /etc/xdg/lxsession/LXDE-pi/autostart it not working.
Any suggestions would be appreciated. m(_ _)m
Code: Select all
#!/bin/bash
cd /home/pi
<simulink module name>_rtt/MW/<simulink module name>
but when I add the file path to /etc/xdg/lxsession/LXDE-pi/autostart it not working.
Code: Select all
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@lxterminal --command "/home/pi/startfacedetect.shl"
@xscreensaver splash
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
I'd suggest you read the post just above yours.
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
I am having issues with this as well. I can get lxterminal to start on boot, but am trying to get navit to start as well. To start the navit program in a lxterminal the command is ./navit in the directory home/pi/navit/navit. In home/pi/.config/lxsession/LXDE-pi/autostart I have the following
@lxterminal --command "/home/pi/navit/navit/./navit"
This just brings me to the GUI on boot with no terminals.
I have tried different variations but have not had any luck on getting the program to load. I am making a GPS system that I need to be headless so right now the only way is to have a keyboard attached and manually change directory and start navit. Any suggestions??
@lxterminal --command "/home/pi/navit/navit/./navit"
This just brings me to the GUI on boot with no terminals.
I have tried different variations but have not had any luck on getting the program to load. I am making a GPS system that I need to be headless so right now the only way is to have a keyboard attached and manually change directory and start navit. Any suggestions??
-
- Posts: 2
- Joined: Tue Jul 07, 2015 6:08 am
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Hi,I find @lxterminal --command "/home/pi/xxx.sh" Should be add at end on the line
add it after @xscreensaver is working for me and add before that doesn't work
I'm use pi 3.Hope it help someone:)
add it after @xscreensaver is working for me and add before that doesn't work
I'm use pi 3.Hope it help someone:)
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Sorry, folks, I've done all of the above, but terminal is not starting either I
place the line in front of a @xscreensaver or after it.
I'm using pi 3.
this script:
place the line in front of a @xscreensaver or after it.
I'm using pi 3.
Code: Select all
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@lxterminal --command "/home/pi/test.sh"
Code: Select all
#!/bin/bash
echo This is test
sleep 5
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
The script may be running to completion and the terminal closes before you see it. Test to see if it works using a script that waits for input, so the terminal will stay open until you close it.
Create a test script. I just named it "test.sh", make it executable.
Then edit the autostart file
Add this line at the bottom
Then log out and back in, or reboot. When the desktop starts you should see the terminal open in the middle of the screen, waiting for you to press a key. That will confirm everything's working, then edit the autostart file and replace "/path/to/test.sh" with the script you want to use.
Create a test script. I just named it "test.sh", make it executable.
Code: Select all
#!/bin/bash
pause(){
read -n1 -rsp $'Press any key to close the terminal...\n'
}
echo Script is running
pause
Code: Select all
nano ~/.config/lxsession/LXDE-pi/autostart
Code: Select all
lxterminal -e "/path/to/test.sh"
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Thank you kindly, will give it a try on Monday and update.
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
This worked!!!
So, can I open more than one terminal doing this?
So, can I open more than one terminal doing this?
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Sure you can. And depending on what you're doing and how you want it to work you may not need "lxterminal".
This is the auto start file for one of the Pi's at my desk (Pi3B). Since it's at my desk I use Synergy, so the Pi uses my Windows PC mouse/keyboard and I only need the HDMI and power plugged into the PI (really cuts down on cable mess and the need for another keyboard/mouse). Synergy runs in the background so I start the script directly, and I use the "@" so it will restart should it die for some reason.
I also have a 24 segment LED bargraph display that shows CPU temp and load, and that runs in the background as well, using Python.
Just to test I added a second line to run the test.sh script twice and each shows up in it's own terminal as expected.
This is the auto start file for one of the Pi's at my desk (Pi3B). Since it's at my desk I use Synergy, so the Pi uses my Windows PC mouse/keyboard and I only need the HDMI and power plugged into the PI (really cuts down on cable mess and the need for another keyboard/mouse). Synergy runs in the background so I start the script directly, and I use the "@" so it will restart should it die for some reason.
I also have a 24 segment LED bargraph display that shows CPU temp and load, and that runs in the background as well, using Python.
Just to test I added a second line to run the test.sh script twice and each shows up in it's own terminal as expected.
Code: Select all
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@/home/jimmy/.startsynergy.sh
sudo python /home/jimmy/scripts/bargraph1.py
@lxterminal -e "/home/jimmy/scripts/projects/test.sh"
@lxterminal -e "/home/jimmy/scripts/projects/test.sh"
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
This is great - in fact, a real life saver for me, since I try running
several bluetooth clients in the background, but they show errors,
while running on the foreground just fine.
Thanks for the tip for Synergy as well, will look into it.
Best regards
Alex
several bluetooth clients in the background, but they show errors,
while running on the foreground just fine.
Thanks for the tip for Synergy as well, will look into it.
Best regards
Alex
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
You can download the "still free to download" version 1.4 of Synergy for Windows/MAC/Linux here:
http://symless.com/download/free/ The software has always been free, but they now require a "donation" to download the latest version. But you don't want the latest version anyway.
Fortunately the "still free to download" version matches the 1.4 version in the RPi repository. Just use "apt-get install synergy" on the RPi.
I love it, especially since you can copy/paste across different OS. For the post above I moved the cursor over to the RPi screen, copied the text from the autostart file, then moved the cursor back to the Windows screen and pasted it right into the post.
I have a RPi1B+ with the RPF 7" touchscreen. Sometimes it's easier to do stuff using a mouse/keyboard, so I can set it on my desk (it's wireless so it's connected anyway) touch my Synergy desktop icon to start Synergy, then use my PC mouse/keyboard without plugging anything into the RPi.
http://symless.com/download/free/ The software has always been free, but they now require a "donation" to download the latest version. But you don't want the latest version anyway.
Fortunately the "still free to download" version matches the 1.4 version in the RPi repository. Just use "apt-get install synergy" on the RPi.
I love it, especially since you can copy/paste across different OS. For the post above I moved the cursor over to the RPi screen, copied the text from the autostart file, then moved the cursor back to the Windows screen and pasted it right into the post.
I have a RPi1B+ with the RPF 7" touchscreen. Sometimes it's easier to do stuff using a mouse/keyboard, so I can set it on my desk (it's wireless so it's connected anyway) touch my Synergy desktop icon to start Synergy, then use my PC mouse/keyboard without plugging anything into the RPi.
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Perfect, this will solve the major hassle of copying between the OS!
Thank u!
Thank u!
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Now I'm trying to run the test script on another pi 3, the terminal opens, but echo
command doesn't work!
Any ideas will be greatly appreciated...
command doesn't work!
Any ideas will be greatly appreciated...
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Something just came up = may be I have to add "sudo"telecom wrote:Now I'm trying to run the test script on another pi 3, the terminal opens, but echo
command doesn't work!
Any ideas will be greatly appreciated...
in front?
Will do tomorrow + update
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
No, "sudo" is not helping - my best guess - something wrong with the kernel /lxterminal.
Will update later.
Will update later.
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Sudo wouldn't be needed for the test script, there is a problem with something else. You say the echo command doesn't work, does the terminal open but the "echo" line doesn't display, or does the terminal not open at all?
Re: HowTo auto-run LXTerminal from LXDE desktop at startup
Hi. the terminal opens, but its not doing anything and I can't type on it.
I can close it, and open another terminal, which would work just fine.
Its only on one pi3, another works fine , opens and runs the script.
Regards
Alex
I can close it, and open another terminal, which would work just fine.
Its only on one pi3, another works fine , opens and runs the script.
Regards
Alex