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

Clash 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"
How can I write a script named
my_ulimitso that it can be called
by the similar syntax asulimitof bash but also is a
chain-loading utility, just like the syntax of
http://jdebp.eu./Softwares/nosh/guide/ulimit.htmlmy_ulimit [-H] [-S] [limits...] next-progMore generally, is it possible not just for bash
ulimitbut also
for other command which work in a similar way asulimit, 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.
bash scripting ulimit
add a comment |Â
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"
How can I write a script named
my_ulimitso that it can be called
by the similar syntax asulimitof bash but also is a
chain-loading utility, just like the syntax of
http://jdebp.eu./Softwares/nosh/guide/ulimit.htmlmy_ulimit [-H] [-S] [limits...] next-progMore generally, is it possible not just for bash
ulimitbut also
for other command which work in a similar way asulimit, 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.
bash scripting ulimit
add a comment |Â
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"
How can I write a script named
my_ulimitso that it can be called
by the similar syntax asulimitof bash but also is a
chain-loading utility, just like the syntax of
http://jdebp.eu./Softwares/nosh/guide/ulimit.htmlmy_ulimit [-H] [-S] [limits...] next-progMore generally, is it possible not just for bash
ulimitbut also
for other command which work in a similar way asulimit, 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.
bash scripting ulimit
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"
How can I write a script named
my_ulimitso that it can be called
by the similar syntax asulimitof bash but also is a
chain-loading utility, just like the syntax of
http://jdebp.eu./Softwares/nosh/guide/ulimit.htmlmy_ulimit [-H] [-S] [limits...] next-progMore generally, is it possible not just for bash
ulimitbut also
for other command which work in a similar way asulimit, 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.
bash scripting ulimit
edited May 30 at 13:00
asked May 30 at 12:21
Tim
22.6k61222401
22.6k61222401
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password