how to write a script that will run commands after su, without using -c
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I'm trying to automate a standard activity on a system I do not have root access on. The administrator of the systems have given me authority to run sudo su - 'user'
command, and only that command. I can not add a -c
argument or sudo
will fail.
My script will have to start with my permissions, and midway through change to running with the user's permissions. I'm trying to figure out if there is a way to make a script do this for me in a single command?
Before anyone asks, trying to get my visudo
permissions extended is quite difficult. While I could probably su
using the password I do not know the password of the user, don't want to change it, and really should hardcode it in my script anyways, so regular su
without sudo
isn't really an option. It seems like there has to be some way to work with the command I'm authorized to use?
sudo su
add a comment |Â
up vote
5
down vote
favorite
I'm trying to automate a standard activity on a system I do not have root access on. The administrator of the systems have given me authority to run sudo su - 'user'
command, and only that command. I can not add a -c
argument or sudo
will fail.
My script will have to start with my permissions, and midway through change to running with the user's permissions. I'm trying to figure out if there is a way to make a script do this for me in a single command?
Before anyone asks, trying to get my visudo
permissions extended is quite difficult. While I could probably su
using the password I do not know the password of the user, don't want to change it, and really should hardcode it in my script anyways, so regular su
without sudo
isn't really an option. It seems like there has to be some way to work with the command I'm authorized to use?
sudo su
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I'm trying to automate a standard activity on a system I do not have root access on. The administrator of the systems have given me authority to run sudo su - 'user'
command, and only that command. I can not add a -c
argument or sudo
will fail.
My script will have to start with my permissions, and midway through change to running with the user's permissions. I'm trying to figure out if there is a way to make a script do this for me in a single command?
Before anyone asks, trying to get my visudo
permissions extended is quite difficult. While I could probably su
using the password I do not know the password of the user, don't want to change it, and really should hardcode it in my script anyways, so regular su
without sudo
isn't really an option. It seems like there has to be some way to work with the command I'm authorized to use?
sudo su
I'm trying to automate a standard activity on a system I do not have root access on. The administrator of the systems have given me authority to run sudo su - 'user'
command, and only that command. I can not add a -c
argument or sudo
will fail.
My script will have to start with my permissions, and midway through change to running with the user's permissions. I'm trying to figure out if there is a way to make a script do this for me in a single command?
Before anyone asks, trying to get my visudo
permissions extended is quite difficult. While I could probably su
using the password I do not know the password of the user, don't want to change it, and really should hardcode it in my script anyways, so regular su
without sudo
isn't really an option. It seems like there has to be some way to work with the command I'm authorized to use?
sudo su
sudo su
edited Sep 12 '14 at 21:14
HalosGhost
3,62592035
3,62592035
asked Sep 12 '14 at 19:54
dsollen
381315
381315
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
6
down vote
accepted
Put the commands that you want to run as the other user into a separate file,user2commands
, and then do
sudo su - user < user2commands
If you donâÂÂt want to have a separate file, consider:
sudo su - user << EOF
commands to be run as the other user
ï¸Â
EOF
2
this has weird behavior if the commands need to interact with standard input. For example, if you usecat
this won't work (e.g., tryecho cat | sudo su - user
)
â pqnet
Sep 12 '14 at 23:11
How to escape the<
character when we are putting the entire sudo command within an argument, inside an xml file. I am using phing, so I want to do something like this -<exec command="sudo su auto_deploy << EOF echo 'Logged in user' whoami EOF" dir="$dir.scratchpad" />
. The<<
before the EOF is throwing XML validation error.
â Sandeepan Nath
Aug 19 '16 at 11:31
add a comment |Â
up vote
1
down vote
From my personal experience this never worked. Figuring out a workaround creates more work and it may not work properly if you don't have root permissions.
add a comment |Â
up vote
0
down vote
I also have the same question. using
New contributor
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
Put the commands that you want to run as the other user into a separate file,user2commands
, and then do
sudo su - user < user2commands
If you donâÂÂt want to have a separate file, consider:
sudo su - user << EOF
commands to be run as the other user
ï¸Â
EOF
2
this has weird behavior if the commands need to interact with standard input. For example, if you usecat
this won't work (e.g., tryecho cat | sudo su - user
)
â pqnet
Sep 12 '14 at 23:11
How to escape the<
character when we are putting the entire sudo command within an argument, inside an xml file. I am using phing, so I want to do something like this -<exec command="sudo su auto_deploy << EOF echo 'Logged in user' whoami EOF" dir="$dir.scratchpad" />
. The<<
before the EOF is throwing XML validation error.
â Sandeepan Nath
Aug 19 '16 at 11:31
add a comment |Â
up vote
6
down vote
accepted
Put the commands that you want to run as the other user into a separate file,user2commands
, and then do
sudo su - user < user2commands
If you donâÂÂt want to have a separate file, consider:
sudo su - user << EOF
commands to be run as the other user
ï¸Â
EOF
2
this has weird behavior if the commands need to interact with standard input. For example, if you usecat
this won't work (e.g., tryecho cat | sudo su - user
)
â pqnet
Sep 12 '14 at 23:11
How to escape the<
character when we are putting the entire sudo command within an argument, inside an xml file. I am using phing, so I want to do something like this -<exec command="sudo su auto_deploy << EOF echo 'Logged in user' whoami EOF" dir="$dir.scratchpad" />
. The<<
before the EOF is throwing XML validation error.
â Sandeepan Nath
Aug 19 '16 at 11:31
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
Put the commands that you want to run as the other user into a separate file,user2commands
, and then do
sudo su - user < user2commands
If you donâÂÂt want to have a separate file, consider:
sudo su - user << EOF
commands to be run as the other user
ï¸Â
EOF
Put the commands that you want to run as the other user into a separate file,user2commands
, and then do
sudo su - user < user2commands
If you donâÂÂt want to have a separate file, consider:
sudo su - user << EOF
commands to be run as the other user
ï¸Â
EOF
answered Sep 12 '14 at 22:05
G-Man
12.1k92860
12.1k92860
2
this has weird behavior if the commands need to interact with standard input. For example, if you usecat
this won't work (e.g., tryecho cat | sudo su - user
)
â pqnet
Sep 12 '14 at 23:11
How to escape the<
character when we are putting the entire sudo command within an argument, inside an xml file. I am using phing, so I want to do something like this -<exec command="sudo su auto_deploy << EOF echo 'Logged in user' whoami EOF" dir="$dir.scratchpad" />
. The<<
before the EOF is throwing XML validation error.
â Sandeepan Nath
Aug 19 '16 at 11:31
add a comment |Â
2
this has weird behavior if the commands need to interact with standard input. For example, if you usecat
this won't work (e.g., tryecho cat | sudo su - user
)
â pqnet
Sep 12 '14 at 23:11
How to escape the<
character when we are putting the entire sudo command within an argument, inside an xml file. I am using phing, so I want to do something like this -<exec command="sudo su auto_deploy << EOF echo 'Logged in user' whoami EOF" dir="$dir.scratchpad" />
. The<<
before the EOF is throwing XML validation error.
â Sandeepan Nath
Aug 19 '16 at 11:31
2
2
this has weird behavior if the commands need to interact with standard input. For example, if you use
cat
this won't work (e.g., try echo cat | sudo su - user
)â pqnet
Sep 12 '14 at 23:11
this has weird behavior if the commands need to interact with standard input. For example, if you use
cat
this won't work (e.g., try echo cat | sudo su - user
)â pqnet
Sep 12 '14 at 23:11
How to escape the
<
character when we are putting the entire sudo command within an argument, inside an xml file. I am using phing, so I want to do something like this - <exec command="sudo su auto_deploy << EOF echo 'Logged in user' whoami EOF" dir="$dir.scratchpad" />
. The <<
before the EOF is throwing XML validation error.â Sandeepan Nath
Aug 19 '16 at 11:31
How to escape the
<
character when we are putting the entire sudo command within an argument, inside an xml file. I am using phing, so I want to do something like this - <exec command="sudo su auto_deploy << EOF echo 'Logged in user' whoami EOF" dir="$dir.scratchpad" />
. The <<
before the EOF is throwing XML validation error.â Sandeepan Nath
Aug 19 '16 at 11:31
add a comment |Â
up vote
1
down vote
From my personal experience this never worked. Figuring out a workaround creates more work and it may not work properly if you don't have root permissions.
add a comment |Â
up vote
1
down vote
From my personal experience this never worked. Figuring out a workaround creates more work and it may not work properly if you don't have root permissions.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
From my personal experience this never worked. Figuring out a workaround creates more work and it may not work properly if you don't have root permissions.
From my personal experience this never worked. Figuring out a workaround creates more work and it may not work properly if you don't have root permissions.
answered Sep 12 '14 at 21:07
unixmiah
326110
326110
add a comment |Â
add a comment |Â
up vote
0
down vote
I also have the same question. using
New contributor
add a comment |Â
up vote
0
down vote
I also have the same question. using
New contributor
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I also have the same question. using
New contributor
I also have the same question. using
New contributor
New contributor
answered 2 mins ago
arpan gupta
1
1
New contributor
New contributor
add a comment |Â
add a comment |Â
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%2f155326%2fhow-to-write-a-script-that-will-run-commands-after-su-without-using-c%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