我正在创建一个bash脚本来自动执行某些命令,我在将错误检查写入同一文件时遇到了一些麻烦.
#!/bin/bash
touch ErrorLog.txt
bro-cut service < conn.log | sort | uniq -c > ProtocolHierarchy.txt
if [ $? -eq 0 ]; then
echo -e "OK Protocol Hierarchy Created\n" > ErrorLog.txt
else
echo -e "FAILED Creating Protocol Hierarchy\n" > ErrorLog.txt
fi
bro-cut id.orig_h < dns.log | sort | uniq -c > AllIPAddresses.txt
if [ $? -eq 0 ]; then
echo -e "OK Created all IP Addresses\n" > ErrorLog.txt
else
echo -e "FAILED Creating all IP Addresses\n" > ErrorLog.txt
fi
Run Code Online (Sandbox Code Playgroud)
目标是拥有一个我可以打开的文件,看到所有命令都工作或失败,目前文件看起来像这样
-e …Run Code Online (Sandbox Code Playgroud)