LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   New to Linux - CRON JOB Help Needed :) (https://www.linuxquestions.org/questions/linux-newbie-8/new-to-linux-cron-job-help-needed-4175459364/)

mdexter 04-23-2013 09:22 PM

New to Linux - CRON JOB Help Needed :)
 
Hello there,

I have recently set up an FTP folder in my domain under my domain name then the following directory:

/home/mp/public_html/aoe2hdozclan.com/ftp

The ‘ftp’ folder has permissions currently set at 700

Ok, the FTP settings for my clients is:

user: aoe2hdozclan@mdexter.com
pass: guest
host: ftp.mdexter.com
port: 21

Please reason I use a generic password is because all users need something simple to login by otherwise they will not bother.

Now my question and issue is:

I am wanting to be able to have users upload their files and have read only attributes for other users so another user cannot delete the file. My web host offered 755 as permissions set on the ‘ftp’ folder as solution and this doesn't work as I have had another user login and delete my test files with 755 and the same with 700.

So Person A logs in with the details above and uploads a file called TEST.txt. Then person B logs in (from another computer and IP of course) logs in with the details above and uploads a file called IMAGE.jpg

Currently person B can see person A's file TEST.txt and then person B can deletes it and visa versa. This is not what I want, I do not want person B to come along and delete person A's files or the other way around..

I have had another person suggest to me the following, that persons message to me is:

To set up a cron job with a script command to add read only attributes once the file is uploaded to my ‘ftp’ folder so any user that logs in can see the files but they cannot delete them.

I have added a screenshot of my CRON JOB cpanel view. NOW is this possible that someone knows a script to make a file have READ ONLY attributes once it is fully uploaded to my ‘ftp’ folder.

IMAGE HERE http://files.enjin.com/411454/misc/cronjob.jpg

Also apart from the command script the other options are how often from the common settings dialog box and what needs to be added to the command to allow it to operate in the ‘ftp’ folder.

Again the FTP is mydomain//home/mp/public_html/aoe2hdozclan.com/ftp

The users will be uploading video files so they may take 30-60 minutes approx and will the common settings affect the upload or will they just keep executing on the files regardless?

I hope someone could please help me out on this one as it’s a very important factor on this site for our users/

With regards and thank you in advance.

Mat

ra.amri 04-24-2013 03:17 PM

Hi, if you want to run the command each minute for example, put */1 for Minute, and * for the others. The command is chmod -R a=r /home/mp/public_html/aoe2hdozclan.com/ftp/*.

But I don't think cronjobs are a good idea. For example someone could delete a file uploaded less than a minute ago with those settings.

mdexter 04-24-2013 06:40 PM

Hello ra.amri, thank you so very much for this, can I ask you that is exactly my issue, I simply do not want people to delete the other peoples files, is there a way that I can be alerted of a new file appearing in the folder, like via email....this way I can go and retrieve it asap....is this possible at all, I simply need a quick solution that I can retrieve the file ASAP

Thank you very much for your help and I hope you could answer this new query

Many thanks in advance

it does change the file to 444 which is great, the log is as follows:

chmod: `/home/mp/public_html/aoe2hdozclan.com/ftp/_vti_cnf': Permission denied

I understand the permission denied as that folder has 000 as the permissions


CAN I ASK AGAIN, is it possible in a cron job to alert me when a new file appears in the ftp folder, I am more and more thinking that this may be the solution because I can retrieve it within a couple of minutes or 5 minutes from arriving???

Many thanks

chrism01 04-24-2013 06:46 PM

If they're all sharing a login area, you might as well use the anonymous option anyway.
More specifically, see 22.5.6. File Transfer Options https://www.centos.org/docs/5/html/D...ftpd-conf.html to change the ownerships after upload.
Use chown_uploads, chown_username options.

mdexter 04-24-2013 07:08 PM

1 Attachment(s)
Oh, dear I do not have those options as it needs a password according to this screenshot, I am not sure about that page and where to add these options......I am not a coder and not sure where to start but the other option could a file alert me as to when it arrives or how do I actually code the anonymous way?

image here to show you the ftp cpanel

sag47 04-24-2013 11:42 PM

Doing a cron job to set the files to be readonly would only be effective if you changed the user with chown. I do not recommend this. Not only will you be *regularly* chowning possibly a large amount of files as the directory grows but you'll be faced with the fact that there will always be some delay that files can be affected by other users until the cron job runs.

I recommend you set up an FTP Staging directory where your users upload to a staging directory and upon the upload finishing the FTP server automatically moves the files to another directory. This way only the staging directory is read/write for the user and any other directories are not. This would require you modifying the configuration of the FTP server itself to accomplish this. What FTP server are you using?

mdexter 04-25-2013 12:13 AM

Its just a standard FTP server through my cpanel...where you have to set password etc.

Is it possible using the cron job to have another folder next to the ftp folder which is not an ftp folder but the cronjob script moves the files to that folder after they are downloaded, is this possible at all, then no one will be able to move the file once it has arrived because the script has moved the file, is that possible at all...

By the way, thank you so very much for helping me out here, no one else has been able to assist me, this is for our Gaming Clan and a lot of people are asking so again thank you

Cheers

sag47 04-25-2013 12:56 AM

Sure you can. Let's call the staging directory "upload".

For example here's your directories:
  • /home/mp/public_html/aoe2hdozclan.com/ftp
  • /home/mp/public_html/aoe2hdozclan.com/ftp/upload

Make the ftp directory read only for the user and make the upload directory write only (with no ability to read). Replace the "aoe2hdozclan@mdexter.com" with the proper user that requires ownership of these directories.
Code:

chown root:aoe2hdozclan@mdexter.com ftp
chmod 750 ftp
chown chown root:aoe2hdozclan@mdexter.com ftp/upload
chmod 730 ftp/upload

Now a user shouldn't be able to upload files to the ftp directory but they *can* upload files to the 'upload' directory.

Create a script which can be executed by a cron job. Let's call it /usr/local/bin/movefiles.sh
Code:

#!/bin/bash
cd /home/mp/public_html/aoe2hdozclan.com/ftp/upload
#If there are no files then simply exit
if [ "$(ls -1 | wc -l)" -eq "0" ];then
  exit
fi
#there must be files since we've gotten this far so move them all one directory up.
mv * ../

Now create the cron job that runs every minute. See man 5 crontab.
Code:

* * * * * /usr/local/bin/movefiles.sh

chrism01 04-25-2013 02:23 AM

For that kind of thing, inotifywait http://linux.die.net/man/1/inotifywait would be more efficient and react faster.

mdexter 04-25-2013 06:30 AM

WOW, this works absolutely perfectly, thank you thank you so very very much....that is awesome, i still havr the issue of only being able to have the permissions on the ftp and the uploads folder at 700 each otherwise I get an email permission denied

but it is working, and thank you so very much

---------- Post added 04-25-13 at 09:01 PM ----------

WOW, this works absolutely perfectly, thank you thank you so very very much....that is awesome, i still havr the issue of only being able to have the permissions on the ftp and the uploads folder at 700 each otherwise I get an email permission denied

but it is working, and thank you so very much

sag47 04-25-2013 10:12 AM

Quote:

Originally Posted by chrism01 (Post 4938466)
For that kind of thing, inotifywait http://linux.die.net/man/1/inotifywait would be more efficient and react faster.

How would you apply that to files with unknown inodes (i.e. they don't exist yet because they will be uploaded)? I've used something like incrontab to monitor the inodes on existing files but I've yet to find a good inotify solution for keeping track of folders updating. I'm curious to know how it would be done if it can.

*EDIT* after reading the inotifywait man page more closely I realize it is a command line tool and is able to monitor directories. Pretty cool. Learn something every day.

SAM

mdexter 04-25-2013 10:18 AM

I have to say that this overall is the perfect solution and again I want to say thankyou very much for all of your awwesome help as you have solved my issue whilst others could not!!!

Again many thanks indeed and the folders operate as intended, love even testing them out......perfect stuff.

sag47 04-25-2013 10:33 AM

If you are in practice using my original "movefiles.sh" script then one thing I should have accounted for (nobody is perfect right?) is the possibility that a user uploads a file with a duplicate file name. You have two options to handle that.

Creating a backup copy for each file (so duplicates will move into a new file name).
Code:

mv --backup=numbered * ../
Or force the script to overwrite existing files of the same name.
Code:

mv -f * ../
SAM

mdexter 04-25-2013 05:23 PM

Hello Sag47, ok so the original script is:


#!/bin/bash
cd /home/mp/public_html/aoe2hdozclan.com/ftp/uploads
#If there are no files then simply exit
if [ "$(ls -1 | wc -l)" -eq "0" ];then
exit
fi
#there must be files since we've gotten this far so move them all one directory up.
mv * ../


Where would the new addition of

mv --backup=numbered * ../

Where would that fit into the above script......sorry, I like the option of the ability to rewrite incase they do upload two with the same name, just need to know where to put your new snippit into?


Many thanks again

Thank you

mdexter 04-26-2013 12:37 AM

I added:

mv --backup=numbered * ../

and replaced

mv * ../

Will see how it goes, again thank you so very much

_______________________________________________

Would I be pushing the limits of the cron job, does it have the ability to send out an email to an email address with a custom message at all?

or is this something not capable of the cron job, if so it would be awesome to send out an automated message to the person who uploaded the file with a custom message?

Again if not, not to worry as you have been ever so helpful :)


All times are GMT -5. The time now is 07:10 PM.