0

I have modified an open-source program called mosquitto that I run using the command ./mosquitto -c ../mosquitto.conf -v. The mosquitto program will run indefinitely until you quit it using ctrl+c.

As part of my testing, I want to create a bash script that runs the program and saves all of the logs (which are printed to the screen) to a text file, which it will then parse to determine some statistics. I am redirecting the output to a file as stated on this stackoverflow post, but nothing is being saved (the logs are still print to the terminal). Does anyone know what the issue might be? Is there some other method I could use?

#!/bin/bash

cd ../ && make && cd src
./mosquitto -c ../mosquitto.conf -v >> logs.txt
annedroiid
  • 6,267
  • 11
  • 31
  • 54
  • 1
    What happens if you use `./mosquitto -c ../mosquitto.conf -v 2> logs.txt` instead? – Scott Hunter Oct 31 '17 at 01:37
  • or `&>>` to redirect both stdout and stderr. – karakfa Oct 31 '17 at 01:39
  • You can send the output of your `bash` script to a log file which will help you avoid printing it on the terminal. Also, a search in google says that logs are configured in the `mosquitto.conf` file [Check This](http://www.steves-internet-guide.com/mosquitto-logging/) – mathB Oct 31 '17 at 02:35
  • That's exactly what the last line `./mosquitto -c ../mosquitto.conf -v >> logs.txt` is attempting to do. I'm saying that the normal method that otherstackoverflow says would work is not working. – annedroiid Oct 31 '17 at 02:43
  • Thanks about the mosquitto.conf tip, I didn't realise I could set it in the config. – annedroiid Oct 31 '17 at 02:43
  • @annedroiid, no I meant the output of the `bash` script, not the output of the `mosquitto` command. Let us know if setting `logs` in the `conf` fixes your issue. – mathB Oct 31 '17 at 02:46
  • As I stated above, the reason I wanted to output the logs into a file was so that later in the same script it could do some analysis on them. So just outputting the results of the bash script wouldn't work, unless I wanted to be silly and have two bash scripts (one to run the program, then one to run the one that runs the program). – annedroiid Oct 31 '17 at 02:51

1 Answers1

-1

I have to presume that the reason why it won't redirect the output is due to the way Mosquitto is written, particularly since as mathB pointed out there is a flag in the configuration file which can set the output of the logs to a file.

annedroiid
  • 6,267
  • 11
  • 31
  • 54