Marco fourth week of 36 jobs

1, describes what GPT is how it should use

GPT: GUID (Globals Unique Identifiers) partitiontable 128 partitions 64-bit support 8Z (512Byte / block) 64Z (4096Byte / block), using 128-bit UUID (Universally Unique Identifier) ​​indicates that the disk and partition GPT partition table automatic backups two in the head and tail, and a CRC parity bits, UEFI (unified Extensible firmware Interface) hardware support GPT, the operating system starts.

gdisk command creates a GPT partition

2. Create a 10G partition, and format for the ext4 file system. Requirements:
(1) Block size is 2048, set aside space by 20%, the volume label MYDATA,
(2) mounted to / mydata directory, to ban the program to run automatically when the mount, and does not update the access time stamp of the file.
(3) can be switched automatically mounted.

fdisk /dev/sdb
Marco fourth week of 36 jobs

2048 MYDATA -m -b -L mkfs.ext4 20 is / dev / sdb1
[-b block set size] [-L Set volume label MYDATA] [% headspace 20 is]
Mount -o noexec, the noatime / dev / sdb1 / mydata
[noexec- prohibit programs that run automatically] [noatime- not update file access timestamp]

Automatically mount:
blkid / dev / sdb1 View uuid

vim / etc / fstab in the fstab add the following:
the UUID = bd6e7c18-1071-4962-A071-febddabc4d49 / mydata ext4 Defaults, the noatime, noexec 0 0

3, create a swap partition size for the 1G and enable

Marco fourth week of 36 jobs

partprobe
mkswap /dev/sdb2
swapon -a
swapon -s
vim /etc/fstab 添加如下:
/dev/sdb2 swap swap defaults 0 0

4, calculates scripting / etc / passwd file 10 and the user 20 and the user id number.

#!/bin/bash
users1=$(cat /etc/passwd|wc -l)
[ $users1 -lt 20 ] && echo "less than 20users" && exit 2
userid10=$(head -n 10 /etc/passwd | tail -n 1 | cut -f 3 -d ":")
userid20=$(head -n 20 /etc/passwd | tail -n 1 | cut -f 3 -d ":")
usersum=$[$userid10+$userid20]

echo "the 10th user id is $userid10"
echo "the 20th user id is $userid20"
echo "the sum is $usersum"

5, save the current host name to hostName variable, if the host name is empty or is localhost.localdomain will be set to www.magedu.com

#!/bin/bash
hostName=$(hostname)
[ "$hostName" == "localhost.localdomain" -o -z "hostName" -o -n "hostname" ] && hostnamectl set-hostname www.magedu.com;echo 'hostName='$hostName || echo "nothing to be change"

6, scripting, command line parameters into a user name, judge id number is even or odd.
#! / bin / bash

read -p "Enter a username: " usename
id=$(cat /etc/passwd |grep $username |cut -f3 -d:)
echo "The user \"$username\" id is $id"
[ expr $id % 2 -eq 0 ] && echo "this id is even number" || echo "this id is odd number"

Guess you like

Origin blog.51cto.com/14387464/2409042