LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-23-2013, 10:22 PM   #1
mdexter
LQ Newbie
 
Registered: Apr 2013
Posts: 12

Rep: Reputation: Disabled
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
 
Old 04-24-2013, 04:17 PM   #2
ra.amri
LQ Newbie
 
Registered: Apr 2013
Location: Casablanca, MOROCCO
Distribution: Gentoo Linux
Posts: 8

Rep: Reputation: 1
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.

Last edited by ra.amri; 04-24-2013 at 04:19 PM.
 
1 members found this post helpful.
Old 04-24-2013, 07:40 PM   #3
mdexter
LQ Newbie
 
Registered: Apr 2013
Posts: 12

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

Last edited by mdexter; 04-24-2013 at 07:44 PM.
 
Old 04-24-2013, 07:46 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
1 members found this post helpful.
Old 04-24-2013, 08:08 PM   #5
mdexter
LQ Newbie
 
Registered: Apr 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
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
Attached Thumbnails
Click image for larger version

Name:	ftp.jpg
Views:	11
Size:	62.1 KB
ID:	12396  
 
Old 04-25-2013, 12:42 AM   #6
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
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?
 
1 members found this post helpful.
Old 04-25-2013, 01:13 AM   #7
mdexter
LQ Newbie
 
Registered: Apr 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Smile

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
 
Old 04-25-2013, 01:56 AM   #8
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

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

Last edited by sag47; 04-25-2013 at 02:01 AM.
 
1 members found this post helpful.
Old 04-25-2013, 03:23 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
For that kind of thing, inotifywait http://linux.die.net/man/1/inotifywait would be more efficient and react faster.
 
2 members found this post helpful.
Old 04-25-2013, 07:30 AM   #10
mdexter
LQ Newbie
 
Registered: Apr 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-25-2013, 11:12 AM   #11
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by chrism01 View Post
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

Last edited by sag47; 04-25-2013 at 11:15 AM.
 
Old 04-25-2013, 11:18 AM   #12
mdexter
LQ Newbie
 
Registered: Apr 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Smile

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.

Last edited by mdexter; 04-25-2013 at 11:20 AM.
 
Old 04-25-2013, 11:33 AM   #13
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

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

Last edited by sag47; 04-25-2013 at 11:36 AM.
 
Old 04-25-2013, 06:23 PM   #14
mdexter
LQ Newbie
 
Registered: Apr 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Smile

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
 
Old 04-26-2013, 01:37 AM   #15
mdexter
LQ Newbie
 
Registered: Apr 2013
Posts: 12

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

Last edited by mdexter; 04-26-2013 at 01:53 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 09:52 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
Cron job in Linux kulan Linux - Software 3 12-18-2006 02:25 PM
Cron job in Suse Linux excidy Linux - Software 8 06-12-2006 11:32 PM


All times are GMT -5. The time now is 02:30 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration