I am a beginner with just basic understanding of programing. I am trying to enable a script that would copy certain files each time USB memory is mounted.
I am using OSMC version of kodi.
As i understand, there are two ways to do this, udev rules and systemd service. I have went for the systemd as it was suggested as better somewhere and it did seem simpler.
What i have done so far
1. Created trigger.sh
- Code: Select all
#!/bin/sh
cp /media/Jet/{video01.mkv,video02.mkv,video03.mkv} /home/osmc/.kodi/userdata/video
Jet is the name of the usb stick. I understand it will always have to be named that way and that files will always have to be named as they are.
2. I have created unit copy.service in /etc/systemd/system
- Code: Select all
[Unit]
Description=My flashdrive script trigger
Requires=media-Jet.mount
After=media-Jet.mount
[Service]
ExecStart=/home/osmc/.kodi/userdata/video/trigger.sh
[Install]
WantedBy=media-Jet.mount
3. I have executed chmod u+x for the trigger.sh
4. enabled service with sudo systemctl enable copy.service
Now, executing the trigger.sh itself works and the files are copied to the desired folder with no problems.
Mounting the usb does something, but does not copy files.
Here is the result of systemctl status copy.service
- Code: Select all
osmc@osmc:~$ systemctl status copy
* copy.service - My flashdrive script trigger
Loaded: loaded (/etc/systemd/system/copy.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2018-07-25 13:24:01 CEST; 1s ago
Process: 841 ExecStart=/home/osmc/.kodi/userdata/video/trigger.sh (code=exited, status=1/FAILURE)
Main PID: 841 (code=exited, status=1/FAILURE)
Jul 25 13:24:00 osmc systemd[1]: Started My flashdrive script trigger.
Jul 25 13:24:00 osmc trigger.sh[841]: cp: cannot stat '/media/Jet/{video01.mkv,video02.mkv,video03.mkv}': No such file or directory
Jul 25 13:24:01 osmc systemd[1]: copy.service: Main process exited, code=exited, status=1/FAILURE
Jul 25 13:24:01 osmc systemd[1]: copy.service: Unit entered failed state.
Jul 25 13:24:01 osmc systemd[1]: copy.service: Failed with result 'exit-code'.
During my research, i have also seen that service is running script as root and not user (osmc in this case). I have tried running trigger.sh as root (by using sudo su and then running script) and it also works with no issues.
Also worth noting is that the location of the files is not important. I have chosen this one as it is the home of playlists folder, but it can be changed to any other location.
Any help would be highly appreciated.