LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-26-2016, 07:42 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,555

Rep: Reputation: 177Reputation: 177
Best way to run non-daemon job


I want to run tcpdump at boot and direct the output to a speicifed file. I then want logrotate to restart that job periodically. I am running Slackware 14.1

I can put the job in /etc/rc.d/rc.local:

tcpdump -tttt -nn portrange 1-4 and 'tcp[13] & 4 != 0' >> /var/log/mylog 2>&1 &

Would that be the best way to do it at start-up? Would I need nohup?

with logrotate I'm thinking:

Code:
/var/log/mylog
{
    weekly
    rotate 12

    sharedschriptes
        prerotate
            killall tcpdump
        endscript

        postrotate
            tcpdump -tttt -nn portrange 1-4 and 'tcp[13] & 4 != 0' > /var/log/mylog 2>&1 &
        endscript
}
Would that work running putting the '&' at the end of the command in the logrotate script?

Last edited by mfoley; 06-26-2016 at 07:44 PM.
 
Old 06-27-2016, 05:55 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
It looks like it should work with the & at the end. The "killall" will unfortunately get any other instances of "tcpdump" that might be running.

If you examine the variable $! immediately after running "tcpdump" in the post-rotate script, you will get the PID of tcpdump and that can be saved in a file and used later for restarting. There are drawbacks to that method, so alternately you could search the ouput of "ps" for the right instance of "tcpdump" to kill.

About the redirect, you won't get that useful information from just redirecting stdin and stdout from "tcpdump". If you want the raw packets, then capture using -w instead of >>
 
Old 07-03-2016, 12:12 PM   #3
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,555

Original Poster
Rep: Reputation: 177Reputation: 177
Turbocapitalist, OK, I'm going to try it and see what happens. Normally there won't be any other tcpdumps running, so I needn't worry about capturing and saving the PID. That tcpdump gives me e.g.:

2016-07-02 12:33:42.587933 IP 98.102.63.107.1910 > 98.30.204.114.61355: Flags [R.], seq 1405462380, ack 207756548, win 0, length 0

which is all I need. I don't need the actual packet. I need the timestamp and the IP to compare with the log.samba to track break-ins (the log.samba does not give the IP for non-local login attempts).

I'll post back results, though it may be a while.
 
  


Reply

Tags
daemon, logrotate, tcpdump



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to enter command because of daemon job on startup Brandt087 Linux - Newbie 2 02-20-2015 03:53 AM
Debian daily cron job won't run, but does run in cron.hourly. sandersch Linux - General 7 05-24-2012 01:50 AM
run as daemon? bjh SUSE / openSUSE 1 11-08-2008 12:56 PM
Enable daemon to run with service daemon start,etc baddah Programming 6 12-02-2007 05:51 PM
run as a daemon dellcom1800 Linux - Software 6 10-15-2004 07:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration