There is a script that runs tcpdump. How can I see tcpdump work in the console in real time, knowing its pid? The script itself is run via cron.

  • and how exactly does it start? Maybe he does not output anything to the terminal? - KoVadim
  • Runs with os: os.system(tcpdump -i eth0) . - kmz_61
  • It is clear that using os (operating system). How exactly? - KoVadim
  • The process hangs in the background. using ps ax it can be seen, but it is not clear how to output to the console - kmz_61
  • one

1 answer 1

Probably a Python script and it is written wrong

 os.system(tcpdump -i eth0) 

that's how:

 os.system("tcpdump -i eth0") 

Knowing pid when you run this script will not help you. In fact, you need to do this:

  1. Run crontab -e
  2. Find a row in the table that runs your script
  3. In this line, most likely, there is something like > / dev / null
  4. Replace with something like >> ~ / log_tcpdump.txt
  5. Run tail -f ~ / log_tcpdump.txt
  6. Wait for the script to run by time
  7. Watch his issue

The comments link to the recipe type:

tail -f / proc // fd / 1

Well ... It will give effect at once. And the next time you start your script, it will have a different PID and again - everything from the beginning.

  • With the pid process everything is easy. If you are sure that there is only one process, then somewhere tai -f /proc/$(pidof tcpdump)/fd/1 . If there can be a lot of processes, then you need to do a cycle. for i in $(pidof tcpdump); do tailf /proc/$i/fd/1; done for i in $(pidof tcpdump); do tailf /proc/$i/fd/1; done (yes, sometimes tailf is better than tailf -f ) - KoVadim
  • @KoVadim, tailf - obsolete command, will be removed in 2017 - mymedia