bash -x输出到logfile

#! /bin/bash

logfile=/var/log/xltest.log

echo `date` >> ${logfile} 2>&1

echo postinst arg:$1 >> ${logfile} 2>&1

exec {BASH_XTRACEFD}>>${logfile}    #//bash -x输出到logfile

exec 1>>${logfile}  #//标准输出到文件

exec 2>>${logfile} #//标准错误输出到文件

set -x        #//用于脚本调试。把它下面的命令打印到屏幕  set -x 是开启 set +x是关闭

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure! Here's a shell script that accepts a directory as a parameter, recursively traverses all files and subdirectories within that directory, and outputs the count of `.log` and `.txt` files along with their respective file paths: ```bash #!/bin/bash # Function to recursively traverse directory traverse_directory() { local dir=$1 # Loop through each file and subdirectory in the given directory for file in "$dir"/*; do if [ -f "$file" ]; then # Check if the file has .log or .txt extension if [[ $file == *.log ]]; then echo "Log file found: $file" ((log_count++)) elif [[ $file == *.txt ]]; then echo "Text file found: $file" ((txt_count++)) fi elif [ -d "$file" ]; then # Recursively call the function for subdirectories traverse_directory "$file" fi done } # Check if directory is provided as argument if [ $# -eq 0 ]; then echo "Please provide a directory as an argument." exit 1 fi # Initialize file count variables log_count=0 txt_count=0 # Call the function to traverse the directory traverse_directory "$1" # Output the file counts echo "Number of log files: $log_count" echo "Number of text files: $txt_count" ``` To use this script, save it to a file (e.g., `file_count.sh`), make it executable using `chmod +x file_count.sh`, and then run it with the desired directory as the argument: ```bash ./file_count.sh /path/to/directory ``` Replace `/path/to/directory` with the actual directory path you want to traverse. The script will recursively search for `.log` and `.txt` files and print their counts along with the file paths.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值