shell運行寫log

tee 重定向輸出到多個文件java

在執行Linux命令時,咱們既想把輸出保存到文件中,又想在屏幕上看到輸出內容,就能夠使用tee命令
要注意的是:在使用管道線時,前一個命令的標準錯誤輸出不會被tee讀取。日誌

tee file         //覆蓋
tee -a file     //追加
tee -            //輸出到標準輸出兩次
tee - -          //輸出到標準輸出三次
tee file1 file2 -    //輸出到標準輸出兩次,並寫到那兩個文件中
ls | tee file   

  另:把標準錯誤也被tee讀取blog

ls "*" 2>&1 | tee ls.txt it

1. class

#!/bin/sh
if [ $# -ne 1 ]
then 
 echo "Usage:sh $0   YYYYMMDD "
  exit 1
fi
V_DT=$1

exec 1>>`basename $0`.log
date_current=`date +%Y%m%d`
echo "傳入時間爲: ${V_DT}"
echo "系統時間爲: ${date_current}"
exit 0

  2. test

#!/bin/sh
if [ $# -ne 1 ]
then 
 echo "Usage:sh $0   YYYYMMDD "
  exit 1
fi
V_DT=$1

date_current=`date +%Y%m%d`
echo "傳入時間爲: ${V_DT}"  >> $(basename $0).log
echo "系統時間爲: ${date_current}" >> $(basename $0).log
echo "tee commant test" 2>&1|tee -a $(basename $0).log     --日誌和屏幕都存在
exit 0
相關文章
相關標籤/搜索