LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 01-17-2010, 11:25 AM   #1
stascrash
LQ Newbie
 
Registered: Nov 2006
Location: Chicago, IL
Posts: 29

Rep: Reputation: 15
Autocreate DATE folder


Hey guys,
i am running into few problems with the script here.
I have an FTP server, all configured, and i need to have a script that will create a folder with current dated within a tree as soon as particular user logs in. I was wondering if that is possible with proftpd.
if not, can someone suggest how to create a script that will simply create a DIR with date and autorun itself every 24 hours?
i am running Debian/Proftpd with Mysql authorization.
Thanks
-stas
 
Old 01-17-2010, 11:52 AM   #2
stascrash
LQ Newbie
 
Registered: Nov 2006
Location: Chicago, IL
Posts: 29

Original Poster
Rep: Reputation: 15
hey guys,
after a little research i got this

Quote:
mkdir `date +%m%d%Y`
It works and creates like i need it.
Now, i have the following tree of folders

Quote:
ftp/user/userA/DATE folder
ftp/user/userB/Date folder
etc.
Is there a way to tell my script to run and make folders, replacing userA, going next to userB etc, until the end of my folder structure?
i tried mkdir ftp/user/*/`date +%m%d%Y` - using * to mark ALL, but it did not work, any ideas? thanks
 
Old 01-17-2010, 11:59 AM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
You could loop through the directories:

Code:
##
##Untested
##

l_date=$(date +%m%d%Y)
for l_dir in $(ls ftp/user/)
do
   mkdir ftp/user/${l_dir}/${l_date}
done

Last edited by Disillusionist; 01-17-2010 at 12:04 PM. Reason: correction ;)
 
Old 01-17-2010, 01:22 PM   #4
stascrash
LQ Newbie
 
Registered: Nov 2006
Location: Chicago, IL
Posts: 29

Original Poster
Rep: Reputation: 15
@Disillusionist: Thanks you, let me give this a try, i hope it will work for what i need. Do u know if i can execute a script when FTP client connects ?
 
Old 01-17-2010, 05:05 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I don't know if you can do that from FTP, but you could definitely run that loop from cron at eg 00:01 in the morning.
http://www.adminschoice.com/docs/cro...Crontab%20file

After all, you don't want it to create the folders each time a user logs in, just the first time in a given day...
 
Old 01-18-2010, 06:52 PM   #6
stascrash
LQ Newbie
 
Registered: Nov 2006
Location: Chicago, IL
Posts: 29

Original Poster
Rep: Reputation: 15
Thanks Guys,
after working a little more, i added few more variables to it to do and it is all ready to go.
I have another question, honestly, this is my first or second script for Linux, and after exploring some tutorials, to made it executable, but for some reason it needs me to still put SH in front,
could you suggest how to get around this?
Thanks,
 
Old 01-19-2010, 01:54 AM   #7
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Tell the script what interpreter it should be using.

If using bash, the first line of the script should be:
Code:
#!/bin/bash
If using sh, the first line of the script should be:
Code:
#!/bin/sh
If using Perl, the first line of the script should be:
Code:
#!/usr/bin/perl
To check where sh is coming from type the following at the command line:
Code:
which sh
 
Old 01-19-2010, 08:32 AM   #8
stascrash
LQ Newbie
 
Registered: Nov 2006
Location: Chicago, IL
Posts: 29

Original Poster
Rep: Reputation: 15
Yeah, i got all that taken care of, even run the chmod to make it executable, but when i type. script.sh it does not run saying
-bash: script.sh: command not found.
but when i add SH in front it runs no problem, i am going to schedule this for CRON to run, but don't think this will work if i don't get it to run without the use of SH command in front.
Weird, i know that the command to run it is simple, and straight forward, but running it did not help, i was using bash scripting tutors, and nothing really worked.
Thanks for getting back to me
 
Old 01-19-2010, 10:03 AM   #9
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
What happens if you type:
Code:
./script.sh
"Obviously" this needs to be run from the directory containing script.sh

Messages of "script.sh" not found normally means that the directory containing script.sh is not in the $PATH environment variable.

What happens if you type:
Code:
which script.sh
 
Old 01-19-2010, 05:21 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
When you put it in cron, supply the full/absolute path to the script. cron env is minimal and won't include eg you home dir. Same rule applies to any other scripts/files referenced, unless the script takes care of that.

2 10 * * * /path/to/script.sh
 
Old 01-20-2010, 03:24 PM   #11
stascrash
LQ Newbie
 
Registered: Nov 2006
Location: Chicago, IL
Posts: 29

Original Poster
Rep: Reputation: 15
@Disillusionist:
When i run ./script.sh
i get the following: PERMISSION DENIED
when i run WHICH - i get nothing, no return.
i guess the first PERMISSION DENIED means i have no root rights to run it? am i correct?
however i ran CHMOD u+x on my script, and it shows with a "*" in MC.
 
Old 01-20-2010, 05:15 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Open a terminal and run

ls -l script.sh
 
Old 01-21-2010, 12:42 AM   #13
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Quote:
Originally Posted by stascrash View Post
@Disillusionist:
When i run ./script.sh
i get the following: PERMISSION DENIED
You don't have read/execute permissions for this script.

Typically, if I need a script to be run by anybody, I set permissions to 755 (-rwxr-xr-x) read/write/execute for owner read/execute for group read/execute for all.

Code:
chmod 755 script.sh
Quote:
Originally Posted by stascrash View Post
when i run WHICH - i get nothing, no return.
This means that script.sh is not in your $PATH environment variable.

This is fine, but it means that you either need to refer to the full path of the script:
/path/to/script.sh

or when running from the directory that holds the script precede with ./
./script.sh

Last edited by Disillusionist; 01-21-2010 at 02:35 AM. Reason: spotted error ;)
 
Old 01-22-2010, 09:20 AM   #14
stascrash
LQ Newbie
 
Registered: Nov 2006
Location: Chicago, IL
Posts: 29

Original Poster
Rep: Reputation: 15
alright,Disillusionist, well i have changed the permissions to 755. and it runs with a full path and with ./ from the folder. works and does what it suppose to do. I have setup a CRON for it, like chrism01 suggested with the full path, and waiting for it to execute,
Thank you guys for your help, i will post the results there once it runs.
 
Old 01-23-2010, 07:05 PM   #15
stascrash
LQ Newbie
 
Registered: Nov 2006
Location: Chicago, IL
Posts: 29

Original Poster
Rep: Reputation: 15
Hello Guys,
Thank you very much for helping me out with this problem,
i got my scripts to work and run at specific time. I had some issues mounting the NAS unit with FSTAB, so i created a script to mount and run it at boot time.
Thanks again,
cheers!!
 
  


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
Sort files under a folder by created date Kunsheng Programming 3 05-11-2009 04:58 AM
Date wise Folder name opi045 Linux - Software 1 01-21-2009 12:13 PM
copy folder/files according to modification date bkcreddy17 Programming 14 10-15-2008 07:24 PM
autocreate spam folder ebeda Linux - Enterprise 2 12-18-2006 09:37 AM
Is this possible....to autocreate users on linux? jviola Linux - Networking 19 10-16-2006 07:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12: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
Open Source Consulting | Domain Registration