Run process before opening file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I want to achieve the following: every time I attempt to open a file (which is /etc/hosts in this case), a process/script (I don't know what the right term is) starts running. This script would require the user to do some task, e.g. spending x minutes reading some pdf or writing x lines of some document created by this script. Until this task is finished, the file won't open.



Is this possible? Can I achieve it with a bash script? Can I also guarantee that the file doesn't open if the process is somehow interrupted before its finished? And can I trigger the process independently of the way in which I open the file? E.g. from terminal or with the mouse.



I don't know much about computers, so the terminology I am using and the tags below are probably not the best. If this is the case, I apprecaite any convenient edit of the question. Thanks!







share|improve this question



















  • To try to restrict the number of possible ways of opening the file, would you want to do this only when a particular user opens the file for editing (writing), e.g. if someone did sudo vim /etc/hosts? What is the underlying issue that you are wanting to solve?
    – Kusalananda
    Jun 6 at 8:56










  • @Kusalananda I am the only user. Hence, sudo vim /etc/hosts should not be an exception. Neither should be when replacing vim by any other text editor, nor commands like xdg-open. I am trying to avoid procrastination with sites such as Youtube. I can block it via this file. But if I can undo the change any time, it is not much of a help. For this reason I am looking for a system that requires a large amount of effort to change the file back, so that I only do it when it really is necessary. And ideally this effort would be productive, e.g. forcing me to write some tex file or reading some pdf.
    – Pedro
    Jun 6 at 9:04










  • If at all possible. Hand over administration of the system to another trusted human being and get them to change the root password and restrict your sudo rights.
    – Kusalananda
    Jun 6 at 9:14






  • 2




    If you've already blocked the sites and now want to stop yourself from unblocking them, I think we've reached the limits of the technical problem and are now in the realms of the human problem :) If your urge to procrastinate is so high you'll go to the trouble of unblocking the site, then you really need to find a non-technical solution. Anything you can do, you can also undo.
    – terdon♦
    Jun 6 at 9:21







  • 2




    Only if you have the password to the router. And the outside connection has to be protected by the cabinet too, so that you can't just plug in a bypass ethernet cable.
    – Kusalananda
    Jun 6 at 9:31














up vote
1
down vote

favorite












I want to achieve the following: every time I attempt to open a file (which is /etc/hosts in this case), a process/script (I don't know what the right term is) starts running. This script would require the user to do some task, e.g. spending x minutes reading some pdf or writing x lines of some document created by this script. Until this task is finished, the file won't open.



Is this possible? Can I achieve it with a bash script? Can I also guarantee that the file doesn't open if the process is somehow interrupted before its finished? And can I trigger the process independently of the way in which I open the file? E.g. from terminal or with the mouse.



I don't know much about computers, so the terminology I am using and the tags below are probably not the best. If this is the case, I apprecaite any convenient edit of the question. Thanks!







share|improve this question



















  • To try to restrict the number of possible ways of opening the file, would you want to do this only when a particular user opens the file for editing (writing), e.g. if someone did sudo vim /etc/hosts? What is the underlying issue that you are wanting to solve?
    – Kusalananda
    Jun 6 at 8:56










  • @Kusalananda I am the only user. Hence, sudo vim /etc/hosts should not be an exception. Neither should be when replacing vim by any other text editor, nor commands like xdg-open. I am trying to avoid procrastination with sites such as Youtube. I can block it via this file. But if I can undo the change any time, it is not much of a help. For this reason I am looking for a system that requires a large amount of effort to change the file back, so that I only do it when it really is necessary. And ideally this effort would be productive, e.g. forcing me to write some tex file or reading some pdf.
    – Pedro
    Jun 6 at 9:04










  • If at all possible. Hand over administration of the system to another trusted human being and get them to change the root password and restrict your sudo rights.
    – Kusalananda
    Jun 6 at 9:14






  • 2




    If you've already blocked the sites and now want to stop yourself from unblocking them, I think we've reached the limits of the technical problem and are now in the realms of the human problem :) If your urge to procrastinate is so high you'll go to the trouble of unblocking the site, then you really need to find a non-technical solution. Anything you can do, you can also undo.
    – terdon♦
    Jun 6 at 9:21







  • 2




    Only if you have the password to the router. And the outside connection has to be protected by the cabinet too, so that you can't just plug in a bypass ethernet cable.
    – Kusalananda
    Jun 6 at 9:31












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to achieve the following: every time I attempt to open a file (which is /etc/hosts in this case), a process/script (I don't know what the right term is) starts running. This script would require the user to do some task, e.g. spending x minutes reading some pdf or writing x lines of some document created by this script. Until this task is finished, the file won't open.



Is this possible? Can I achieve it with a bash script? Can I also guarantee that the file doesn't open if the process is somehow interrupted before its finished? And can I trigger the process independently of the way in which I open the file? E.g. from terminal or with the mouse.



I don't know much about computers, so the terminology I am using and the tags below are probably not the best. If this is the case, I apprecaite any convenient edit of the question. Thanks!







share|improve this question











I want to achieve the following: every time I attempt to open a file (which is /etc/hosts in this case), a process/script (I don't know what the right term is) starts running. This script would require the user to do some task, e.g. spending x minutes reading some pdf or writing x lines of some document created by this script. Until this task is finished, the file won't open.



Is this possible? Can I achieve it with a bash script? Can I also guarantee that the file doesn't open if the process is somehow interrupted before its finished? And can I trigger the process independently of the way in which I open the file? E.g. from terminal or with the mouse.



I don't know much about computers, so the terminology I am using and the tags below are probably not the best. If this is the case, I apprecaite any convenient edit of the question. Thanks!









share|improve this question










share|improve this question




share|improve this question









asked Jun 6 at 8:43









Pedro

1113




1113











  • To try to restrict the number of possible ways of opening the file, would you want to do this only when a particular user opens the file for editing (writing), e.g. if someone did sudo vim /etc/hosts? What is the underlying issue that you are wanting to solve?
    – Kusalananda
    Jun 6 at 8:56










  • @Kusalananda I am the only user. Hence, sudo vim /etc/hosts should not be an exception. Neither should be when replacing vim by any other text editor, nor commands like xdg-open. I am trying to avoid procrastination with sites such as Youtube. I can block it via this file. But if I can undo the change any time, it is not much of a help. For this reason I am looking for a system that requires a large amount of effort to change the file back, so that I only do it when it really is necessary. And ideally this effort would be productive, e.g. forcing me to write some tex file or reading some pdf.
    – Pedro
    Jun 6 at 9:04










  • If at all possible. Hand over administration of the system to another trusted human being and get them to change the root password and restrict your sudo rights.
    – Kusalananda
    Jun 6 at 9:14






  • 2




    If you've already blocked the sites and now want to stop yourself from unblocking them, I think we've reached the limits of the technical problem and are now in the realms of the human problem :) If your urge to procrastinate is so high you'll go to the trouble of unblocking the site, then you really need to find a non-technical solution. Anything you can do, you can also undo.
    – terdon♦
    Jun 6 at 9:21







  • 2




    Only if you have the password to the router. And the outside connection has to be protected by the cabinet too, so that you can't just plug in a bypass ethernet cable.
    – Kusalananda
    Jun 6 at 9:31
















  • To try to restrict the number of possible ways of opening the file, would you want to do this only when a particular user opens the file for editing (writing), e.g. if someone did sudo vim /etc/hosts? What is the underlying issue that you are wanting to solve?
    – Kusalananda
    Jun 6 at 8:56










  • @Kusalananda I am the only user. Hence, sudo vim /etc/hosts should not be an exception. Neither should be when replacing vim by any other text editor, nor commands like xdg-open. I am trying to avoid procrastination with sites such as Youtube. I can block it via this file. But if I can undo the change any time, it is not much of a help. For this reason I am looking for a system that requires a large amount of effort to change the file back, so that I only do it when it really is necessary. And ideally this effort would be productive, e.g. forcing me to write some tex file or reading some pdf.
    – Pedro
    Jun 6 at 9:04










  • If at all possible. Hand over administration of the system to another trusted human being and get them to change the root password and restrict your sudo rights.
    – Kusalananda
    Jun 6 at 9:14






  • 2




    If you've already blocked the sites and now want to stop yourself from unblocking them, I think we've reached the limits of the technical problem and are now in the realms of the human problem :) If your urge to procrastinate is so high you'll go to the trouble of unblocking the site, then you really need to find a non-technical solution. Anything you can do, you can also undo.
    – terdon♦
    Jun 6 at 9:21







  • 2




    Only if you have the password to the router. And the outside connection has to be protected by the cabinet too, so that you can't just plug in a bypass ethernet cable.
    – Kusalananda
    Jun 6 at 9:31















To try to restrict the number of possible ways of opening the file, would you want to do this only when a particular user opens the file for editing (writing), e.g. if someone did sudo vim /etc/hosts? What is the underlying issue that you are wanting to solve?
– Kusalananda
Jun 6 at 8:56




To try to restrict the number of possible ways of opening the file, would you want to do this only when a particular user opens the file for editing (writing), e.g. if someone did sudo vim /etc/hosts? What is the underlying issue that you are wanting to solve?
– Kusalananda
Jun 6 at 8:56












@Kusalananda I am the only user. Hence, sudo vim /etc/hosts should not be an exception. Neither should be when replacing vim by any other text editor, nor commands like xdg-open. I am trying to avoid procrastination with sites such as Youtube. I can block it via this file. But if I can undo the change any time, it is not much of a help. For this reason I am looking for a system that requires a large amount of effort to change the file back, so that I only do it when it really is necessary. And ideally this effort would be productive, e.g. forcing me to write some tex file or reading some pdf.
– Pedro
Jun 6 at 9:04




@Kusalananda I am the only user. Hence, sudo vim /etc/hosts should not be an exception. Neither should be when replacing vim by any other text editor, nor commands like xdg-open. I am trying to avoid procrastination with sites such as Youtube. I can block it via this file. But if I can undo the change any time, it is not much of a help. For this reason I am looking for a system that requires a large amount of effort to change the file back, so that I only do it when it really is necessary. And ideally this effort would be productive, e.g. forcing me to write some tex file or reading some pdf.
– Pedro
Jun 6 at 9:04












If at all possible. Hand over administration of the system to another trusted human being and get them to change the root password and restrict your sudo rights.
– Kusalananda
Jun 6 at 9:14




If at all possible. Hand over administration of the system to another trusted human being and get them to change the root password and restrict your sudo rights.
– Kusalananda
Jun 6 at 9:14




2




2




If you've already blocked the sites and now want to stop yourself from unblocking them, I think we've reached the limits of the technical problem and are now in the realms of the human problem :) If your urge to procrastinate is so high you'll go to the trouble of unblocking the site, then you really need to find a non-technical solution. Anything you can do, you can also undo.
– terdon♦
Jun 6 at 9:21





If you've already blocked the sites and now want to stop yourself from unblocking them, I think we've reached the limits of the technical problem and are now in the realms of the human problem :) If your urge to procrastinate is so high you'll go to the trouble of unblocking the site, then you really need to find a non-technical solution. Anything you can do, you can also undo.
– terdon♦
Jun 6 at 9:21





2




2




Only if you have the password to the router. And the outside connection has to be protected by the cabinet too, so that you can't just plug in a bypass ethernet cable.
– Kusalananda
Jun 6 at 9:31




Only if you have the password to the router. And the outside connection has to be protected by the cabinet too, so that you can't just plug in a bypass ethernet cable.
– Kusalananda
Jun 6 at 9:31










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










To stop yourself, as root, to undo the blocking of a website, you will have to give up control of the blocking and unblocking process and involve another human being.



The radical solution would be to just give up root privileges on the machine to some other trusted human, and at least to severely restrict the available operations that you can do through sudo. On a Unix system, virtually all software can be installed in one's home directory, if one's willing to put one's mind to it.



The other solution is to move the actual blocking process from the machine entirely, and let that be handled by a separate piece of equipment, like a locked-away router. Note that the router would also need to block tunneling through SSH, and other creative ways of connecting through other machines.



The protection of the router's configuration and physical access would also include protection of the external network outlet as to not allow you to tamper with the blocking by unplugging the router and bypassing it with an ethernet cable.



The key for accessing the router, and the router's admin password, would not be in your possession.



There might also be something one could do with virtual machines or containers (or possibly even just a chroot), so that the external connection would be protected by "another system" (the host machine) which you have no easy access to, while you work on the virtual machine or in the container.



I believe this is the limit to the technical solutions to your issue. As such, they are not limited to Unix systems. The next step would be to work with personal behaviour in other ways, such as through changing the way you work (always be visible by someone who cares), or seek outside help from a behaviour therapist or similar.






share|improve this answer























    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f448129%2frun-process-before-opening-file%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    To stop yourself, as root, to undo the blocking of a website, you will have to give up control of the blocking and unblocking process and involve another human being.



    The radical solution would be to just give up root privileges on the machine to some other trusted human, and at least to severely restrict the available operations that you can do through sudo. On a Unix system, virtually all software can be installed in one's home directory, if one's willing to put one's mind to it.



    The other solution is to move the actual blocking process from the machine entirely, and let that be handled by a separate piece of equipment, like a locked-away router. Note that the router would also need to block tunneling through SSH, and other creative ways of connecting through other machines.



    The protection of the router's configuration and physical access would also include protection of the external network outlet as to not allow you to tamper with the blocking by unplugging the router and bypassing it with an ethernet cable.



    The key for accessing the router, and the router's admin password, would not be in your possession.



    There might also be something one could do with virtual machines or containers (or possibly even just a chroot), so that the external connection would be protected by "another system" (the host machine) which you have no easy access to, while you work on the virtual machine or in the container.



    I believe this is the limit to the technical solutions to your issue. As such, they are not limited to Unix systems. The next step would be to work with personal behaviour in other ways, such as through changing the way you work (always be visible by someone who cares), or seek outside help from a behaviour therapist or similar.






    share|improve this answer



























      up vote
      0
      down vote



      accepted










      To stop yourself, as root, to undo the blocking of a website, you will have to give up control of the blocking and unblocking process and involve another human being.



      The radical solution would be to just give up root privileges on the machine to some other trusted human, and at least to severely restrict the available operations that you can do through sudo. On a Unix system, virtually all software can be installed in one's home directory, if one's willing to put one's mind to it.



      The other solution is to move the actual blocking process from the machine entirely, and let that be handled by a separate piece of equipment, like a locked-away router. Note that the router would also need to block tunneling through SSH, and other creative ways of connecting through other machines.



      The protection of the router's configuration and physical access would also include protection of the external network outlet as to not allow you to tamper with the blocking by unplugging the router and bypassing it with an ethernet cable.



      The key for accessing the router, and the router's admin password, would not be in your possession.



      There might also be something one could do with virtual machines or containers (or possibly even just a chroot), so that the external connection would be protected by "another system" (the host machine) which you have no easy access to, while you work on the virtual machine or in the container.



      I believe this is the limit to the technical solutions to your issue. As such, they are not limited to Unix systems. The next step would be to work with personal behaviour in other ways, such as through changing the way you work (always be visible by someone who cares), or seek outside help from a behaviour therapist or similar.






      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        To stop yourself, as root, to undo the blocking of a website, you will have to give up control of the blocking and unblocking process and involve another human being.



        The radical solution would be to just give up root privileges on the machine to some other trusted human, and at least to severely restrict the available operations that you can do through sudo. On a Unix system, virtually all software can be installed in one's home directory, if one's willing to put one's mind to it.



        The other solution is to move the actual blocking process from the machine entirely, and let that be handled by a separate piece of equipment, like a locked-away router. Note that the router would also need to block tunneling through SSH, and other creative ways of connecting through other machines.



        The protection of the router's configuration and physical access would also include protection of the external network outlet as to not allow you to tamper with the blocking by unplugging the router and bypassing it with an ethernet cable.



        The key for accessing the router, and the router's admin password, would not be in your possession.



        There might also be something one could do with virtual machines or containers (or possibly even just a chroot), so that the external connection would be protected by "another system" (the host machine) which you have no easy access to, while you work on the virtual machine or in the container.



        I believe this is the limit to the technical solutions to your issue. As such, they are not limited to Unix systems. The next step would be to work with personal behaviour in other ways, such as through changing the way you work (always be visible by someone who cares), or seek outside help from a behaviour therapist or similar.






        share|improve this answer















        To stop yourself, as root, to undo the blocking of a website, you will have to give up control of the blocking and unblocking process and involve another human being.



        The radical solution would be to just give up root privileges on the machine to some other trusted human, and at least to severely restrict the available operations that you can do through sudo. On a Unix system, virtually all software can be installed in one's home directory, if one's willing to put one's mind to it.



        The other solution is to move the actual blocking process from the machine entirely, and let that be handled by a separate piece of equipment, like a locked-away router. Note that the router would also need to block tunneling through SSH, and other creative ways of connecting through other machines.



        The protection of the router's configuration and physical access would also include protection of the external network outlet as to not allow you to tamper with the blocking by unplugging the router and bypassing it with an ethernet cable.



        The key for accessing the router, and the router's admin password, would not be in your possession.



        There might also be something one could do with virtual machines or containers (or possibly even just a chroot), so that the external connection would be protected by "another system" (the host machine) which you have no easy access to, while you work on the virtual machine or in the container.



        I believe this is the limit to the technical solutions to your issue. As such, they are not limited to Unix systems. The next step would be to work with personal behaviour in other ways, such as through changing the way you work (always be visible by someone who cares), or seek outside help from a behaviour therapist or similar.







        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited Jun 6 at 10:07


























        answered Jun 6 at 9:46









        Kusalananda

        101k13199313




        101k13199313






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f448129%2frun-process-before-opening-file%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay