LinuxQuestions.org
Review your favorite Linux distribution.
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-28-2013, 01:32 PM   #1
anky.parmar1786
LQ Newbie
 
Registered: Feb 2011
Posts: 4
Blog Entries: 4

Rep: Reputation: 0
scripts for maiking new directories


Hi All,

I have one question.. I have two directories.. one is /logs and other is /logs_backup.
There are 5 folders in /logs directory with the name Jan,Feb,Mar,Apr and May .. now what I want to do is
that I want to move these folders log(Jan,Feb,Mar,Apr and May) in /logs_backup directory.
I want a script in which when script will run,it will check in /logs_backup directory that whether is Jan folder is there or not? If it is there then ok and if it is not there then create a folder with name of Jan.
Same way If I'll add any new folder in /logs directory with the coming months name like Jun,Jul etc so when the scripts run next time it will check first that whether Jun folder is available in /logs_backup or not? If it is available then no need to create but when if it is not there then create folder with the same name..If anybody help me on this then I shall be very thankful to him/her.. Thanks in advance.. Ankit
 
Old 04-28-2013, 01:43 PM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
should not be to hard, post using code/code flags of what you have come up with so far. would be happy to help as i know others here would be as well.
 
Old 04-28-2013, 02:18 PM   #3
cortman
Member
 
Registered: Jan 2012
Location: ZZ9 Plural Z Alpha
Distribution: Crunchbang 11, LFS 7.3, DSL 4.1.10, Lubuntu 12.10, Debian 7
Posts: 219

Rep: Reputation: 43
I don't quite understand. You're saying "if there is a folder in /logs_backup that is called "Jan", then move the "Jan" folder from /logs to /logs_backup. Otherwise, create a folder in /logs_backup called "Jan" and move /logs/Jan to /logs_backup/Jan/Jan?
 
Old 04-28-2013, 02:23 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,925

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by anky.parmar1786 View Post
Hi All,
I have one question.. I have two directories.. one is /logs and other is /logs_backup.

There are 5 folders in /logs directory with the name Jan,Feb,Mar,Apr and May .. now what I want to do is that I want to move these folders log(Jan,Feb,Mar,Apr and May) in /logs_backup directory.

I want a script in which when script will run,it will check in /logs_backup directory that whether is Jan folder is there or not? If it is there then ok and if it is not there then create a folder with name of Jan.
Same way If I'll add any new folder in /logs directory with the coming months name like Jun,Jul etc so when the scripts run next time it will check first that whether Jun folder is available in /logs_backup or not? If it is available then no need to create but when if it is not there then create folder with the same name..If anybody help me on this then I shall be very thankful to him/her.. Thanks in advance.. Ankit
You've been registered here for two years now...writing a script should be something you can easily do. As others have said, post what you've written/tried so far, and we will HELP you, but we WILL NOT write the script FOR YOU.

There are THOUSANDS of VERY easily found bash scripting tutorials you can find with a Google search, that have examples on how to check for file/directory existing. Start there.
 
Old 04-28-2013, 02:43 PM   #5
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Quote:
Originally Posted by TB0ne View Post
You've been registered here for two years now...writing a script should be something you can easily do. As others have said, post what you've written/tried so far, and we will HELP you, but we WILL NOT write the script FOR YOU.

There are THOUSANDS of VERY easily found bash scripting tutorials you can find with a Google search, that have examples on how to check for file/directory existing. Start there.
not cutting you down, but look at the total number of posts he has. not many. my guess is he registered 2 years ago and asked a few questions. he might have been away from linux in general for a long time and is now faced with a new linux question again. i for one have been using linux on and off for over a decade, yet only last year did i start to learn basic bash scripting.

this to me does sound a bit like homework though. thus my response. this could be handled via either rsync, or a simple f -! "foo" but will not know until the OP posts some kind of attempt so we have a better idea of exactly what he wants to accomplish and why.
 
1 members found this post helpful.
Old 04-28-2013, 11:55 PM   #6
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 you want to check if a file or dir exists etc, http://tldp.org/LDP/abs/html/fto.html.

In addition, I recommend these to be read
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
1 members found this post helpful.
Old 05-04-2013, 04:33 PM   #7
anky.parmar1786
LQ Newbie
 
Registered: Feb 2011
Posts: 4
Blog Entries: 4

Original Poster
Rep: Reputation: 0
hi,kindly go through my below script,its execute without any error but didn't created folder premium1. so please guide on it.. Thanks in advance..

# !/bin/bash

function MAKEDIR {
echo -e "Premium1"
read Premium1
if [ ! -d $Premium1 ]
then
mkdir $Premium1
echo -e "Directory $Premium1 created"

else
echo -e "$Premium1 directory already exists!"
echo -e "Failed to create $Premium1 directory, Directory already exists"
fi
}
 
Old 05-05-2013, 07:21 AM   #8
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
1. please use code tags for posting code https://www.linuxquestions.org/quest...do=bbcode#code
2. there should be no space between '#' & '!/bin/bash'
3. all that does is declare/define a fn; it needs to be called to do something eg
Code:
#!/bin/bash

# optionally, add this line to debug
set -xv

# declare fn
function blah
{
.
.
.
}

# ... and call it
blah
and see my links above
 
Old 05-05-2013, 08:56 AM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
...additionally:
4. directory creation is not anchored anywhere, meaning it will execute 'mkdir' wherever the current processes current working directory is,
5. it should explicitly set an umask to avoid perm probs,
6. one shouldn't use mixed case unless unavoidable.
 
Old 05-05-2013, 08:56 AM   #10
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by anky.parmar1786 View Post
...its execute without any error but didn't created folder premium1. so please guide on it..
Add debug mode i.e. set -xv in your script, so you can check where it goes wrong or stuck:
Code:
#!/bin/bash
set -xv
function MAKEDIR {
......
......
......
fi
}
 
Old 05-05-2013, 08:50 PM   #11
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
Think I already mentioned that
 
Old 05-05-2013, 11:09 PM   #12
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by chrism01 View Post
Think I already mentioned that
Right. I missed your post.

@anky.parmar1786:
As said, add debug mode, and find where your script gets stuck or what's wrong with it.
 
  


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
Maiking linux server on ARM platform Fajkowsky Linux - General 1 11-13-2012 11:07 AM
Why are there four different rc scripts directories? prasadcm Linux - Newbie 1 04-20-2010 01:42 PM
users accessing directories,files using php scripts ckob Linux - Security 3 03-14-2008 09:06 AM
Startup scripts in rcn.d directories correro Linux - Newbie 1 01-20-2006 01:20 AM
running cgi scripts in other directories init-5 Linux - Software 2 09-16-2003 04:01 PM


All times are GMT -5. The time now is 02:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration