muzicman0 84 Posted September 12, 2025 Posted September 12, 2025 (Hopefully I put this in the right section) I have a bash script on my Ubuntu Emby Server that monitors directories for new files and will refresh the library if it detects a new video file. It used to work fine, but stopped working recently. I can't figure out why. If I run this command in terminal: curl -X POST "http://10.3.0.124:8096/emby/Items/14176/Refresh?Recursive=true&MetadataRefreshMode=Default&ImageRefreshMode=Default&ReplaceAllMetadata=false&ReplaceAllImages=false&api_key=xxxxxxxxxxxxxxxxxxxxxx" -H "accept: */*" It works as expected. In the script: ... COMMAND='curl -X POST "http://10.3.0.124:8096/emby/Items/14176/Refresh?Recursive=true&MetadataRefreshMode=Default&ImageRefreshMode=Default&ReplaceAllMetadata=false&ReplaceAllImages=false&api_key=xxxxxxxxxxxxxxxxxxxxxx" -H "accept: */*"' ... $COMMAND It doesn't work. I have even tied to just use the command in the script and not store it in a variable, but it still doesn't work. Any ideas? (Also, to be clear, according to the logs at least, it is detecting the new file, but the library isn't refreshed) ------------------------------------------------------------------------------------------------- Complete script is below, just in case context helps. Just don't laugh at my coding skills. I am great at taking code from google and making it do what I want, but I would never consider myself a developer. #!/bin/bash WAIT_SEC=15 PATTERN="[a-zA-Z\(\) ].*\.(mkv|ts|mpg|mp4)$" COMMAND='curl -X POST "http://10.3.0.124:8096/emby/Items/14176/Refresh?Recursive=true&MetadataRefreshMode=Default&ImageRefreshMode=Default&ReplaceAllMetadata=false&ReplaceAllImages=false&api_key=xxxxxxxxxxxxxxxxxxxxxx" -H "accept: */*"' LOGFILE="/home/muzicman0/scripts/logs/Monitor_TV.log" ARCHIVEDLOGFILE="$(dirname $LOGFILE)/Archived/Monitor_TV.log" MONITORDIR="/mnt/Media_1/TV/TV/" LOGFILESIZELIMIT=40000 #Max log size in bytes mkdir --parents "$(dirname $LOGFILE)/Archived" #Check Log file size and delete if appropriate echo "[$(date)] Checking Log file to see if it is over $LOGFILESIZELIMIT bytes." >> $LOGFILE LOGSIZE="$(stat --format="%s" "$LOGFILE")" echo "[$(date)] Current Log file is $LOGSIZE bytes." >> $LOGFILE if [ "$LOGSIZE" -gt "$LOGFILESIZELIMIT" ]; then mv -f "$LOGFILE" "$ARCHIVEDLOGFILE" sleep 2 echo "[$(date)] Previous $LOGFILE was over $LOGSIZE bytes. It was archived." >> $LOGFILE fi echo "[$(date)] Start monitoring media files..." >> $LOGFILE inotifywait -m -r -e close_write --format '%w%f' "${MONITORDIR}" | while read NEWFILE do if [[ "${NEWFILE}" =~ .$PATTERN ]]; then # Does the file end with a video file extension? echo "[$(date)] The file '$NEWFILE' appeared in directory '$MONITORDIR'" >> $LOGFILE echo "[$(date)] Trigger Emby library scan in $WAIT_SEC seconds..." >> $LOGFILE sleep $WAIT_SEC $COMMAND echo "[$(date)] Library refreshed." >> $LOGFILE #Check Log file size and delete if appropriate echo "[$(date)] Checking Log file to see if it is over $LOGFILESIZELIMIT bytes." >> $LOGFILE LOGSIZE="$(stat --format="%s" "$LOGFILE")" echo "[$(date)] Current Log file is $LOGSIZE bytes." >> $LOGFILE if [ "$LOGSIZE" -gt "$LOGFILESIZELIMIT" ]; then mv -f "$LOGFILE" "$ARCHIVEDLOGFILE" sleep 2 echo "[$(date)] Previous $LOGFILE was over $LOGSIZE bytes. It was archived." >> $LOGFILE fi fi done
Luke 42077 Posted September 12, 2025 Posted September 12, 2025 Hi, did you check the server log to see if your request was received?
muzicman0 84 Posted September 12, 2025 Author Posted September 12, 2025 These are the relevant log entries from about a 35 seconds after the last time the script was triggered. 2025-09-12 08:30:16.755 Info Server: http/1.1 POST http://host2/emby/Sessions/Capabilities/Full?X-Emby-Client=Emby Web&X-Emby-Device-Name=Google Chrome Windows&X-Emby-Device-Id=198de81c-6e93-48a9-a7b3-8f1c2857dc43&X-Emby-Client-Version=4.8.11.0&X-Emby-Token=x_secret1_x&X-Emby-Language=en-us&reqformat=json. Source Ip: host3, UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 2025-09-12 08:30:16.756 Info Server: http/1.1 Response 204 to host3. Time: 0ms. POST http://host2/emby/Sessions/Capabilities/Full?X-Emby-Client=Emby Web&X-Emby-Device-Name=Google Chrome Windows&X-Emby-Device-Id=198de81c-6e93-48a9-a7b3-8f1c2857dc43&X-Emby-Client-Version=4.8.11.0&X-Emby-Token=x_secret1_x&X-Emby-Language=en-us&reqformat=json 2025-09-12 08:30:16.801 Info App: Sqlite: 284 - automatic index on LastWatchedEpisodes(SeriesPresentationUniqueKey) I don't really know what I am looking for though. My guess is it is something within the script that is an issue since the command works completely fine outside the script. Relevant log entries from my script (just to match up time): [Fri Sep 12 08:29:39 AM PDT 2025] The file '/mnt/Media_1/TV/TV/Star Trek Strange New Worlds/Season 03/Star Trek Strange New Worlds - S03E10 - New Life and New Civilizations.mkv' appeared in directory '/mnt/Media_1/TV/TV/' [Fri Sep 12 08:29:39 AM PDT 2025] Trigger Emby library scan in 15 seconds... [Fri Sep 12 08:29:54 AM PDT 2025] Library refreshed. [Fri Sep 12 08:29:54 AM PDT 2025] Checking Log file to see if it is over 40000 bytes. [Fri Sep 12 08:29:54 AM PDT 2025] Current Log file is 17103 bytes.
Luke 42077 Posted September 12, 2025 Posted September 12, 2025 Well the url that you are posting to, do you see that in the log?
muzicman0 84 Posted September 12, 2025 Author Posted September 12, 2025 assumign you are saying that the the API command (the URL) should be in the log, then no. The only thing I see is what I posted above. Those are the only log entries that are close enough to the time the script triggered that are showing in the log. This is why I think the command is not even being sent, I just don't know why since it used to work. Don't think it is an actual Emby issue, was just hoping someone could help that might know something more than I do in Bash. It does show up in the log when I run it outside the script (IE: direct from the terminal): 2025-09-12 08:39:24.044 Info Server: http/1.1 Response 204 to host4. Time: 1ms. POST http://10.3.0.124:8096/emby/Items/14176/Refresh?Recursive=true&MetadataRefreshMode=Default&ImageRefreshMode=Default&ReplaceAllMetadata=false&ReplaceAllImages=false&api_key=x_secret2_x
Luke 42077 Posted September 12, 2025 Posted September 12, 2025 OK so then yea it’s not even getting to the server. Maybe being denied access? You can test by running the script under sudo
muzicman0 84 Posted September 12, 2025 Author Posted September 12, 2025 Maybe. But it shouldn't be. and when I run the command in terminal it isn't denied.
Luke 42077 Posted September 12, 2025 Posted September 12, 2025 Maybe try running the whole script from the terminal to see if you get an error message there.
muzicman0 84 Posted September 12, 2025 Author Posted September 12, 2025 Very fruitful. curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535 curl: (3) URL rejected: Bad hostname now I just have to figure out why it is happening.
Solution muzicman0 84 Posted September 12, 2025 Author Solution Posted September 12, 2025 Well, I fixed it, but still don't know why it happened. I did compile a new version of curl, but that didn't fix it. So I changed the script to run the command directly instead of from a variable. I had tried that before, but now it works. no idea why it didn't work before. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now