5
votes
1answer
51 views

Getting the process-id out of command launched with “su -c”

I am running a java program inside a shell and writing the process-id to a text file. So when I do this: nohup java app.Main > /dev/null 2>&1 & echo $! > /var/run/app.pid It works. ...
5
votes
1answer
461 views

What does su - `whoami` command do?

I am running a script in my project and I see this command su - `whoami` I am having a few basic questions: What does this command do ? What is the significance of `` quotes outside the whoami ...
0
votes
1answer
109 views

How do you keep the password hidden when invoked during the su command?

This is the first time it has happened to me where I am using the su command and it actually displays the password on the terminal and doesn't stay hidden. Here is my code snippet: sshpass -p ...
2
votes
1answer
122 views

How to create an executable bash script for these commands?

I wish to create an executable bash script that will run the following commands as root, that is, using sudo su iptables-save | awk '/^[*]/ { print $1 } /^:[A-Z]+ [^-]/ { print ...
3
votes
2answers
237 views

Passing arguments to su-provided shell

man su says: You can use the -- argument to separate su options from the arguments supplied to the shell. man bash says: -- A -- signals the end of options and disables further option ...
8
votes
2answers
148 views

How do I elevate privileges in the middle of pipeline?

My guess was as follows: echo "Generating some text" | su - -c cat >/output/file But su says: su: must be run from a terminal What would you do?
2
votes
3answers
3k views

How to login as root from Bash and do stuff

This is my simple bash: cat test.sh #!/bin/bash echo "hello" su - root -c /path/to/script.sh <<EOF password EOF whoami echo "good bye" But I get this error: ...
1
vote
2answers
164 views

Script to su -c into a screen is not working as intended

I'm working on a script that will allow me to load up a screen from a user via sudo and su -c. However, when I use it, it will just show the shell of the user: sudo su -c "script /dev/null; screen -r ...
1
vote
1answer
97 views

ssh key authentication not working from network/if-up.d/ scripts

I have two nearly identical scripts in network/if-up that need to access SSH keys. Permissions on SSH private keys are 600, so how can my scripts access these keys? I would prefer to keep the SSH ...
0
votes
3answers
86 views

Is there a way to switch to “su -” after switching users through “su”?

Maybe the title wasn't worded quite clear. But basically what I want to be able to do is to switch to having used "su -" instead of the traditional hyphenless "su" after already using "su" to switch ...
11
votes
4answers
9k views

Why doesn't “sudo su” in a shell script run the rest of the script as root?

A sample script can be as below: #!/bin/bash sudo su ls /root When using ./test.sh as the normal user, instead run ls as super user and exit, it switches to root; and when I logout, it executes ls ...
1
vote
3answers
2k views

Shell script to become root

How can we write a shell script to become root? That is I donot want to input the password at prompt it should be within the script itself. I was trying to make but failed to do so.Is it possible, if ...
2
votes
2answers
365 views

Am I using bash after this ordeal?

On Mountain Lion, host Coguaro, I login as user coconutpowder using bash: Coguaro:~ coconutpowder$ echo $0 -bash I need to run a command with elevated privileges so I try to su switch to root but ...
2
votes
3answers
2k views

Switching to superuser while shell script is running

I have a shell script that contains the following lines: CURRENT_USER=${USER} echo $CURRENT_USER su echo switch to `who am i` Once the 2nd line is executed, the shell prompts me to enter the root ...
3
votes
2answers
3k views

su vs su - (on Debian): why is PATH the same?

I know what should be the difference between su and su -, but in my system (debian testing) for example PATH is the same: [root]# su [root]# echo $PATH ...
4
votes
3answers
950 views

`$XAUTHORITY` appears from 'nowhere' on su+tmux

When I switched from su+bash to su+tmux+zsh I noticed that I get $XAUTHORITY variable defined as /root/.xauthXXXXXX where XXXXXX are 6 random alphanumeric characters. With previous configuration X ...