Can't run external programm from a udev-started script - linux

I'm trying to set up a automatic PDF-Viewer via a Raspberry Pi.
The problem I'm facing is that the script I started from an udev-rule is doing anything I want, except starting any external program. When I'm runnig both scripts from terminal, everything works fine as well, xpdf is launched with no problems.
This is how my scripts look right now:
startpdf (successfully executed from a udev-rule)
!#/bin/bash
/usr/local/script/pdfscript &
exit 0
pdfscript
!#/bin/bash
mkdir -p /media/usb/stick
sudo mount /dev/usbstick /media/usb/stick
/usr/bin/logger Testing the Script
sudo mkdir -p /usr/local/script/testfolder
/usr/bin/xpdf
Everything is working fine, the testfolder is created and the logger is doing fine as well. The reason for having two scripts is the short amount of time before a udev-started script is terminated.
The only problem is that xpdf won't start. I tried it with libreoffice or any other program too and I don't know what am I missing.
Please help me, It's driving me nuts :(

Related

Script exits after certain amount of time

I have this node.js Discord bot that is currently running in production. I run it locally on my Raspberry Pi (doesn't get used a lot so it's cheaper for me). Previously it worked fine, but now, after some time the script exits without logging anything special. This is the command I run in the Raspbian terminal to start the script:
node KMAR.js > plb_log.log 2> plb_error.log &
I run the same script for another bot, on the same RPi. Whenever I start them at the same time, they seem to crash at the same time aswell. This seems to be 2 weeks (sometimes 3 weeks) after I start. I do make use of node cron, but I only have something scheduled a few times a day. It doesn't seem like this cronjob would have anything to do with it.
With previous versions of the bot this wouldn't happen. However, I couldn't find differences between versions that would cause this behaviour.
If it could help, here's the repo of the project. Older versions are included aswell. https://github.com/jwsteens/plb
To summarize my problem; my code exits not quite randomly, but after a few weeks. I can't figure out why this happens, as I get no error messages and I can't find anything in my code which would lead to this issue.
You can write a script that automatically restarts the bot when it crashes or stops.
#!/bin/bash
while :
do
yournodepath yourbotpath
sleep 1
done
save it as start.sh or something
and then instead of running node . you can do
chmod 777 start.sh
./start.sh
and now it will run forever until you exit the script

Other ways for auto-start script in Kali Linux?

So I'm basically wanting to get a script to run on system boot. It's basically an SSH callback. I've tried a few ways that I've gotten to work in the past on other distributions, but having a little bit of difficulty here.
First thing I've tried was adding the /path/to/script.rb to /etc/rc.local. However, this file does not exist on the latest version of Kali Linux. I tried to create it and replicate my old Ubuntu rc.local file, but it didn't run on system startup.
Next thing I tried was creating an executable bash script in /etc/init.d/, following the update-rc.d script.sh defaults and making the file executable. Restarted and nothing. If I run the script manually, it works. I tried to redirect the output to a file in the tmp folder, but it doesn't appear that there are any errors from what I'm understanding.
Are there any other ways to get an auto run script started other than these two methods? Seem to be the most common way to get this working, but it's just not doing it for me.
Add script to
/etc/init.d
Run command:
chmod 755 /etc/init.d/script
Run command:
update-rc.d script enable

Cannot run an application from udev script

In our embedded system, we have properly set udev to run a script located in /etc/udev/scripts/mount.sh. This works very well. However, we cannot successfully run an application from inside this script.
This is very weird. We tried to write this application call in a script, say test.sh. If we call test.sh from udev script (mount.sh), nothing happened. It only works if we call test.sh from the shell.
Does anyone know what's the problem here?
Updated:
test.sh looks like:
#!/bin/sh
/usr/local/app/appipc "[header]usb,add"
appipc is just a simple Qt application to use QLocalSocket to connect to a local server by name. If we run this script in shell, it works. But not from udev script (mount.sh).
Finally we figured out that, the Qt lib was not able to load correctly if we run a Qt application from udev script. That's why we doubt it never runs. If we run a regular C application, everything works well!
This is kind of silly and negligent of us! We should consider this in advance. Thanks everyone for the time.

Raspberry Pi boot script duplicating

I am trying to run a few scripts at each boot of the raspberry pi. I have been able to verify that when they are not configured to start automatically, I can run them, and they all work exactly as intended (and in only one instance). I have tried quite a few methods of autostarting these scripts, and I have found that using a desktop entry in .config/autostart directory to be my preferred way of doing it. I have also tried editing rc.local, crontab, systemd, and entries in .config/lxsession/LXDE-pi/autostart with no more success.
The issue is that when I have the scripts running at boot, there is a duplicate of the script running (I have it set to open a new instance of LXterminal, though there are not duplicates of the terminal). The script runs at boot just fine, but I am cannot figure out why there seems to be a "ghost" version of the script too. I have the autostart commands set to write to log files that show that the scripts are running more than once. I have also tried this on a fresh raspbian install. Could someone help me figure this out? I'm at a loss on what my issue is. This is for use of Amazon Alexa.
This is what I have in /home/pi/.config/autostart/AlexaBoot.desktop:
[Desktop Entry]
Name=AlexaBoot
Exec=lxterminal -e "/bin/bash /home/pi/Desktop/alexa_boot.sh"
Type=Application
I can post what I have in the autostarted script if necessary. Thanks.
Found a fix for this. My solution is outlined on a similar Github issue, hopefully this is able to help someone with the same issue.

#reboot via crontab isnt working

IM running a VPS server on Ubuntu 14.04 minimal x86. I connect to it using putty via SSH.
On the server i have a simple script that is starting a few instances of bots
nohup node /nodebots/bot10/server.js &
I use root as a user, so all the privileges and +chmod X are set properly (in my opinion)
The idea is that my node.js program is not excelent + the service im running the bots for sometimes has reboots, server crashes etc.
Ive installed crontab and at this moment struggling to set the script to be run at boot.
Ive used various solutions including trying to boot it via init.d , adding a line to rc.local and well using crontab -e. None of it helps.
Currently the code in crontab looked the following ways
`#reboot sh /nodebots/botsrun.sh`
#reboot root /nodebots/sh botsrun.sh
#reboot cd /nodebots/ && sh botsrun.sh
None of it helped.
Im new to Ubuntu, coding and even terminal commands. I would really apreaciate any kind of help. I will be more then grateful for a step by step tutorial on what im doing wrong and what should be done.

Resources