0

I currently filter out data from a MQTT live stream. I then dump this datum into a csv file named mqtt.csv and the dumping process is done by executor_start_up_job.txt which is written in BASH.

I want to make the dumping of the filter daemon, i.e. in the background, and also want to make it in so that every time the system is rebooted it is done automatically. So I've concluded to write an init.d script, and contents of my code is:

#!/bin/bash
set -x

requested_command=$1

start() {

        /home/ed/start_up_job/executor_start_up_job.txt &
}
# Restart the Dump
stop() {

        killproc executor_start_up_job.txt
        echo
}
### main logic ###
case $requested_command in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        last_line=`cat mqtt.csv | tail -1`
        echo "last print line: $last_line"
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac
exit 0

Once I have inserted set -x I get the following output:


+ ./MySQL_table_update_daemon.sh start
+ requested_command=start
+ start
+ exit 0

Q: It's my first time writing an init.d and I have written my code based on this example it doesn't work, as I get the error "segmentation fault"

9
  • Have you tried running it?
    – jasonwryan
    Commented Mar 9, 2015 at 0:25
  • @jasonwryan, yeah I have, but it just says "segmentation fault"
    – 3kstc
    Commented Mar 9, 2015 at 1:17
  • 1
    Are you segfaulting on infinite recursion? It looks like on the second line of the script you are sourcing the script itself! Which will cause it to be sourced recursively again and again. Can you explain that line? (Also, MySQL_table_update_daemon.txt is a very odd name for something executable that would be found in /etc/init.d, as has been pointed out already.)
    – Celada
    Commented Mar 9, 2015 at 1:30
  • @Celada I've got shebang #!/bin/bash to make this (MySQL_table_update_daemon.txt) an executable. I've commented out the ./etc....daemon.txt and currently I am trying to make the code run from the terminal but it doesn't work. The output is just nothing, its as if I've just pushed enter from the terminal; my input to the terminal is ./MySQL_table_update_daemon.txt start
    – 3kstc
    Commented Mar 9, 2015 at 1:36
  • 1
    Run it under bash -x to see what it's doing. It might be working find except that /home/ed/start_up_job/executor_start_up_job.txt is doing nothing. By the way, that's also a very odd name for an executable. What's with the .txt suffix everywhere?
    – Celada
    Commented Mar 9, 2015 at 1:41

1 Answer 1

1

No, it will not work because you have several syntax errors.

You also have some best practices violations.

Use bash -x on your file after correcting the errors to see it run. Read your script carefully and fix the syntax errors.

Some errors:

echo "last print line: `cat mqtt.csv | tail -1"
echo $"Usage: $0 {start|stop|restart|reload|status}"
# missing ;;

I stopped looking after 3. Note also it is normal to specify paths to executable files, usually with variables. It is also not normal to execute 'txt' files. You also aren't telling the user that you support 'condrestart' .

1
  • I don't know how to use bash -x ? is this the same thing as set -x ?
    – 3kstc
    Commented Mar 9, 2015 at 2:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .