Solved

Linux Script

Posted on 2012-12-22
7
613 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_
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now