0

My goal is to get a/all list/s out of the mycroft skill "List-Manager" in formated and splitted txt-files to transfer them to my Nextcloud-Notes-Skill. Sure, Hey Google and Alexa are the easiest options but I don't like them.
The bash-script I wrote does this work (formatting and splitting) in the terminal.

This is the textfile the mycroft skill uses...
{"Remind me": ["remind_item_1", "remind_item_2"], "shopping": ["mate", "book", "keyboard", "bavarian beer"]}

and I get these two textfiles
Name of the first textfile: Remind me

  • [ ] remind_item_1
  • [ ] remind_item_2

Name of the second textfile: shopping

  • [ ] mate
  • [ ] book
  • [ ] keyboard
  • [ ] bavarian beer

Before we go to the code below here somme infos. First, I suspect there is a much better way to get to the same result. I'm a selfmade "something like a programmer" and certainly not a pro and I don't want to offend anyone when I call myself a programmer. Second, I want to do it with on-board resources. Third, I like to learn new things and I never have done bash-scripting.

The monitoring of the file which changed does "incron". Every time I change the list incron starts a script:

/opt/mycroft/skills/list-manager.lb803/data.json        IN_MODIFY       /bin/bash /home/pi/my_directory/notes_skill.sh

Incron works, it starts the script below but only the first command (copy-command). I have every time the file "data_list_manager.txt" in my directory, but nothing further. Incron is allowed to act like user "pi" and "root". All the files have pi- or root-rights. It stops after the "cp"-command. And I don't why.
In this version of code the result are only two list. In the moment it is okay, and I change it if I have a solution for ma question.
The directory reference /bin/... before the commands "echo" "sed" is, because I have read that the "incron" works different like the Terminal and needs the directory-name of the commands.
Thank you very much for your support!

#!/bin/bashcp 
cp /opt/mycroft/skills/list-manager.lb803/data.json /home/pi/my_directory/data_list_manager.txt
#wait
foo="$(/bin/cat /home/pi/my_directory/data_list_manager.txt | /bin/sed s/[[{}\"]//g)"
foo="$(/bin/echo "$foo" | /bin/sed -e s/,[[:space:]]/@@/g -e s/:[[:space:]]/@@@@/g -e s/[]]/@@@@/g)"
foo="$(/bin/echo "$foo" | /bin/sed -e s/@@@@@@/\\n/g -e s/@@@@/\\n@@@/g)"
/bin/echo "$foo" >/home/pi/my_directory/splitfile.txt
/usr/bin/split -l2 /home/pi/my_directory/splitfile.txt
#wait
nam="$(/bin/cat /home/pi/my_directory/xaa | /bin/sed q)"
foo="$(/bin/cat /home/pi/my_directory/xaa | /bin/sed '2!d')"
foo="$(/bin/echo "$foo" | /bin/sed -e s/@@@/\-\ [\ ]\ /g -e s/@@/\\n\-\ [\ ]\ /g)"
/bin/echo "$foo" >/home/pi/my_directory/Listen/"$nam".txt
nam="$(/bin/cat /home/pi/my_directory/xab | /bin/sed q)"
foo="$(/bin/cat /home/pi/my_directory/xab | /bin/sed '2!d')"
foo="$(/bin/echo "$foo" | sed -e s/@@@/\-\ [\ ]\ /g -e s/@@/\\n\-\ [\ ]\ /g)"
/bin/echo "$foo" >/home/pi/my_directory/Listen/"$nam".txt
nam="$(/bin/cat /home/pi/my_directory/xac | /bin/sed q)"
foo="$(/bin/cat /home/pi/my_directory/xac | /bin/sed '2!d')"
foo="$(/bin/echo "$foo" | /bin/sed -e s/@@@/\-\ [\ ]\ /g -e s/@@/\\n\-\ [\ ]\ /g)"
/bin/echo "$foo" >/home/pi/my_directory/Listen/"$nam".txt
nam="$(/bin/cat /home/pi/my_directory/xad | /bin/sed q)"
foo="$(/bin/cat /home/pi/my_directory/xad | /bin/sed '2!d')"
foo="$(/bin/echo "$foo" | /bin/sed -e s/@@@/\-\ [\ ]\ /g -e s/@@/\\n\-\ [\ ]\ /g)"
/bin/echo "$foo" >/home/pi/my_directory/Listen/"$nam".txt
subduck
  • 1
  • 2
  • How do you know that _It stops after the "cp"-command_? – Armali Jul 24 '21 at 20:04
  • The cp command works because the file is copied. I tried it several times --> delete the file, start the process and it copied the file but nothing further happens. – subduck Jul 24 '21 at 20:15
  • To truly see what goes on in the script, you can add the line `set -x; exec 2>/tmp/logfile` at its start and look into the logfile afterwards. – Armali Jul 24 '21 at 20:26

0 Answers0