I'm rather new to scripting with the shell (I started on Wednesday) and encountered a problem that left me clueless.
I moved to an old house recently and the sound of the 433mhz door bell is too quiet. Since I always wanted to start playing around with a raspberry pi and my wife allowed me to get a new toy, I got one.
Now the pi receives the signal from the door bell's sender and activates several wireless sockets around the house, making it impossible to not notice that someone is at the door.
My first script was in php, but the infinity loop waiting for the signal took too much ressources and I wanted to optimize it - so I made some shell scripts.
I made the php script a daemon, because I restart the pi sometimes and didn't want to forget starting the 'bell expander'. That worked well.
Now I made my shell script a daemon and that works not so well. It starts, idles at low cpu load and waits for signals. It receives them, logs the time and such but does not execute the script that controls the wireless sockets. And I have no clue why.
Please have mercy with my script...
First script, started as a daemon, listens for incoming signals, logs some stuff and triggers the second script (well, at least it should...)
/home/pi/tuerklingel_ueberwachung:
The second script calls all the different scripts that activate/deactivate the wireless sockets. I seperated each of the scripts so that I don't have to restart the daemon when I change something and to control the sockets individually, like how long they are active and so on. Some sleep for a few seconds because they activate flashing lights, for example.
/home/pi/tuerklingel_meldung
And this is the init script:
The weird thing is - it works like a charm when I execute the /home/pi/tuerklingel_ueberwachung manually. But if it runs as a daemon, it doesn't execute /home/pi/tuerklingel_meldung. And I have no idea why...
The daemon runs as the user pi, the user that owns all the scripts. chmod a+x is set for every script.
It doesn't matter how I try to call /home/pi/tuerklingel_meldung, it doesn't work.
I tried
. /home/pi/tuerklingel_meldung
/home/pi/tuerklingel_meldung
/bin/bash /home/pi/tuerklingel_meldung
sh /home/pi/tuerklingel_meldung
and possibly some other variations that I don't remember at the moment.
OK, not all is clear for me yet, but lets try to understand what you did /do ... and what is failing...
Quote:
it works like a charm when I execute the /home/pi/tuerklingel_ueberwachung manually.
OK but then
Quote:
But if it runs as a daemon, it doesn't execute /home/pi/tuerklingel_meldung.
What is the difference between both ? because saying " if it runs as a daemon" doesnt tell how that is achieved... If its thru your init script ? If so did you try manually your execution using the init script AND after try using cron/at to launch only tuerklingel_ueberwachung and compare
You try, and give us the results I am tempted to say when you run a script that work ( interactive mode) and does not when called in batch mode, look carefully at your environment, you have something the batch mode is unaware that it need to properly execute what you want...
Thank you for your answers and sorry for anything unclear. English is far from being my first language and scripting is really new for me.
I'll try to explain.
The init script starts "tuerklingel_ueberwachung" (door bell monitoring) as a daemon. It runs in the background and waits for incoming signals.
Everything seems ok, the logging works and I even get log entries for the last if-statement, it just doesn't execute the line "/bin/bash /home/pi/tuerklingel_meldung" (door bell report), no matter how I try to call it. The variables get set, the line gets logged, but the script tuerklingel_meldung does not get executet.
I added a line to tuerklingel_meldung to log if it gets called, but nothing happens. So the error must be in the daemonized script. Or the process of... uhm... daemonization...
If I start the script "tuerklingel_ueberwachung" manually from the shell, like ./tuerklingel_ueberwachung, it listens, logs and executes the script for reporting like I want it to, no problem at all, just one loud cacophony of wireless door bells all over the house.
I used relative and absolute paths, but neither did work.
I executed the init script manually, like vbe asked me to, and it worked, too. When started via cron the same faulty behaviour occurs.
When started via cron the same faulty behaviour occurs.
We agree executing "tuerklingel_ueberwachung" via cron or using at, yes?
In which cse you must have something set in your environment missing for the batch mode to work most likely like Jim and I think, a variable, or $PATH settings
Try sourcing your environment ( add tests to remove interractive parts lik TTY business or it will complain... ) as first ( well second...) line of your "tuerklingel_ueberwachung" script and test again in batch mode
We agree executing "tuerklingel_ueberwachung" via cron or using at, yes?
Yes, I executed "tuerklingel_ueberwachung" via cron and had the same behaviour like running it as daemon.
I don't understand "sourcing your environment"? Like env/printenv?
Calling env from the manually started tuerklingel_ueberwachung returns
while calling env from the daemon returns significantly less lines:
soooo... There's a difference and that should be the problem, shouldn't it? I'm pretty sure I don't need this ls_colors thing, but PATH has to be adjusted - just like you guys guessed - and maybe other vars too?
Staring at above tuerklingel_ueberwachung again and again for a long time, some questions come up:
- is date executed correctly, so NOW=`date +"%d.%m.%Y, %R:%S"` and TIMESTAMP=`date +"%s"` are being set? If, say, TIMESTAMP is empty or unset, none of the if branches will be entered even if TRIGGERED is initialized to 0 , as 0 won't be -lt ""
- what is jq doing? Is it correctly executed without a valid PATH? If not, the main if branch might be entered but none of the "sub-ifs", RING will remain 0 , and tuerklingel_meldung again wouldn't be executed.
Put in some echo/printf statements to log the contents of above variables to a file. You might want to execute with the -x option to bash set.
Is it on purpose that you mix the (deprecated) `...` and $(...) versions of "command substitution"?
I'm trying to use a shell script to compile and execute a java file. The java classes are using sockets, so there is a client.java file and a server.java file, each with their own shell script. I also want to handle the command line arguments within the shell script, not the java classes. The... (1 Reply)
I need to write something that will read and execute all the files(Mainly executable scripts) inside one or more folders; in other words, a continuous chain with a break when finished. I'm new to shell and need syntax help. I'm on Ubuntu 12.10-Gnome btw.
Here are some main highlights I think... (2 Replies)
Say i have a simple example:
root@server # cat /root/scripts/test.sh
while sleep 5
do
echo "how are u mate" >> /root/scripts/test.log
done
root@server #
Instead of using rc.local to start or another script to check status, I would like make it as daemon, where i can do the following:
... (2 Replies)
Hi all,
I am getting : No such file or directory while executing a shell script. But i have that corresponding file in the corresponding path. It also have executable rights. Please help me out in this
Thanks in advance.
Ananthi.U (7 Replies)
Colleagues,
i have an jsp application which uses a servlet for controlling the request. the servlet uses a java class that will invoke a shell script. when i involked a shell script using java's runtime.exec command , it didnt work...
applications used are tomcat5, Fedora 6 and java1.5.0_09... (1 Reply)
Hello Everybody
I have a shell script file which contains certain intialisation.Initialisation section is around 20 lines.This initialisation section is required by 20 shell script files.
Intialisation shell script contains only initialisation of variables and it is not a good practise to... (2 Replies)
I have simple shell script that I run as cron job every hour of the day. I would like to make it a daemon that runs far more frequently like every 30 seconds or so, but I have never made daemon before. How can I do this?
-Sam (7 Replies)
Hi
How can i dynamically read files names from a list file and execute them from a single shell script.
Please help its urgent
Thanks in Advance (4 Replies)