LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-09-2015, 12:36 PM   #1
Garrett85
Member
 
Registered: Jan 2011
Posts: 332

Rep: Reputation: 6
Debian: running scrip in cron


#!/bin/bash

SOURCEPATH="/home/garrett/VideoTest/Videos2/"
TARGETPATH="/home/garrett/VideoTest/Videos1/"

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.
 
Old 06-09-2015, 12:55 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
please use [code] tags.
you probably want
Code:
/bin/ln -s "${SOURCEPATH}${LSRESULTS}" "${TARGETPATH}${LSRESULTS}"
the crontab entry should probably be like
Code:
0 * * * * /path/to/script

Last edited by schneidz; 06-09-2015 at 01:08 PM.
 
Old 06-09-2015, 01:07 PM   #3
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
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.
 
Old 06-09-2015, 01:36 PM   #4
Garrett85
Member
 
Registered: Jan 2011
Posts: 332

Original Poster
Rep: Reputation: 6
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.

Thanks schneidz I'll give that a try.
 
Old 06-09-2015, 03:10 PM   #5
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
If you use samba, you can use force-user in the config.
Something like
Code:
[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

Last edited by Sefyir; 06-09-2015 at 03:15 PM.
 
Old 06-09-2015, 04:05 PM   #6
Garrett85
Member
 
Registered: Jan 2011
Posts: 332

Original Poster
Rep: Reputation: 6
NFS, not Samba

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.

Quote:
Originally Posted by Sefyir View Post
If you use samba, you can use force-user in the config.
Something like
Code:
[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
 
Old 06-09-2015, 04:31 PM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,800

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scrip running on remote server hassan hashmi Linux - Newbie 1 03-14-2015 12:23 AM
HELP ME: Error while running tcl scrip for ZRP in NS2.33 ubuntu 10.04 vuichoigiaitri Ubuntu 1 12-02-2012 10:11 PM
Scrip issue on Debian toolbox1234 Linux - Newbie 3 01-27-2012 12:58 AM
Problems running PHP scrip in command line Hondro Programming 0 06-21-2007 02:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration