This question already has answers here:
UBUNTU: XOpenDisplay(NULL) fails when program run in boot sequence via rc.local
(2 answers)
Closed 7 years ago.
I have to run a bash script on bootup which opens couple of terminals and runs some command in each terminal.
test.sh (My bash file)
#!/bin/bash
sleep 10
gnome-terminal --tab-with-profile="Default" -e 'bash -c '\''export TAB=1; mkdir /home/naman/Desktop/test_folder'\'
I have created a testjob.conf inside /etc/init/ :
testjob.conf (Upstart config file)
description "A test job file for experimenting with Upstart"
author "Naman Kumar"
start on runlevel [2345]
exec echo Test Job ran at `date` >> /var/log/testjob.log
exec bash /home/naman/Desktop/test.sh
Now, the problem is testjob.conf is not able to run the test.sh file on bootup (or it runs it but does not create a folder test_folder). If I remove the last line from testjob.conf : exec bash /home/naman/Desktop/test.sh, everything works and when I do cat /var/log/testjob.log, I get the correct output but if the last line is there, cat /var/log/testjob.log does not give the latest output.
I have also tried updating /etc/rc.local with : bash /home/naman/Desktop/test.sh but that also does not seem to be running the test.sh script on bootup
I am not sure whether they run the scripts but are not able to create the folder or they are not even able to run the script on bootup.
Note: I can not use System -> Preferences -> Startup Applications because I don't have any monitor, so the desktop application does not run. (I am running it on a Single Board Computer with no monitor).
Does anyone know what is the issue here and why is the test.sh script not running properly on bootup?
Thanks in advance.
Naman
Cong ma is pretty close on this. Sysvinit is for system level daemons. It has no idea for users. That means it doesnt have a way to interact with your window system (or gnome).
Further: without a monitor, what would you expect gnome-terminal to do? gnome-terminal would open up a terminal on the monitor: which you can't see.
What you should look at is taking your commands (date, etc) and putting them in /etc/rc.local and not trying to 'olay them into a different terminal or anything. Just literally run the commands there.
Related
I have created a simple HelloWorld application.
I want to autostart my application in OpenWRT(19.07.1) just after boot up.
The application should be started automatically after the shell prompt comes.
My helloworld application is in /usr/bin
I want to start this application automatically after bootup in openwrt
here is what I have created in /etc/init.d/script.sh
#!/bin/sh
START=10
start()
{
echo start
/usr/bin/helloworld
}
then
chmod +x script
/etc/init.d/script enable
After this I rebooted
I tried the above steps, but after rebooting no changes are reflected
manually I'm able to run my application.
Please help to resolve this issue.
Can anyone please write script for me??
Your shebang line,
#!/bin/sh /etc/rc.common
is wrong: it causes the shell to read and execute /etc/rc.common instead of the current file. Change it to
#!/bin/sh
instead, and it should now work.
If you have /usr/bin/whatnow:
#!/bin/sh /usr/local/bin/helpers
This part of the script will never be interpreted by the shell.
and /usr/local/bin/helpers:
#!/bin/sh
echo "This is the helper!"
then running whatnow will output This is the helper!.
Create a procd script as described in OpenWRT procd init script example. Place your script in /etc/init.d/<filename>.
It can look like this:
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=95
STOP=01
start_service() {
procd_open_instance
procd_set_param command /bin/sh "/var/myscript.sh"
procd_close_instance
}
There is many more options available in the manual.
On my raspberry pi, I have entered the following entry in my crontab using crontab -e (without sudo):
* * * * * echo "Hello World" &>> /home/pi/test.txt
Just as a test, that is.
After restarting cron (sudo /etc/init.d/cron restart) the test.txt file is created in /home/pi/, but the content remains empty.
Why?
If I run this without the asterisks in my ssh terminal on the Rasberry Pi, it works fine.
I got to this point because my goal is to run a python script and log any errors, because sometimes it stops running and I don't know why. Hence my need for logging.
Thank you for your help!
P.S. I have the same problem on my Orange Pi that runs Raspbian (Debian Buster), but there cron doesn't work for some reason so there I am using rc.local to run my scripts on boot. But the same problem arises: Log file is created but no content is added.
It appears that Raspbian is using dash as the default shell for cron. dash is sh compliant and not bash compliant. That means that you cannot use &>>. You must use >> output.log 2>&1 instead.
You're saying that your goal is to run a Python script. There's a catch with that too. Python's buffering output so if it's too short it won't appear in your log file by default. You can use python -u for unbuffered output.
I hope that my answer makes sense.
I'm on ubuntu 17.04, and I'm trying to execute some commands in sequence, so I have written this shell script:
#!
sudo java -jar ~/Desktop/PlugtestServer.jar
sudo /opt/lampp/lampp start
sudo node httpServer.js
The problem is that after the first command, it execute PlugtestServer and then stop on it, because it is a server and continue to execute it. There is a command in order to automatically open a new terminal and execute PlutestServer in it?
There is way to open a new terminal window and execute command in it using gnome-terminal
The sample format for command is:
gnome-terminal -e "command you want to execute"
gnome-terminal -e "./your-script.sh arg1 arg2"
Hope that helps!!
Your script stays on the first command showing output, you can make the shell move on by adding "&" to the end of your lines. However this might still not do what you want, if you want PlugTestServer to remain running when you log out. For that you should include "nohup" which will keep the command running while piping output to a file.
So, an example:
#!/bin/sh
nohup java -jar ~/Desktop/PlugtestServer.jar > plugtest.out & #Pipes output to plugtest.out, use /dev/null if you don't care about output.
/opt/lampp/lampp start
node httpServer.js
Notice I removed sudo from the script. It's generally better to invoke the script with "sudo" unless you have specific reason to, at the very least it simplifies the commands.
I'm not sure if your second and third command "fork" or "block", so add "nohup" and "&" if you need to.
This question already has answers here:
how do i start commands in new terminals in BASH script
(2 answers)
Closed 20 days ago.
I am fairly new to Linux, so if I am referencing something with the wrong wording please let me know!
I have created the following shell file, which works perfectly:
#!/bin/bash
cd ~/Desktop/folder/
cd companion && npm start
The lines I want to add below:
Opens New Terminal with the following:
cd ~/Desktop/folder/
cd javaclient && mvn exec:exec
When I execute this shell file it works fine and runs my app, however I want to add some lines in there that would open a new terminal window ('lxterminal' works for me) and run a few commands that would start running another app. Does anyone know how I can accomplish this? Any help/suggestions will be much appreciated!
P.S. The whole idea is to run 2 apps in 2 separate terminal windows by only executing 1 shell file.
You can use built-in lxterminal programatically as,
lxterminal\
--title="MyScriptWindow" \
-e "bash -c ./somescript.sh;bash"\
bash is triggered manually at the end to prevent the terminal from closing, after the command or the script completes.
I have tried everything to make this work. login scripts, LXDE-pi autostart, cron task #reboot, init.d, and I cannot get my script running with a terminal window running in the foreground so that I can interact with it. I can get it to run but only in background. Is there any way I can get a script that simply runs: "python /home/pi/myscript.py" at startup and leaves the terminal window open with the script running for my keyboard inputs? I would rather not use the /dev/input/event if at all possible. Thanks
Simply running python /home/pi/myscript.py at startup will run your script without any terminal. So there is no window that can be kept open. The behavior you want can be achieved by starting an terminal application and let it execute your script.
e. g. using xterm:
xterm -e "python /home/pi/myscript.py"
or lxterminal:
lxterminal --command "python /home/pi/myscript.py"
I was missing a simple flag.. what I did was edit ~/.config/lxsession/LXDE-pi/autostart with
#lxterminal -e /home/pi/autoscript.sh
and in that file, I added
cd /home/pi/
python -i 2Trackmain.py
I wasn't using the -i flag, so every time I pressed Enter to move through the interactive py script, it exited the terminal, using -i will keep the window open for your interaction. And I only had to add the change directory part b/c the script called other scripts in the same directory.