Why won't sonarr run this custom script?

Some time back I wrote this post, about wanting to have the parent show’s folder be touched so that the last-modified timestamp would be updated on OSX.

I was graciously provided with an elegant short custom script that seems like it should do the trick:

#!/bin/bash
touch "$sonarr_series_path"/datetime

Simple right? Except that Sonarr never, EVER, runs it. And I can’t figure out why. It’s definitely set as the custom script, run On Grab, On Download, On Upgrade, and On Rename. Path is:

/Users/media/Desktop/series_touch.sh

(media is my account name on this machine).

The script is in the correct location… I can see nothing wrong… It has full read & write permissions for everyone. Oh and I should add that the test in sonarr succeeds.

Why won’t it execute? Anyone have any ideas?

See:

Setting the script to /bin/bash and the arguments to the script should fix it up.

Thanks but I’m afraid I don’t know how to do that. I’m a developer but never spend any time with shell scripting. Can you point me more to what needs doing?

Like so:

Oh! Excellent… thanks! Have set it, will see how it does.

Well sadly, it doesn’t quite work. It does touch the file in question, however the modified date of the folder as reported by MacOS, is not changing.

I’m wondering if maybe creating/touching the datetime file and then immediately deleting it, might do the trick. Going to play around and see if I can get that to work.

Hot damn, that appears to have done the trick. Why a simple touch alone isn’t enough, I can’t say… but touching and then removing, is working! Will report back if at some point it starts to fail…

You could just touch the folder with:

#!/bin/bash
touch "$sonarr_series_path"

It’s what I do.

Oh holy crap. Can’t believe I never thought of that… should totally work. Will test!!

The issue was presumably that your script would create a ‘datetime’ file the first time it was called for a show, which should have correctly updated the folder’s modified timestamp. However, any other time the show was updated, that ‘datetime’ file already exists and updating the a file’s timestamp wouldn’t affect the timestamp on the folder…

Hmmm… that’s interesting, I understood that if any file inside a folder is modified (including a touch), then the parent folder is effectively updated. And I have seen the “old” script work correctly sometimes, but not consistently. So I don’t think it’s as absolute as what you’re saying. I think there’s a bug somewhere that causes it to fail a majority of the time, but not all the time. Not a bug in Sonarr mind you, but in the OS. I wonder if that approach would work or not (or somewhere in between) on other OSes.

It’s exactly how it works though, and it describes your intermittent behaviour:

$ mkdir Folder; stat -f "%Sm" Folder; sleep 10; touch Folder/file; stat -f "%Sm" Folder; sleep 10; touch Folder/file; stat -f "%Sm" Folder 
Mar 14 19:53:31 2017
Mar 14 19:53:41 2017
Mar 14 19:53:41 2017

The folder’s timestamp (first timestamp) updated (second timestamp) when a file was created ten seconds later, but not when that file was touched again another ten seconds later (third timestamp).

Ahhh of course, duh. First time the file is created, it’s a valid update of the parent, but not on subsequent touches… And on occasion I’ve deleted the date time file manually which would of course mean next time, it will update just fine… Makes complete sense… I appreciate the clarification!

Well sadly, this did not work. This morning an episode of The Americans was downloaded, renamed, put in the proper place, etc. however the parent folder was NOT touched and the modification date is still from a week ago.

I’m going to go back to my previous approach (creating and deleting a file in the parent directory) and see how that does.

Confirmed, my more complicated approach of creating the date time file inside the parent directory and then deleting it, works. 3 shows downloaded last night, all 3 had their modified dates updated. Not sure why the simpler more direct method failed me, but this one is 3-for-3 so far…

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.