How can we write a script that generalize bash's ulimit to be a chain-loading utility?

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











up vote
0
down vote

favorite












In How can I change my command to run without superuser privilleges but with the changed limit value?, I found that I can run sleep 100 with changed core file size limit as



sudo sh -c "ulimit -c 1024 && sleep 100"


or better yet with lowered privilleges:



sudo sh -c "ulimit -c 1024 && sudo -u nobody sleep 100"



  1. How can I write a script named my_ulimit so that it can be called
    by the similar syntax as ulimit of bash but also is a
    chain-loading utility, just like the syntax of
    http://jdebp.eu./Softwares/nosh/guide/ulimit.html



    my_ulimit [-H] [-S] [limits...] next-prog



  2. More generally, is it possible not just for bash ulimit but also
    for other command which work in a similar way as ulimit, like:



    mywrapper command-name [command-arg] next-prog


The difficult part for me is how to specify and handle the arguments to ulimit, the chain-loaded program name and its arguments, with respect to parameter expansion and word splitting.
Here is my experiment, appreciate any improvement on it



$ cat mywrapper.sh 
#/bin/bash

setup_command="$1"
chained_command="$2"
eval "$setup_command" && sudo -u nobody bash -c "$chained_command"

$ sudo ./mywrapper.sh "ulimit -c 1024" "sleep 100"
^Quit


Thanks.







share|improve this question

























    up vote
    0
    down vote

    favorite












    In How can I change my command to run without superuser privilleges but with the changed limit value?, I found that I can run sleep 100 with changed core file size limit as



    sudo sh -c "ulimit -c 1024 && sleep 100"


    or better yet with lowered privilleges:



    sudo sh -c "ulimit -c 1024 && sudo -u nobody sleep 100"



    1. How can I write a script named my_ulimit so that it can be called
      by the similar syntax as ulimit of bash but also is a
      chain-loading utility, just like the syntax of
      http://jdebp.eu./Softwares/nosh/guide/ulimit.html



      my_ulimit [-H] [-S] [limits...] next-prog



    2. More generally, is it possible not just for bash ulimit but also
      for other command which work in a similar way as ulimit, like:



      mywrapper command-name [command-arg] next-prog


    The difficult part for me is how to specify and handle the arguments to ulimit, the chain-loaded program name and its arguments, with respect to parameter expansion and word splitting.
    Here is my experiment, appreciate any improvement on it



    $ cat mywrapper.sh 
    #/bin/bash

    setup_command="$1"
    chained_command="$2"
    eval "$setup_command" && sudo -u nobody bash -c "$chained_command"

    $ sudo ./mywrapper.sh "ulimit -c 1024" "sleep 100"
    ^Quit


    Thanks.







    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      In How can I change my command to run without superuser privilleges but with the changed limit value?, I found that I can run sleep 100 with changed core file size limit as



      sudo sh -c "ulimit -c 1024 && sleep 100"


      or better yet with lowered privilleges:



      sudo sh -c "ulimit -c 1024 && sudo -u nobody sleep 100"



      1. How can I write a script named my_ulimit so that it can be called
        by the similar syntax as ulimit of bash but also is a
        chain-loading utility, just like the syntax of
        http://jdebp.eu./Softwares/nosh/guide/ulimit.html



        my_ulimit [-H] [-S] [limits...] next-prog



      2. More generally, is it possible not just for bash ulimit but also
        for other command which work in a similar way as ulimit, like:



        mywrapper command-name [command-arg] next-prog


      The difficult part for me is how to specify and handle the arguments to ulimit, the chain-loaded program name and its arguments, with respect to parameter expansion and word splitting.
      Here is my experiment, appreciate any improvement on it



      $ cat mywrapper.sh 
      #/bin/bash

      setup_command="$1"
      chained_command="$2"
      eval "$setup_command" && sudo -u nobody bash -c "$chained_command"

      $ sudo ./mywrapper.sh "ulimit -c 1024" "sleep 100"
      ^Quit


      Thanks.







      share|improve this question













      In How can I change my command to run without superuser privilleges but with the changed limit value?, I found that I can run sleep 100 with changed core file size limit as



      sudo sh -c "ulimit -c 1024 && sleep 100"


      or better yet with lowered privilleges:



      sudo sh -c "ulimit -c 1024 && sudo -u nobody sleep 100"



      1. How can I write a script named my_ulimit so that it can be called
        by the similar syntax as ulimit of bash but also is a
        chain-loading utility, just like the syntax of
        http://jdebp.eu./Softwares/nosh/guide/ulimit.html



        my_ulimit [-H] [-S] [limits...] next-prog



      2. More generally, is it possible not just for bash ulimit but also
        for other command which work in a similar way as ulimit, like:



        mywrapper command-name [command-arg] next-prog


      The difficult part for me is how to specify and handle the arguments to ulimit, the chain-loaded program name and its arguments, with respect to parameter expansion and word splitting.
      Here is my experiment, appreciate any improvement on it



      $ cat mywrapper.sh 
      #/bin/bash

      setup_command="$1"
      chained_command="$2"
      eval "$setup_command" && sudo -u nobody bash -c "$chained_command"

      $ sudo ./mywrapper.sh "ulimit -c 1024" "sleep 100"
      ^Quit


      Thanks.









      share|improve this question












      share|improve this question




      share|improve this question








      edited May 30 at 13:00
























      asked May 30 at 12:21









      Tim

      22.6k61222401




      22.6k61222401

























          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',
          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%2f446896%2fhow-can-we-write-a-script-that-generalize-bashs-ulimit-to-be-a-chain-loading-ut%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446896%2fhow-can-we-write-a-script-that-generalize-bashs-ulimit-to-be-a-chain-loading-ut%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)