troubleshooting Question

Linux Script Question 2

Avatar of Jack_son_
Jack_son_Flag for Afghanistan asked on
LinuxLinux OS DevLinux Networking
3 Comments2 Solutions927 ViewsLast Modified:
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/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 #
      57 done
      58 done
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros