Can't run command line as plex in synology dsm 6

Server Version#: Version 1.21.1.3795
Player Version#: Version 4.49.2

I am trying to get command line scanning to work.

I followed this: Help running Plex Media Scanner from command line on Synology DS918+

It works as admin, but when I try:

su plex -s /bin/sh -c "scripts/plexscanner.sh"

I get su: Permission denied

I read that v6 of DSM removed root access to the shell, perhaps that is related.

I tried adding plex to the administrators group, and adding a password for plex.

I also tried running the script from a task, and have the result emailed to me (just to see if that did anything) but I get another error:

: /var/packages/Plex Media Server/Plex Media Scanner: No such file or directory

Again, the script works when I run it from shell as admin, but not as su plex or from the task running as plex.

Thanks for any support.

What is plexscanner.sh ? (Contents???)

Details needed.

I used your script, linked in my original post, just added an argument to test:

#!/bin/sh

export LD_LIBRARY_PATH="/var/packages/Plex Media Server/target"
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/volume1/Plex/Library/Application Support"

"/var/packages/Plex Media Server/target/Plex Media Scanner" --list

It works as admin, but this command prompts for a password and then denies me:

admin:~ $ su plex -s /bin/sh -c scripts/plexscanner.sh
Password:
su: Permission denied

The script works when I run it in DM’s scheduled tasks as the plex user, the issue is not being able to su, is there a work around?

What I showed was not absolute.

Basic rules of Linux:

  1. admin is only special to Synology apps
  2. admin is a non privileged user account to normal Linux
  3. The su command requires higher privilege than admin has

You don’t understand what the su command does, do you?

not looking for a lecture, just a work around. i’ll keep looking.

It was a sincere question so I could gauge how to respond.

Since you’ve made your decision, I wish you luck.

It just needed sudo before it, oops :slight_smile:

If this helps anyone else:

sudo su plex -s /bin/sh -c scripts/plexscanner.sh

Hint:

  1. admin, like plex has no special privileges in Linux. admin only means something to Synology apps.

  2. su (substitute user) is a Linux command which requires root privilege to spawn the named process as the specific user.

  3. admin, plex, chuck, or any other non-root user will get “permission denied” for this reason.

  4. sudo gates the calling username, validates it can raise to root, then executes the given command string (that which follows) as root.

FYI:

DSM 7 is entirely different. All this fuss will be for nothing in DSM 7. Everything runs as a non-privileged account.

Here is the final script, hope it helps somebody:

#!/bin/sh

# this needs to be ran as plex, example:
# sudo su plex -s /bin/sh -c "scripts/plexscanner.sh --scan -vp --section 1 --directory '/volume1/media/tv/Strangers with Candy'"

printf -v arg_list '%q ' "$@"

export LD_LIBRARY_PATH="/var/packages/Plex Media Server/target"
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/volume1/Plex/Library/Application Support"

if [ $# -eq 0 ]
then
    eval "/var/packages/Plex\ Media\ Server/target/Plex\ Media\ Scanner --help"
else
    eval "/var/packages/Plex\ Media\ Server/target/Plex\ Media\ Scanner $arg_list"
fi

I’m sure there is room for improvement, but at least now I can scan a new tv series without having to scan all 150 in the library with them :smiley:

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