linux用shell指令碼模擬時鐘 指令碼錄製

2021-08-07 10:11:22 字數 828 閱讀 4770

#!/bin/bash

# this is a clock, it will display time once a second, in the same position

# file name: clock.sh

tput sc

while true

do echo -n `date`

sleep 1

tput rc

tput ed

done

tput sc: 儲存游標位置

tput rc: 恢復游標位置

tput ed:清除游標之後的資料

這個指令碼做的工作是,先儲存游標位置,每輸出一次時間之後,就恢復游標位置、並清除游標之後的內容。這樣時間就不停地(每隔一秒)寫入原來的位置並被清除,看起來就是乙個時鐘

由於時鐘是乙個動態的變化過程,我使用下面的辦法錄製了執行過程:

qingsong@db2a:/tmp$

script -t 2> timing.log -a output.session

qingsong@db2a:/tmp$

cat clock.sh

qingsong@db2a:/tmp$

bash clock.sh

thu aug 24 21:29:22 pdt 2017

^cqingsong@db2a:/tmp$

exit

$scriptreplay timing.log output.session

linux用shell指令碼解決被ddos攻擊的問題

最近 常常被人ddos所以寫了乙個小程式用來自動封鎖ip,如下 for dostatus netstat na grep established awk awk f sort uniq c sort rn head 10 grep v e 127.0 192.168 118.163.81 66.24...

用指令碼模擬抽籤

1 寫乙個指令碼執行後,輸入名字,產生隨機數01 99之間的數字。2 如果相同的名字重複輸入,抓到的數字還是第一次抓取的結果,3 前面已經抓到的數字,下次不能在出現相同數字。4 第乙個輸入名字後,螢幕輸出資訊,並將名字和數字記錄到檔案裡,程式不能退出 繼續等待別的學生輸入。理性分析 乙個隨機數對應乙...

用shell指令碼監控系統

簡單的用shell指令碼寫乙個 監控 程式作為思路,大致為 實時檢測系統的記憶體使用率,如果大於閾值那麼報警 如果有條件可以使用簡訊介面或者實在不行可以使用郵件通知 並記錄到日誌檔案裡,如果小於閾值那麼正常顯示。bin bash check mem 100 free grep i mem awk b...