Lab:
請撰寫一個script 備份 /home 目錄
Script 名稱: homebackup.sh
Script 要求:
* 請建立 /root/lab 目錄 存放相關備份資料
* script 會判斷今天的日期, 如果當天為星期五則使用tar 進行完整備份,
備份對象為/home目錄所有資料, 並將備份紀錄寫入到/root/lab 名稱為 fullbackuplist-製作日期.log
* script 會判斷今天的日期, 如果當天為星期一到星期四則使用tar 進行遞增備份,
備份對象為/home目錄所有資料, 並將備份紀錄寫入到/root/lab 名稱為 diffbackuplist-製作日期.log
===================
#!/bin/bash
[ -d /root/lab ] || mkdir /root/lab
i=`date +%u`
echo "\$i is $i -- the day of the week"
if [ $i -eq 5 ];then
echo "-----------exec Full Backup--------"
tar cvf /root/lab/backup-full-`date +%F` /home > /root/lab/fullbackuplist-"`date +%F`.log"
echo "----------------done---------------"
elif [ $i -lt 5 ];then
#-N, --after-date=DATE, --newer=DATE
# only store files newer than DATE
echo "------exec Incremental Backup------"
tar cvf /root/lab/backup-diff-`date +%F` -N "`date --date='last friday' +%F`" /home > /root/lab/diffbackuplist-"`date +%F`.log"
echo "----------------done---------------"
fi
2009年6月16日 星期二
2009年6月15日 星期一
linux 記錄2
#grep -v '^#' httpd.conf | grep -v '^$' | wc -l <請觀察內容>
#wc -l httpd.conf <請觀察內容>
#egrep -v '^#|^$' httpd.conf <請觀察內容>
==========================================
#echo "Today is `date`" 檔指令可以執行
#echo 'Today is `date`' 全部為字串
================================
#ls /123 2> ls.txt <將 ls /123 的 STDERR 導向到 ls.txt, 2> 指定 STDERR>
==========================
#mail root -s "disk free" < df.txt <以 df.txt 為信件內容寫信給 root,主旨為 disk free >
=======================
dd <剪下一行>
p <貼上>
2dd <剪下兩行>
p <貼上>
yy <複製一行>
p <貼上>
:syntax on
:%s/httpd.conf/http.bak/gc
============================
*相關設定
:set nu <顯示行號>
:151,156s/^/#/g
==================================
#vi /etc/inittab
修改
id:3:initdefault: <將 5 改為 3, 之後就以 Runlevel 3 開機>
=======================
Lab: userdel 與 userdel -r 的差異為?
-r 會刪除使用者家目錄及信箱
========================
#useradd -m test
#echo 1234 | passwd --stdin test
當使用者離職
1.鎖定該帳戶
#usermod -L test <鎖定使用者帳戶, -L 鎖定, -U 解除>
#tail -n 2 /etc/shadow <在密碼前加上!,為鎖定>
2.刪除使用者帳戶
#userdel test
#ls -l /home
3.將其帳戶移轉到/root
#mv /home/test /root
#chown root.root /root/test
=====================================
Lab: group
#tail -n 2 /etc/group <觀察群組資料庫>
#groupadd mis <新增 mis 群組>
#tail -n 2 /etc/group
#groupmod -A max mis <將使用者 max 加入 mis 群組, -A 新增>
#tail -n 2 /etc/group
#groupmod -R max mis <將使用者 max 從 mis 群組移除, -R 移除>
#tail -n 2 /etc/group
#groupdel mis <刪除 mis 群組>
#tail -n 2 /etc/group
===================================
#chmod g+s /mis <將/mis 資料夾加上 SGID>
#ls -ld /mis <請觀察權限及擁有者,群組>
#touch /mis/test2
#ls -l /mis <請觀察權限及擁有者,群組>
===================
Lab: sticky bit
目的:不管權限為何不可以刪除其他人的檔案
#mkdir /test
#chmod 1777 /test <將/test 加上 sticky bit 權限並將權限設定為 777>
#touch /test/test.txt
#chmod 777 /test/test.txt
#ls -ld /test <請觀察權限及擁有者,群組>
#ls -l /test <請觀察權限及擁有者,群組>
#su - user1 -c "rm /test/test.txt" <以使用者 user1 刪除/test/test.txt -->失敗>
<因/test 目錄有設定 sticky bit 權限,故非本人不能刪除>
#wc -l httpd.conf <請觀察內容>
#egrep -v '^#|^$' httpd.conf <請觀察內容>
==========================================
#echo "Today is `date`" 檔指令可以執行
#echo 'Today is `date`' 全部為字串
================================
#ls /123 2> ls.txt <將 ls /123 的 STDERR 導向到 ls.txt, 2> 指定 STDERR>
==========================
#mail root -s "disk free" < df.txt <以 df.txt 為信件內容寫信給 root,主旨為 disk free >
=======================
dd <剪下一行>
p <貼上>
2dd <剪下兩行>
p <貼上>
yy <複製一行>
p <貼上>
:syntax on
:%s/httpd.conf/http.bak/gc
============================
*相關設定
:set nu <顯示行號>
:151,156s/^/#/g
==================================
#vi /etc/inittab
修改
id:3:initdefault: <將 5 改為 3, 之後就以 Runlevel 3 開機>
=======================
Lab: userdel 與 userdel -r 的差異為?
-r 會刪除使用者家目錄及信箱
========================
#useradd -m test
#echo 1234 | passwd --stdin test
當使用者離職
1.鎖定該帳戶
#usermod -L test <鎖定使用者帳戶, -L 鎖定, -U 解除>
#tail -n 2 /etc/shadow <在密碼前加上!,為鎖定>
2.刪除使用者帳戶
#userdel test
#ls -l /home
3.將其帳戶移轉到/root
#mv /home/test /root
#chown root.root /root/test
=====================================
Lab: group
#tail -n 2 /etc/group <觀察群組資料庫>
#groupadd mis <新增 mis 群組>
#tail -n 2 /etc/group
#groupmod -A max mis <將使用者 max 加入 mis 群組, -A 新增>
#tail -n 2 /etc/group
#groupmod -R max mis <將使用者 max 從 mis 群組移除, -R 移除>
#tail -n 2 /etc/group
#groupdel mis <刪除 mis 群組>
#tail -n 2 /etc/group
===================================
#chmod g+s /mis <將/mis 資料夾加上 SGID>
#ls -ld /mis <請觀察權限及擁有者,群組>
#touch /mis/test2
#ls -l /mis <請觀察權限及擁有者,群組>
===================
Lab: sticky bit
目的:不管權限為何不可以刪除其他人的檔案
#mkdir /test
#chmod 1777 /test <將/test 加上 sticky bit 權限並將權限設定為 777>
#touch /test/test.txt
#chmod 777 /test/test.txt
#ls -ld /test <請觀察權限及擁有者,群組>
#ls -l /test <請觀察權限及擁有者,群組>
#su - user1 -c "rm /test/test.txt" <以使用者 user1 刪除/test/test.txt -->失敗>
<因/test 目錄有設定 sticky bit 權限,故非本人不能刪除>
linux 記錄1
du -sh /etc
查總共己用多少
du -h --max-depth=1 /home
各子目錄共用多少
cp -i
會詢問
cp -p 保留屬性
ls -R 看整個子目錄
mkdir -p aaa/bbb/ccc 建整個目錄
rm -r aaa 刪整個目錄
touch file{1,1a,1b,2,2a} myfile 大量建檔案
echo file[^a] 排除法
echo file[a-z] 限定範圍
echo *a 找檔案尾為a
find . -name cat 找檔案為cat
find . -name cat -type f 找檔案
find . -name cat -type d 找目錄
find /etc -size +1k 找大於1k
Lab:locate,whereis,which
#cd /home/max
#yast -i findutils-locate <安裝 locate 相關套件>
#touch whatis
#locate whatis <找不到 whatis 因為剛建立沒有在 DB 內>
#updatedb <更新 DB>
#locate whatis
#whereis whatis
#which whatis
查總共己用多少
du -h --max-depth=1 /home
各子目錄共用多少
cp -i
會詢問
cp -p 保留屬性
ls -R 看整個子目錄
mkdir -p aaa/bbb/ccc 建整個目錄
rm -r aaa 刪整個目錄
touch file{1,1a,1b,2,2a} myfile 大量建檔案
echo file[^a] 排除法
echo file[a-z] 限定範圍
echo *a 找檔案尾為a
find . -name cat 找檔案為cat
find . -name cat -type f 找檔案
find . -name cat -type d 找目錄
find /etc -size +1k 找大於1k
Lab:locate,whereis,which
#cd /home/max
#yast -i findutils-locate <安裝 locate 相關套件>
#touch whatis
#locate whatis <找不到 whatis 因為剛建立沒有在 DB 內>
#updatedb <更新 DB>
#locate whatis
#whereis whatis
#which whatis
訂閱:
意見 (Atom)