Running tcpdump in the background linux

Viewed 6943

Linux (Gentoo) and Linux (Redhat on AWS free)

I am a member of the pcap group and can run tcpdump as a non-root user.

I am trying to run a script the runs tcpdump in the background and send the output to a text file temp.txt. My script will create a file called temp.txt but /usr/bin/tcpdump -tttt will not write to it.

I can run the script without nohup.

/usr/sbin/tcpdump -c 10 -tttt > `pwd`/temp.txt

Why will the nohup not work? The following is my script:

#!/bin/bash
#tpd-txt.sh
nohup /usr/sbin/tcpdump -c 10 -tttt > `pwd`/temp.txt > /dev/null 2>&1 &
1 Answers

Try

nohup /usr/sbin/tcpdump -c 10 -tttt 2>&1  >./temp.txt &

I am assuming you want to redirect standard error to output so it can be captured in logs.

Below is quick reference guide for output redirection in 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.
Related