Solved

Linux Script

Posted on 2012-12-22
7
658 Views
Last Modified: 2012-12-23
I'm trying to add these requirements to my script below:
o    The file owner can read, modify and access the scenario company directories
o    The group members can read and access the scenario company directories
o    Everyone else has no access.
·         Create a file in each of the scenario company directories.
o    Set the file permissions for the files in the scenario company directories.
o    The owner can read and modify the file
o    The group members can only read the file
o    Everyone else has no permissions


10 #
      11 # This will create the home ARI directory
      12 #
      13 #
      14 test -d /ARI && echo ">ARI already exists" || mkdir -v /ARI
      15 #
      16 #
      17 # Create Next level of Directories
      18 test –d /ARI/SALES && echo “/ARI/SALES already exists” || mkdir –v /ARI/SALES
      19 test –d  /ARI/IT && echo “/ARI/IT already exists” || mkdir –v /ARI/IT
      20 test –d /ARI/MARKETING && echo “/ARI/SALES already exists” || mkdir –v /ARI/MARKETING
      21 test –d /ARI/FINANCE && echo “/ARI/SALES already exists” || mkdir –v /ARI/FINANCE
      22 #
      23 #
      24 # The next lines create the subfolders under the second level directories
      25 mkdir –v \ARI\SALES\REG_1
      26 mkdir –v \ARI\SALES\REG_2
      27 mkdir –v \ARI\SALES\REG_3
      28 mkdir –v \ARI\IT\OPS
      29 mkdir –v \ARI\IT\DEV
      30 mkdir –v \ARI\IT\RandD
      31 mkdir –v \ARI\MARKETING\FT
      32 mkdir –v \ARI\MARKETING\PT
      33 mkdir –v \ARI\MARKETING\CNT
      34 mkdir –v \ARI\FINANCE\AP
      35 mkdir –v \ARI\FINANCE\AR
      36 mkdir –v \ARI\FINANCE\ADT
      37 #
      38 #
      39 #Create symbolic links from OPS and PT subdirectories to their parent directory
      40 ln-s /ARI/IT /IT/OPS
      41 ln-s /ARI/MARKETING /MARKETING/PT
      42 done
      43 done
0
Comment
Question by:Jack_son_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 38716225
Hi,

Your requirements require you to customise directory and file permissions before running the script. It is not a part of the script.

A directory should have this if you want the owner can read write and group can read write and others won't have any permission:

chmod 770 /Path/to/directoy

Open in new window


While if ypu want the group can only read but can't write the directory should have this:

chmod 750 /path/to/directory

Open in new window


Cheers,
K.
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 38716228
1-3) Add "umask 027" before creating directories (at line 13, for example)

4-7) Add "umask 026" before creating files

Then do something like

touch /ARI/SALES/REG_1/MYFILE

for each of the desired directories.

Since you said it's a Linux script change all backslashes (the Windows directory separator) to forward slashes (which is the standard Linux directory separator)

Tip: When using "mkdir -p ..." the full path will be created if it doesn't already exist, so you can spare all the stuff in the first lines 14-21.
0
 

Author Comment

by:Jack_son_
ID: 38716267
Thanks what is the unmask command do?  How do I add to my script. For touch, i can use that and remove mkdir?
0
Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 38716283
"umask" sets the file/directory creation mask.

Issue "umask" on the command line to check the current setting.

By default, a newly created file has permissions 666 (rw-rw-rw-) and a newly created directory has 777 (rwxrwxrwx).

The value set in the umask is subtracted from this default, so a file created under umask 026 will have permissions 640 (rw-r-----), and a directory created under umask 027 will have permissions 750 (rwxr-x---).

Add it to your script as a regular statement in a separate line:

...
umask 027
mkdir ...
mkdir ...
...
umask 026
touch ...
touch ...
...

When the script exits the umask will be reset to its default value "022".

"man umask" for more.

"touch" does not replace mkdir. It just creates the named (empty!) file, resp. (when used without flags) sets its last modification timestamp to the current time if the file exists.

You can remove the statements meant to create the top level diectories when using the "-p" flag of "mkdir"

So

 mkdir –v -p /ARI/MARKETING/FT

will create /ARI, /ARI/MARKETING and /ARI/MARKETING/FT if neither of these directories already exists, but will leave existing directories alone (means: it will not destroy and recreate these directories).
0
 

Author Comment

by:Jack_son_
ID: 38716291
I updated the script, let me know if this looks on track:

12 #
      13 umask 027
      14 test -d /ARI && echo ">ARI already exists" || mkdir -v /ARI
      15 #
      16 #
      17 # Create Next level of Directories
      18 test –d /ARI/SALES && echo “/ARI/SALES already exists” || mkdir –v /ARI/SALES
      19 test –d  /ARI/IT && echo “/ARI/IT already exists” || mkdir –v /ARI/IT
      20 test –d /ARI/MARKETING && echo “/ARI/SALES already exists” || mkdir –v /ARI/MARKETING
      21 test –d /ARI/FINANCE && echo “/ARI/SALES already exists” || mkdir –v /ARI/FINANCE
      22 #
      23 #
      24 # The next lines create the subfolders under the second level directories
      25 mkdir –v /ARI/SALES/REG_1
      26 mkdir –v /ARI/SALES/REG_2
      27 mkdir –v /ARI/SALES/REG_3
      28 mkdir –v /ARI/IT/OPS
      29 mkdir –v /ARI/IT/DEV
      30 mkdir –v /ARI/IT/RandD
      31 mkdir –v /ARI/MARKETING/FT
      32 mkdir –v /ARI/MARKETING/PT
      33 mkdir –v /ARI/MARKETING/CNT
      34 mkdir –v /ARI/FINANCE/AP
      35 mkdir –v /ARI/FINANCE/AR
      36 mkdir –v /ARI/FINANCE/ADT
      37 #
      38 #
      39 #Create symbolic links from OPS and PT subdirectories to their parent directory
      40 ln-s /ARI/IT /IT/OPS
      41 ln-s /ARI/MARKETING /MARKETING/PT
      42 umask 026
      43 #
      44 touch /ARI/SALES/REG_1/SALESFILE
      45 touch /ARI/SALES/REG_2/SALESFILE1
      46 touch /ARI/SALES/REG_3/SALESFILE2
      47 touch /ARI/IT/OPS/ITFILE1
      48 touch /ARI/IT/DEV/ITFILE2
      49 touch /ARI/IT/RandD/ITFILE3
      50 touch /ARI/MARKETING/FT/FILE1
      51 touch /ARI/MARKETING/PT/FILE2
      52 touch /ARI/MARKETING/CNT/FILE3
      53 touch /ARI/FINANCE/AP/FILE1
      54 touch /ARI/FINANCE/AR/FILE2
      55 touch /ARI/FINANCE/ADT/FILE3
      56 #
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 38716300
Yes, looks good.


I think the ">" character in the message string in line 14 is a typo, right?
Not that it will do any harm, I just wanted to mention ...

The error messages in lines 20/21 need customizing to contain the correct directory name.

Seems you don't want to use "mkdir -p ...", but that's of course your decision.
0
 

Author Closing Comment

by:Jack_son_
ID: 38716983
Great, thanks for the input!  

I'm doing a few more items with the script, but creating a new post. Any contribution is appreciated!
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question