Jack_son_
asked on
Linux Script Question 2
I want to confirm I have the script in order, adding some features and listing all the functionality. Let me know if there is a better process to do this. Here is the requirement:
Automate the following:
· Directory and subdirectory creation
· Files in each of the directories
· Symbolic links from 2 subdirectories to their parent directories
· Include branching to only execute the directory, file and link commands only if the directory or file does not already exist.
· Set up an error log file with commands to route the errors messages into it.
· Sett appropriate file permissions for the directories and files:
· Directories
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.
· Files
o The owner can read and modify the file,
o the group members can only read the file
o everyone else has no permissions at all.
Below is my script thus far:
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/MARKETING already exists” || mkdir –v /ARI/MARKETING
21 test –d /ARI/FINANCE && echo “/ARI/FINANCE 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 037
43 #
44 touch /ARI/SALES/REG_1/SALESFILE
45 touch /ARI/SALES/REG_2/SALESFILE 1
46 touch /ARI/SALES/REG_3/SALESFILE 2
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 #
57 done
58 done
Automate the following:
· Directory and subdirectory creation
· Files in each of the directories
· Symbolic links from 2 subdirectories to their parent directories
· Include branching to only execute the directory, file and link commands only if the directory or file does not already exist.
· Set up an error log file with commands to route the errors messages into it.
· Sett appropriate file permissions for the directories and files:
· Directories
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.
· Files
o The owner can read and modify the file,
o the group members can only read the file
o everyone else has no permissions at all.
Below is my script thus far:
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/MARKETING already exists” || mkdir –v /ARI/MARKETING
21 test –d /ARI/FINANCE && echo “/ARI/FINANCE 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 037
43 #
44 touch /ARI/SALES/REG_1/SALESFILE
45 touch /ARI/SALES/REG_2/SALESFILE
46 touch /ARI/SALES/REG_3/SALESFILE
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 #
57 done
58 done
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
10 #
11 # This will create the home ARI directory
12 #
13 umask 027
14 test -d /ARI && echo "ARI already exists">&2 || mkdir -v /ARI
15 #
16 #
17 # Create Next level of Directories
18 test –d /ARI/SALES && echo “/ARI/SALES already exists”>&2 || mkdir –v /ARI/SALES
19 test –d /ARI/IT && echo “/ARI/IT already exists”>&2 || mkdir –v /ARI/IT
20 test –d /ARI/MARKETING && echo “/ARI/MARKETING already exists”>&2 || mkdir –v /ARI/MARKETING
21 test –d /ARI/FINANCE && echo “/ARI/FINANCE already exists”>&2 || 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/OPS /ARI/OPS
41 ln-s /ARI/MARKETING/PT /ARI/PT
42 umask 026
43 #
44 touch /ARI/SALES/REG_1/SALESFILE
45 touch /ARI/SALES/REG_2/SALESFILE
46 touch /ARI/SALES/REG_3/SALESFILE
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 #