A self-written shell script for automatic formatting, mounting upon startup, creating users and managing ACL Permissions

Source: Internet
Author: User

 

At noon yesterday, after finishing learning ACL and mounting, I tried to write a small script. Suppose a group develops a project and needs to create a project group with three users and a shared folder, to prevent mutual modification or even deletion of objects, set SGID and sticky for this folder.

 

The script function is as follows:

1. A 10 Gb logical partition can be automatically created and formatted as an ext3 partition.

2. automatically mount the partition created in step 1 and mount it at startup

3. Ask the user to manually create three users, automatically create and separate the passwords for their usernames, and create a specified R & D group so that these three users can automatically join.

4. Ask the user to specify a directory, and automatically change the group of the directory to the group created in step 1, and add the SUID permission and sticy post position.

5. You can set ACL permissions for a specified file.

6. Capture the user's Ctrl + C Undo operation throughout the process, do not save and exit.

 

#! /Bin/bash #: Title: ACL. sh #: Synopsis: #: Date: 01:48:01 #: Version: 1.0 #: Author: Dean #: Options: function FS {// automatic Formatting Function fdisk/dev/SDA <endn + 10 gwend partprobe/dev/sda f = 'fdisk-L/dev/SDA | tail-1 | cut -D/-F3 | awk '{print $1} ''' mkfs-T ext3/dev/$ F Read-P "which dir your want mount? "File mkdir $ file &>/dev/null Mount/dev/$ F $ file-o acl echo '/dev/$ F $ file ext3 defaults 0 0'>/etc /fstab} function Gu {// Add user and group read-P "which gruop you want make? "GP // Add group grep $ GP/etc/group | groupadd $ GP // If the added group exists, do not add it. Otherwise, add read-P" input 3 Username: "U1 U2 U3 // ask the user to enter three usernames grep $ u1/etc/passwd | useradd $ U1 & Echo" $ U1 "| passwd-stdin $ U1 &>/ dev/null // automatically set the created user password to its username grep $ U2/etc/passwd | useradd $ U2 & Echo "$ u2" | passwd-stdin $ u2 &>/dev/null grep $ U3/etc/passwd | useradd $ U3 & Echo "$ U3" | passwd-stdin $ U3 &>/dev/null chown: $ GP $ F Ile // modify the folder group chmod g + s o + T $ GP // Add SGID and sticky} function aclw {// ACL permission modify function read-P "Please input a file path: "P if [-e $ p]; then // check whether the file to be modified exists echo" the file is not exist! "Else exit fi echo" which kind of perssition you want add the file: 1) r -- 2) RW-"// provides two permission methods, r -- and RW -- read-P 'chose: 'n' read-P "which user influced:" UN case $ N in '1') setfacl-m u: $ UN: r -- $ P; '2') setfacl-m u: $ UN: RW-$ sp; *) echo "wrong input! ";; Esac} echo "======================================== ======================== "Echo" program for an object team "Echo" made by Dean version 1.0 "Echo" = ========================================================== =============== "Echo" which mode your want User: 1) FS 2) adduser 3) ACL 4) All "// Let the user select the corresponding module echo" useage: The FS will creat a 10g filesystem. "// currently, only 10 Gb partitions are provided. manual adjustment of the read-P partition is not supported." choise: "cCase $ C in '1 ') trap 'echo "Exit unsaved" & Exit '2 // trap tracks the user's Undo operation, exits at any time, and returns unsaved FS; '2 ') trap 'echo "Exit unsaved" & Exit '2 Gu; '3') trap 'echo "Exit unsaved" & Exit '2 aclw; '4 ') trap 'echo "Exit unsaved" & Exit '2 FS Gu aclw; *) exitesac

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.