Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
cd ${SOURCEPATH}
ls *mkv | while read LSRESULTS
do
cd ${TARGETPATH}
if [ ! -a "${LSRESULTS}" ]; then
ln "${SOURCEPATH}${LSRESULTS}" "${TARGETPATH}${LSRESULTS}"
fi
done
#END#
Above is a small script I wrote because I don't want my media streamer (WD TV Live) to have write access to my movie files but it needs to have write access to the directory so it can write the meta data and cover art in the directory. So I'm keeping my movie files in a secure directory and then using this script to create link to the secure movie files in another directory that my stream has NFS write access to.
On a headless Debian system how would I set to script above to run from the cron system, let's say, maybe one an hour.
Also, does anyone see any problems with the script above. I don't want it to have to create the link every time it runs if the link is already there. Let me know if you see any problems please. Thanks.
As a possibility, create a group media, run the media streamer under a different user (X) who belongs to group media, change the media files to permit read only access for group media.
Then give user X write access to the directory. Now it can write to the directory but cannot modify the media files.
Sefyir How can I run the media streamer under anything, it's a device that can read Windows and Linux (Samba & NFS) shares. If I can dictate what user/group it runs under that would be pretty awesome. Let me know how if there is a way. Thanks.
[The West Wing]
path = /media/Shared/TV/The West Wing
writeable = yes
guest ok = yes
force user = X
Now when a user accesses that share, they assume the permissions of X.
Also - check man smb.conf
Code:
force user (S)
This specifies a UNIX user name that will be assigned as the default user for all users connecting to this service. This is useful for sharing files. You should also use it carefully as using it incorrectly can cause
security problems.
This user name only gets used once a connection is established. Thus clients still need to connect as a valid user and supply a valid password. Once connected, all file operations will be performed as the "forced user", no
matter what username the client connected as. This can be very useful.
In Samba 2.0.5 and above this parameter also causes the primary group of the forced user to be used as the primary group for all file activity. Prior to 2.0.5 the primary group was left as the primary group of the
connecting user (this was a bug).
Default: force user =
Example: force user = auser
force group (S)
This specifies a UNIX group name that will be assigned as the default primary group for all users connecting to this service. This is useful for sharing files by ensuring that all access to files on service will use the
named group for their permissions checking. Thus, by assigning permissions for this group to the files and directories within this service the Samba administrator can restrict or allow sharing of these files.
In Samba 2.0.5 and above this parameter has extended functionality in the following way. If the group name listed here has a '+' character prepended to it then the current user accessing the share only has the primary
group default assigned to this group if they are already assigned as a member of that group. This allows an administrator to decide that only users who are already in a particular group will create files with group
ownership set to that group. This gives a finer granularity of ownership assignment. For example, the setting force group = +sys means that only users who are already in group sys will have their default primary group
assigned to sys when accessing this Samba share. All other users will retain their ordinary primary group.
If the force user parameter is also set the group specified in force group will override the primary group set in force user.
Default: force group =
Example: force group = agroup
Ah, you're talking about Samba, I'm using NFS. I would use Samba as a last resort. I prefer to use Linux server as a Linux server rather than making it pretend it's a Window$ server, especially since my client (WD TV Live) can actually see a Linux (NFS) server. I have used Samba in the past but I found it's configuration to be difficult.
[The West Wing]
path = /media/Shared/TV/The West Wing
writeable = yes
guest ok = yes
force user = X
Now when a user accesses that share, they assume the permissions of X.
Also - check man smb.conf
Code:
force user (S)
This specifies a UNIX user name that will be assigned as the default user for all users connecting to this service. This is useful for sharing files. You should also use it carefully as using it incorrectly can cause
security problems.
This user name only gets used once a connection is established. Thus clients still need to connect as a valid user and supply a valid password. Once connected, all file operations will be performed as the "forced user", no
matter what username the client connected as. This can be very useful.
In Samba 2.0.5 and above this parameter also causes the primary group of the forced user to be used as the primary group for all file activity. Prior to 2.0.5 the primary group was left as the primary group of the
connecting user (this was a bug).
Default: force user =
Example: force user = auser
force group (S)
This specifies a UNIX group name that will be assigned as the default primary group for all users connecting to this service. This is useful for sharing files by ensuring that all access to files on service will use the
named group for their permissions checking. Thus, by assigning permissions for this group to the files and directories within this service the Samba administrator can restrict or allow sharing of these files.
In Samba 2.0.5 and above this parameter has extended functionality in the following way. If the group name listed here has a '+' character prepended to it then the current user accessing the share only has the primary
group default assigned to this group if they are already assigned as a member of that group. This allows an administrator to decide that only users who are already in a particular group will create files with group
ownership set to that group. This gives a finer granularity of ownership assignment. For example, the setting force group = +sys means that only users who are already in group sys will have their default primary group
assigned to sys when accessing this Samba share. All other users will retain their ordinary primary group.
If the force user parameter is also set the group specified in force group will override the primary group set in force user.
Default: force group =
Example: force group = agroup
If you must use a while loop, consider to do the cd in a subshell, so the current work directory is unchanged:
Code:
(cd ${SOURCEPATH} && ls -d *.mkv) | while read LSRESULTS
But here a for loop is easier.
Code:
if cd ${SOURCEPATH}
then
for LSRESULTS in *mkv
do
if [ -f "${SOURCEPATH}${LSRESULTS}" ] && [ ! -e "${TARGETPATH}${LSRESULTS}" ]; then
ln -s "${SOURCEPATH}${LSRESULTS}" "${TARGETPATH}${LSRESULTS}"
fi
done
fi
Use -e for "target exists". Actually in the bash man page I see -a is equivalent - but it does not work for me.?
Also test the source files, -f tests for existence (if no files are found, LSRESULTS is *mkv) and ensures it is a file.
Is mkv a file extension? Then *.mkv is more precise.
Last edited by MadeInGermany; 06-09-2015 at 04:42 PM.
Reason: A " was missing
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.