>首先感谢您的帮助,我有一个简单的bash脚本,他正在阅读服务器列表,命令列表和回滚命令列表,脚本工作正常,
但我的问题与日志有关,因此我想将控制台上的输出记录到日志文件中。 问题是当我打开日志文件时,我可以看到带有日志的菜单,任何帮助从日志文件中排除菜单,
使用 导出日志 IM
exec > >(tee -a ${log_file} )
exec 2> >(tee -a ${log_file} >&2)
执行脚本(代码如下(后,我看到的是:
**************************************************************
test script
**************************************************************
** 1) Test ip connectivity for all the servers. **
** 2) Display the default config before apply the hardening.**
** 3) Executing the hardening changes. **
** 4) Display the new values after the hardening applied. **
** 5) Rollback to the default config. **
**************************************************************
Please enter a menu option and enter or x to exit. 3
Option 3 : Executing config.
当我检查日志时,我可以看到一个很好的日志,但菜单:(
[root@host1 newscript]#
[root@host1 newscript]#
[root@host1 newscript]# cat Hardening_log.txt
**************************************************************
test script
**************************************************************
** 1) Test ip connectivity for all the servers. **
** 2) Display the default config before apply the hardening.**
** 3) Executing the hardening changes. **
** 4) Display the new values after the hardening applied. **
** 5) Rollback to the default config. **
**************************************************************
Please enter a menu option and enter or x to exit.
Option 1 : Test ip connectivity for all the servers.
[ UP ] Server : 192.168.0.182
[ UP ] Server : 192.168.0.183
**************************************************************
test script
**************************************************************
** 1) Test ip connectivity for all the servers. **
** 2) Display the default config before apply the hardening.**
** 3) Executing the hardening changes. **
** 4) Display the new values after the hardening applied. **
** 5) Rollback to the default config. **
**************************************************************
Please enter a menu option and enter or x to exit.
Option 2 : Display the config.
___________________________________________________________________________________________________________________________________________________________________________
Starting executing commands for : 192.168.0.182
___________________________________________________________________________________________________________________________________________________________________________
[ PASSED ] Command executed : cat /etc/ssh/sshd_config | grep MaxAuthTries
Printing commands result : #MaxAuthTries 6
[ PASSED ] Command executed : chage -l sofiane | grep "Account expires"
Printing commands result : Account expires : Dec 31, 2022
___________________________________________________________________________________________________________________________________________________________________________
Starting executing commands for : 192.168.0.183
___________________________________________________________________________________________________________________________________________________________________________
[ PASSED ] Command executed : cat /etc/ssh/sshd_config | grep MaxAuthTries
Printing commands result : #MaxAuthTries 6
[ PASSED ] Command executed : chage -l sofiane | grep "Account expires"
Printing commands result : Account expires : Dec 31, 2022
**************************************************************
test script
**************************************************************
** 1) Test ip connectivity for all the servers. **
** 2) Display the default config before apply the hardening.**
** 3) Executing the hardening changes. **
** 4) Display the new values after the hardening applied. **
** 5) Rollback to the default config. **
**************************************************************
Please enter a menu option and enter or x to exit.
Option 3 : Executing config.
___________________________________________________________________________________________________________________________________________________________________________
Starting executing commands for : 192.168.0.182
___________________________________________________________________________________________________________________________________________________________________________
[ PASSED ] Command executed : sed -i '/^#MaxAuthTries/s/6/2/' /etc/ssh/sshd_config
[ PASSED ] Command executed : /usr/bin/chage -E 2021-12-31 sofiane
___________________________________________________________________________________________________________________________________________________________________________
Starting executing commands for : 192.168.0.183
___________________________________________________________________________________________________________________________________________________________________________
[ PASSED ] Command executed : sed -i '/^#MaxAuthTries/s/6/2/' /etc/ssh/sshd_config
[ PASSED ] Command executed : /usr/bin/chage -E 2021-12-31 sofiane
**************************************************************
test script
**************************************************************
** 1) Test ip connectivity for all the servers. **
** 2) Display the default config before apply the hardening.**
** 3) Executing the hardening changes. **
** 4) Display the new values after the hardening applied. **
** 5) Rollback to the default config. **
**************************************************************
Please enter a menu option and enter or x to exit.
谢谢你如此糊涂的帮助
他是我的代码:
#!/bin/bash
clear
#Echo with colors*****************
normal=`echo "