Linux(gentoo)和linux(AWS上的Redhat免费)
我是pcap组的成员,可以以非root用户身份运行tcpdump。
我正在尝试在后台运行脚本tcpdump并将输出发送到文本文件temp.txt我的脚本将创建一个名为temp.txt的文件,但/ usr / bin / tcpdump -tttt不会写入该文件。我可以在没有nohup的情况下运行脚本。
/usr/sbin/tcpdump -c 10 -tttt > `pwd`/temp.txt
[请丢下我骨头,为什么nohup无法正常工作?以下是我的脚本:
#!/bin/bash
#tpd-txt.sh
nohup /usr/sbin/tcpdump -c 10 -tttt > `pwd`/temp.txt > /dev/null 2>&1 &
尝试
nohup /usr/sbin/tcpdump -c 10 -tttt 2>&1 >./temp.txt &
我假设您要将标准错误重定向到输出,以便可以在日志中捕获它。
以下是bash中输出重定向的快速参考指南。
1>filename
# Redirect stdout to file "filename."
1>>filename
# Redirect and append stdout to file "filename."
2>filename
# Redirect stderr to file "filename."
2>>filename
# Redirect and append stderr to file "filename."
&>filename
# Redirect both stdout and stderr to file "filename."
2>&1
# Redirects stderr to stdout.
# Error messages get sent to the same place as standard output.