最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Linux??注意!這個技巧讓你的腳本輸出永不丟失

2023-08-17 15:14 作者:微思網(wǎng)絡  | 我要投稿



對于??的Linux系統(tǒng)管理員來說,是否有過這樣的經(jīng)歷:在 crontab 計劃任務中運?了?個腳本,然后希望查看其輸出,卻因沒有合適的記錄?式?感到困擾?

有沒有想過讓腳本運?的所有輸出?動保存,以便于你在需要時隨時查看?

今天,我將向你展??個?法,讓你得?應?。

?先,我們需要?個腳本,我準備了?個名為 disktest.sh 的腳本,它的功能是創(chuàng)建?個?件并進?各種塊??的讀寫測試。腳本內容如下:

#!/bin/bash
echo?"creating?a?file?to?work?with"
dd?if=/dev/zero?of=/var/tmp/infile?count=1175000
for?bs?in?1k?2k?4k?8k?16k?32k?64k?128k?256k?512k?1M?2M 4M?8M
do
echo?"Testing?block?size?=?$bs"
dd?if=/var/tmp/infile?of=/var/tmp/outfile?bs=$bs
echo?""
done
rm?/var/tmp/infile?/var/tmp/outfile

讓這個腳本每分鐘運??次,并將所有的輸出保存到?志中

[root@localhost?~]#?crontab?-e
*?*?*?*?*?/root/disktest.sh?2>&1?|?logger?-t?disktest

意思是,每分鐘運??次/root/disktest.sh 腳本,并將所有的輸出重定向(2>&1)到 logger 命令。


logger 命令將這些輸出作為系統(tǒng)?志進?處理,并添加?個標簽 "disktest"


這樣,你的disktest.sh腳本的所有輸出就會被?動保存到/var/log/messages?件中。

當你運?disktest腳本后,你可以在messages?件中看到類似以下內容,它記錄了每?次的腳本輸出:

Aug?109:58:02localhost?disktest11048]:?Testingblocksize=1K
Aug?109:58:02localhost?disktest[11048]:587500+0recordsin
Aug?109:58:02?localhost?disktest[11048]:587500+0?records?out
Aug?109:58:02?localhost?disktest[11048]:601600000?bytes(602M574MiB)copied,?533701?s,
1.1GB/s
Aug?109:58:02?localhost?disktest[11048]:
Aug?109:58:02?localhost?disktest[11048]:Testingblocksize=2k
Aug?109:58:03localhost?disktest[11048]293750+0?recordsin
Aug?109:58:03localhost?disktest[11048]:293750+0?records?out
Aug?109:58:03localhost?disktest[11048]:601600000?bytes(602?M574?MiB)copied.379295?s,
1.6?GB/s
Aug?109:58:03?localhost?disktest[11048]:
Aug?109:58:03localhost?disktest[11048]:?Testingblocksize=4k
Aug?109:58:03localhost?disktest[11048]:?146875+0?recordsin
Aug?109:58:03localhost?disktest[11048]:?146875+0?records?out
Aug?109:58:03localhost?disktest[11048]:601600000?bytes602M574MBcopie?327263s,
1.8?GB/s
Aug?109:58:03localhost?disktest[11048]:
Aug?109:58:03localhost?disktest[11048]:Testingblocksize=8k
Aug?109:58:03localhost?disktest[11048]:?73437+1?recordsin
Aug?109:58:03localhost?disktest[11048]:?73437+1?records?out
Aug?109:58:03localhost?disktest[11048]:601600000?bytes(602MB574?MiBcopie?299182s,
2.0?GB/s
Aug109:58:03localhost?disktest[11048]:
Aug?109:58:03localhost?disktest[11048]?Testingblocksize=16k
Aug?109:58:04?localhost?disktest[11048]:36718+1?recordsin
Aug?109:58:04?localhost?disktest[11048]:36718+1?records?out
Aug?109:58:04localhost?disktest[11048]:601600000?bytes(602MB574MB)copied?282859s,
2.1?GB/s


這是?個簡單卻強?的技巧,相信你在未來的?作和學習中會發(fā)現(xiàn)其巨?的價值。




Linux??注意!這個技巧讓你的腳本輸出永不丟失的評論 (共 條)

分享到微博請遵守國家法律
吐鲁番市| 安吉县| 峡江县| 嘉祥县| 铅山县| 久治县| 航空| 水城县| 宝兴县| 格尔木市| 大理市| 昌吉市| 明光市| 彰化市| 西畴县| 荣昌县| 施甸县| 百色市| 石台县| 建德市| 清水县| 乌拉特前旗| 石门县| 安泽县| 犍为县| 桐乡市| 固原市| 嘉祥县| 庄河市| 广河县| 武安市| 虎林市| 福州市| 佛冈县| 靖边县| 临洮县| 吐鲁番市| 花莲市| 老河口市| 吉首市| 乌恰县|