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.
Dont EmulationStation need some sort of X server running in the background for it to work?
IF not, then try the following:
#!/bin/sh
pkill lxsession;
sleep 5
su -c sh /home/pi/RetroPie/EmulationStation/emulationstation
exit
It could also be that when you log out of your lxde session the emulationstation dosent have a usershell to open it, therefore "su -c"
I'm not sure if its going to work but I hope you solve it. :)
Related
I have a script forever.py which I want to run all the time in the background (also after that I close the terminal connected to the VM).
I used nohup python3 forever.py & and it worked, but the problem is that after some days it crashes (I guess due to memory overflow) and I need to restart it manually again.
To solve this, I did as suggested here, created a bash.sh file containing:
#!/bin/bash
until python3 forever.py; do
echo "'forever.py' crashed with exit code $?. Restarting..." 2>stderr.txt
sleep 1
done
and in the terminal, ran the command:
nohup bash bash.sh &
Currently it's running well and I hope the it restart when the program crashes.
My question is: how do I stop the execution of this?
I tried pkill nohup but it doesn't work!
Suggesting to investigate more about pkill command here:
pkill -9 -x "forever.py"
I have a Minecraft Server running on Linux.
I use to start the server, a start.sh file with following content:
(This content starts a screen session and the minecraft server)
screen -S {ScreenSession} java -Xmx2G -Xms2G -jar spigot-1.18.1.jar
If I use /restart ingame, the screen session will end and the server won't start. So I have to go into the Linux Server and start the Minecraft Server again.
My question:
How can I make it so, if I use /restart that the server will restart with a active screen session.
If have tried many things.
I hope someone can help me,
~Kitty Cat Craft
There is multiple way to achieve what you want.
If you have lot of servers, you can use a quick bash script with an auto restart like that:
#!/bin/sh
while true
do
java -Xmx2G -Xms2G -jar spigot-1.18.1.jar --nogui
sleep 5
done
When you will stop, it will wait 5 seconds then restart.
With this, you can use: screen -dmS <screenName> sh myScript.sh which will run the script into another screen. It's usefull when you run it from a script which run lot of server, like that:
screen -dmS srv1 sh srv1.sh
screen -dmS srv2 sh srv2.sh
screen -dmS srv3 sh srv3.sh
You can also, if you have only one server, just firstly use screen -S screenName. Then, when you are in the screen, run the script that restart automatically (the script that I gave at first).
Also, prefer use /stop than /restart, because spigot will try to find the script. And if it success, it will run a second time the same script, and so will have ghost process.
I'm pretty new to Linux / Raspberry PI.
I want to run a command from a shell script in a new shell window since commands like "cvlc music.mp3" (VLC PLAYER) would block the shell until playback has beenn finished.
Therefore it would be nice to export the playback command to another shell
Is this correct?
gnome-terminal && lxterminal don't seem to be an option for the distribution
for testing purpose I created two dumnmy shell-scripts:
[start.sh]
#!/bin/sh
lxterminal\
--title="MyScriptWindow" \
-e "bash -c ./exe.sh;bash"\
[exe.sh]
#!/bin/sh
echo "Hello World"
[output]
root#raspberrypi:/home/pi# ./start.sh
(lxterminal:1315): Gtk-WARNING **: cannot open display:
If I've understood correctly, you are doing all this only because you want the shell to be released at the execution of your cvlc.
You only need to detach it from shell standard output and run it as a background process
nohup cvlc music.mp3 &
is this enought ?
You could also run the program in background
$> ./test.sh &
Or use screen
Using these command you wont block your shell.
So basically, I have a bot I'm running, and I would like for it to keep running even when I exit putty.
I've tried using nohup python bot.py & but it still ends the python bot when I close the putty program. I've also tried using a run.sh file with /usr/bin/nohup bot.py & inside it. but it won't work :( is there something else I'm missing?
I have also made sure the run.sh is a executable as some other forums have suggested, and I still get can't open run
I'm kinda new to the linux terminal.
if you guys could help me out that would be awsome :)
You need to detach the terminal so that when you exit, it is still running. You can use screen or tmux or some other multiplexer.
Here is how to do with screen:
screen -S mybot -m -d /usr/bin/python /path/to/bot.py
-S give the session a name (this is useful if you want to attach later. screen -D -R mybot)
-m always create a new session
-d detach (launch the program, but then detach the terminal returning you to the prompt)
I have a PHP script with infinite loop. I need this script running forever. So, I run
php /path/to/script.php > /dev/null &
And it works in background in my current user's security context. But when I close terminal window (log off), of course, CentOS Linux kills my program.
I see two guesses: run from a different user in background or make a daemon. I need help in each situation.
Thanks a lot!
nohup is your friend.
nohup command &
I think the general solution to that is nohup:
nohup is a POSIX command to ignore the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out. The HUP (hangup) signal is by convention the way a terminal warns depending processes of logout.
nohup is most often used to run commands in the background as daemons. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected. This command is very helpful when there is a need to run numerous batch jobs which are inter-dependent.
nohup is your friend.
You could:
Install screen and run the command from there. screen is a persistent terminal session that you can leave running.
Write an init/upstart (whatever you use) script so it loads on boot
Use the pear lib system_daemon
Use cron if batch work fits the scenario better (just remember to check for running instances before you launch another, iff concurrency is an issue)
Edit: or as everybody else and their brother has just said, nohup
Using command
nohup your_command &
For example
nohup phantomjs highcharts-convert.js -host 127.0.0.1 -port 3003 &
here "phantomjs highcharts-convert.js -host 127.0.0.1 -port 3003" was my command