Executing a script after a TCP connection closes












0














I'm trying to figure out a way to execute a given script (a file) after a TCP connection closes, and if possible filter out the interface it was going through. Now, what i want to do with this data is to store the bytes sent through the connection and if the stored value achieves a given number, store that as well and shut down the interface. Basically, i want monthly traffic limiting, which won't get lost on every reboot and stuff like that. So far I looked at tcpdump, iptables and ipband options, but none of those had options for my idea.










share|improve this question
























  • Does it have to be at the end of a TCP connection? Why not just look at the interface counters every minute or two, and work on that?
    – ilkkachu
    Sep 26 at 17:29












  • Well, it would be better performance-wise (atleast in my opinion) and you can send a fair amount of data under that one or two minutes with 1GBPS uplink on every guest. But if it isn't possible i will definitely give that one a shot.
    – Martin Magyarics
    Sep 26 at 17:33










  • Are you concerned that the program would take too long to notice the bandwidth use, and that the user could use too much bandwidth before their account was disabled?
    – Nick ODell
    Sep 26 at 17:39










  • Well, with 1-2 minute checks, yes. Maybe with smaller intervals it would be better, but i really don't know what would be the optimal value with that method.
    – Martin Magyarics
    Sep 26 at 17:44










  • The real problem with the timed method for me is the interval anyways. Even if i use a 10 second interval, that's a lot of + data.
    – Martin Magyarics
    Sep 26 at 17:49
















0














I'm trying to figure out a way to execute a given script (a file) after a TCP connection closes, and if possible filter out the interface it was going through. Now, what i want to do with this data is to store the bytes sent through the connection and if the stored value achieves a given number, store that as well and shut down the interface. Basically, i want monthly traffic limiting, which won't get lost on every reboot and stuff like that. So far I looked at tcpdump, iptables and ipband options, but none of those had options for my idea.










share|improve this question
























  • Does it have to be at the end of a TCP connection? Why not just look at the interface counters every minute or two, and work on that?
    – ilkkachu
    Sep 26 at 17:29












  • Well, it would be better performance-wise (atleast in my opinion) and you can send a fair amount of data under that one or two minutes with 1GBPS uplink on every guest. But if it isn't possible i will definitely give that one a shot.
    – Martin Magyarics
    Sep 26 at 17:33










  • Are you concerned that the program would take too long to notice the bandwidth use, and that the user could use too much bandwidth before their account was disabled?
    – Nick ODell
    Sep 26 at 17:39










  • Well, with 1-2 minute checks, yes. Maybe with smaller intervals it would be better, but i really don't know what would be the optimal value with that method.
    – Martin Magyarics
    Sep 26 at 17:44










  • The real problem with the timed method for me is the interval anyways. Even if i use a 10 second interval, that's a lot of + data.
    – Martin Magyarics
    Sep 26 at 17:49














0












0








0







I'm trying to figure out a way to execute a given script (a file) after a TCP connection closes, and if possible filter out the interface it was going through. Now, what i want to do with this data is to store the bytes sent through the connection and if the stored value achieves a given number, store that as well and shut down the interface. Basically, i want monthly traffic limiting, which won't get lost on every reboot and stuff like that. So far I looked at tcpdump, iptables and ipband options, but none of those had options for my idea.










share|improve this question















I'm trying to figure out a way to execute a given script (a file) after a TCP connection closes, and if possible filter out the interface it was going through. Now, what i want to do with this data is to store the bytes sent through the connection and if the stored value achieves a given number, store that as well and shut down the interface. Basically, i want monthly traffic limiting, which won't get lost on every reboot and stuff like that. So far I looked at tcpdump, iptables and ipband options, but none of those had options for my idea.







linux tcp exec data traffic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Rui F Ribeiro

38.8k1479128




38.8k1479128










asked Sep 26 at 17:22









Martin Magyarics

64




64












  • Does it have to be at the end of a TCP connection? Why not just look at the interface counters every minute or two, and work on that?
    – ilkkachu
    Sep 26 at 17:29












  • Well, it would be better performance-wise (atleast in my opinion) and you can send a fair amount of data under that one or two minutes with 1GBPS uplink on every guest. But if it isn't possible i will definitely give that one a shot.
    – Martin Magyarics
    Sep 26 at 17:33










  • Are you concerned that the program would take too long to notice the bandwidth use, and that the user could use too much bandwidth before their account was disabled?
    – Nick ODell
    Sep 26 at 17:39










  • Well, with 1-2 minute checks, yes. Maybe with smaller intervals it would be better, but i really don't know what would be the optimal value with that method.
    – Martin Magyarics
    Sep 26 at 17:44










  • The real problem with the timed method for me is the interval anyways. Even if i use a 10 second interval, that's a lot of + data.
    – Martin Magyarics
    Sep 26 at 17:49


















  • Does it have to be at the end of a TCP connection? Why not just look at the interface counters every minute or two, and work on that?
    – ilkkachu
    Sep 26 at 17:29












  • Well, it would be better performance-wise (atleast in my opinion) and you can send a fair amount of data under that one or two minutes with 1GBPS uplink on every guest. But if it isn't possible i will definitely give that one a shot.
    – Martin Magyarics
    Sep 26 at 17:33










  • Are you concerned that the program would take too long to notice the bandwidth use, and that the user could use too much bandwidth before their account was disabled?
    – Nick ODell
    Sep 26 at 17:39










  • Well, with 1-2 minute checks, yes. Maybe with smaller intervals it would be better, but i really don't know what would be the optimal value with that method.
    – Martin Magyarics
    Sep 26 at 17:44










  • The real problem with the timed method for me is the interval anyways. Even if i use a 10 second interval, that's a lot of + data.
    – Martin Magyarics
    Sep 26 at 17:49
















Does it have to be at the end of a TCP connection? Why not just look at the interface counters every minute or two, and work on that?
– ilkkachu
Sep 26 at 17:29






Does it have to be at the end of a TCP connection? Why not just look at the interface counters every minute or two, and work on that?
– ilkkachu
Sep 26 at 17:29














Well, it would be better performance-wise (atleast in my opinion) and you can send a fair amount of data under that one or two minutes with 1GBPS uplink on every guest. But if it isn't possible i will definitely give that one a shot.
– Martin Magyarics
Sep 26 at 17:33




Well, it would be better performance-wise (atleast in my opinion) and you can send a fair amount of data under that one or two minutes with 1GBPS uplink on every guest. But if it isn't possible i will definitely give that one a shot.
– Martin Magyarics
Sep 26 at 17:33












Are you concerned that the program would take too long to notice the bandwidth use, and that the user could use too much bandwidth before their account was disabled?
– Nick ODell
Sep 26 at 17:39




Are you concerned that the program would take too long to notice the bandwidth use, and that the user could use too much bandwidth before their account was disabled?
– Nick ODell
Sep 26 at 17:39












Well, with 1-2 minute checks, yes. Maybe with smaller intervals it would be better, but i really don't know what would be the optimal value with that method.
– Martin Magyarics
Sep 26 at 17:44




Well, with 1-2 minute checks, yes. Maybe with smaller intervals it would be better, but i really don't know what would be the optimal value with that method.
– Martin Magyarics
Sep 26 at 17:44












The real problem with the timed method for me is the interval anyways. Even if i use a 10 second interval, that's a lot of + data.
– Martin Magyarics
Sep 26 at 17:49




The real problem with the timed method for me is the interval anyways. Even if i use a 10 second interval, that's a lot of + data.
– Martin Magyarics
Sep 26 at 17:49















active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471645%2fexecuting-a-script-after-a-tcp-connection-closes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471645%2fexecuting-a-script-after-a-tcp-connection-closes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

サソリ

広島県道265号伴広島線

Setup Asymptote in Texstudio