NAME
sleep - delay for a specified amount of time 延遲指定的秒數docker
SYNOPSIS
sleep NUMBER[SUFFIX]...
sleep OPTIONshell
DESCRIPTION
Pause for NUMBER seconds. SUFFIX may be ‘s’ for seconds (the
default), ‘m’ for minutes, ‘h’ for hours or ‘d’ for days.
crontab任務在關機狀態下任務是不執行的,且開機後不在時間點上也是不執行的編程
anacron: crontab的補充機制
檢查有沒有過去一個有效週期不曾執行的任務,若是有,在開機後的指定時間點執行一次;安全
總結:
任務計劃:
一次性:at, batch
週期性:cronbash
cron:
PATH環境變量
任務時間格式
app
facl: file acl
acl: access control listless
chown: 普通用戶可否改變文件的屬主屬組? 不行
chmod: 普通用戶是否有權限使用? 有測試
openstack用戶,docker(讀寫)ui
經過facl機制,普通用戶能夠單獨向某用戶或某組設定對某文件訪問權限;不經過修改屬主或屬組來實現的。this
文件系統:
ext: extended
ext2, ext3, ext4,
xfs(單個文件無邊界)
NAME
lsattr - list file attributes on a Linux second extended file system
列出文件系統擴展的屬性主要對 ext的擴展
SYNOPSIS
lsattr [ -RVadv ] [ files... ]
DESCRIPTION
lsattr lists the file attributes on a second extended file system.
See chattr(1) for a description of the attributes and what they
mean.
[root@root ~]#lsattr test
-------------e- test 有e顯示錶示支持擴展格式
NAME
chattr - change file attributes on a Linux file system
改變Linux文件系統屬性
SYNOPSIS
chattr [ -RVf ] [ -v version ] [ mode ] files...
DESCRIPTION
chattr changes the file attributes on a Linux file system.
The format of a symbolic mode is +-=[acdeijstuADST].
這個格式向這種模式
The operator ‘+’ causes the selected attributes to be added to the
existing attributes of the files; ‘-’ causes them to be removed;
and ‘=’ causes them to be the only attributes that the files have.
a:只能往裏面追加內容 c:壓縮的格式 d:標記爲還沒有備份
e:擴展格式 i:不能變 j:設置數據日誌 s:安全刪除
t:不在尾部執行合併 u:不可刪除 A:不更新訪問時間戳 D:同步目錄更新
S:同步更新,文件更新 T:把目錄設置爲等級目錄結構
The letters ‘acdeijstuADST’ select the new attributes for the
files: append only (a), compressed (c), no dump (d), extent format
(e), immutable (i), data journalling (j), secure deletion (s), no
tail-merging (t), undeletable (u), no atime updates (A), syn-
chronous directory updates (D), synchronous updates (S), and top
of directory hierarchy (T).
The following attributes are read-only, and may be listed by
lsattr(1) but not modified by chattr: huge file (h), compression
error (E), indexed directory (I), compression raw access (X), and
compressed dirty file (Z).
lsattr, chattr
i 不能改變文件內容
u 不能刪除文件
A 不更新訪問時間戳
facl:
讓普通用戶透過文件的擴展屬性,爲其添加額外的用戶訪問受權機制而無須改
變其屬主、屬組,也不用更改other的權限;
getfacl
NAME
getfacl - get file access control lists
獲得文件的訪問控制列表
[root@root ~]#getfacl test
# file: test
# owner: root
# group: root
user::rw-
group::r--
other::r--
setfacl {-m|-x} 目標:MODE FILE...
NAME
setfacl - set file access control lists
設置文件訪問控制列表
SYNOPSIS
setfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file
...
setfacl --restore=file
DESCRIPTION
This utility sets Access Control Lists (ACLs) of files and direc-
tories. On the command line, a sequence of commands is followed
by a sequence of files (which in turn can be followed by another
sequence of commands, ...).
The -m (--modify) and -M (--modify-file) options modify the ACL of
a file or directory. ACL entries for this operation must include
permissions. 修改屬性
The -x (--remove) and -X (--remove-file) options remove ACL
entries. It is not an error to remove an entry which does not
exist. Only ACL entries without the perms field are accepted as
parameters, unless POSIXLY_CORRECT is defined. 移除屬性
-m u:USERNAME:MODE
-m g:GROUPNAME:MODE
-x u:USERNAME
-x g:GROUPNAME
-R: 遞歸
[openstack@root ~]$getfacl hello
# file: hello
# owner: openstack
# group: openstack
user::r--
group::rw-
other::rw-
[openstack@root ~]$ls -l
total 0
-r--rw-rw-. 1 openstack openstack 0 Dec 29 20:34 hello
[openstack@root ~]$chmod o= hello
[openstack@root ~]$ls hello -l
-r--rw----. 1 openstack openstack 0 Dec 29 20:34 hello
[openstack@root ~]$setfacl -m u:freebsd:rw hello
[openstack@root ~]$getfacl hello
# file: hello
# owner: openstack
# group: openstack
user::r--
user:freebsd:rw-
group::rw-
mask::rw-
other::---
[openstack@root ~]$ls -l
total 4
-r--rw----+ 1 openstack openstack 0 Dec 29 20:34 hello . -> +號了
[openstack@root ~]$setfacl -x u:freebsd hello
[openstack@root ~]$getfacl hello
# file: hello
# owner: openstack
# group: openstack
user::r--
group::rw-
mask::rw-
other::---
訪問文件的過程:先檢查進程運行者用戶是否是文件的屬主,若是是,屬主權限生效,不然,則檢查
有沒有跟此用戶相關的用戶訪問控制列表,若是有,用戶訪問控制列表生效,不然,則檢查進程的屬組
所屬的組其中之一是否是和文件屬組有一個相同,若是有應用屬組權限,不然,檢查訪問控制列表中的
屬組,若是有,應用訪問控制列表,不然其餘用戶來訪問
屬主的訪問權限是高於基於用戶的訪問控制列表,屬組的訪問權限也是高於基於屬組的訪問控制列表
啓用facl以後權限應用模型:
屬主: 匹配則應用
用戶級別的facl: 匹配則應用
屬組:匹配則應用
組級別的facl:
其它
bash編程之循環:
順序
選擇:if
循環:for
另外一種循環:while 和 until
for i in {1..100}; do
done
while適用於循環次數未知,或不便用for直接生成較大的列表時;
while 測試條件; do
循環體
done
如測試結果爲「真」,則進入循環;退出條件爲,測試條件爲假;
declare -i count=1
while $count <= 1000; do
循環體
let count++
done
until 測試條件; do
循環體
done
若是測試結果爲「假」,則進入循環;退出條件爲,測試條件爲真;
練習:求100之內全部正整數之和
#!/bin/bash
#
declare -i count=1
declare -i sum=0
until [ $count -gt 100 ]; do
let sum+=$count
let count++
done
echo $sum
#!/bin/bash
#
declare -i count=1
declare -i sum=0
while [ $count -le 100 ]; do
let sum+=$count
let count++
done
echo $sum
練習:求100之內全部偶數之和;要求使用取模方法;
#!/bin/bash
#
declare -i counter=1
declare -i sum=0
while [ $counter -le 100 ]; do
if [ $[$counter%2] -eq 0 ]; then
let sum+=$counter
fi
let counter++
done
echo $sum
#!/bin/bash
#
declare -i counter=1
declare -i sum=0
while [ $counter -le 100 ]; do
[ $[$counter%2] -eq 0 ] && let sum+=$counter
let counter++
done
echo $sum
請用until實現上述過程;
[root@root scripts]#./evensum.sh
The sum is 2550.
The sum1 is 2500.
The sum add sum1 is 5050.
[root@root scripts]#cat evensum.sh
#!/bin/bash
#
declare -i num=1
declare -i sum=0
declare -i sum1=0
until [ $num -gt 100 ]
do
# sum=$[$sum+$num]
# let num++
[ $[$num%2] -eq 0 ] && sum=$[$sum+$num] || sum1=$[$sum1+$num]
let num++
done
echo "The sum is $sum."
echo "The sum1 is $sum1."
echo "The sum add sum1 is $[$sum+$sum1]."
練習:提示用戶輸入一個用戶名,若是用戶存在,就顯示用戶的ID號和shell;不然顯示用戶不存在;
顯示完成以後不退出,再次重複前面的操做,直到用戶輸入q或quit爲止;
read -p "Plz enter a username: " userName
while [ "$userName" != 'q' -a "$userName" != 'quit' ]; do
if id $userName &> /dev/null; then
grep "^$userName\>" /etc/passwd | cut -d: -f3,7
else
echo "No such user."
fi
read -p "Plz enter a username again: " userName
done
請用until實現上述過程;
read -p "Plz input user name:" username
until [ "$username" == "q" -o "$username" == "quit" ];do if ! id "$username" &> /dev/null;then echo "$username not exists." else grep "$username" /etc/passwd |cut -d: -f1,7 fi read -p "Plz input user name:" username done