su

pass password to su/sudo/ssh

I'm writing a C/Shell program that will be doing su or sudo or ssh. They all want their passwords in consol input rather than stdin. Does anybody know a solution? Setting up password-less sudo is not an option. Expect could be an option, but it's not present on my stripped-down system. ...

How can I su from root to db2inst1 and invoke a SQL script, in one line?

How can I su from root to db2inst1 and invoke a SQL script all in 1 line? I am thinking about something like this: su db2inst1 | db2 CONNECT TO myDatabase USER db2inst1 USING mypw; db2 -c -i -w -td@ -f /tmp/deploy/sql/My.sql | exit; Any ideas? ...

Dont want my cshrc to execute on login

Hi, On unix I am working as say user X, and I want to login to user Y from X. Now issue is that I dont want Y's cshrc (or any other login script) to run while I login to his user name. I vaguely remember there used to be a way to do so, something like execute "su" command with some option for not running login scripts, but none of th...

Running interactive shell script in name of other user

In my shell script (bash) I want to call other shell scripts. I run my script as user_A. One of these scripts needs special handling: It has to be run as different user (user_B). Password needed here. It is interactive, but not only asks questions but runs another script in name of another user (user_C) using su. I have to enter a pass...

Executing scripts using more users

I'm writing a bash script which calls a lot of other scripts. Several scripts have to be executed as user_1 but several ones as user_2. The scripts should be called in strict sequence. I start my script as user_1 and use su many times to become user_2. These times su requires a password so I have to retype it many times. I'd like to avoi...

How to define environment variable in input command of su

This command has an empty output. su user -c "ABC=abc;echo $ABC" Any idea, how can I define a variable in the input command? ...

Running bash function in command of su

In my bash script I execute some commands as other user. I want to call a bash function in command of su I defined in my script before. my_function() { do_something } su username -c "my_function" The above script doesn't work, of course my_function is not defined inside su. I have only the idea to save the function into separate fi...

su and sudo in a shell script

There is a shell script (/bin/sh, not bash) that requires root permissions for execution. If it is ran by a normal user it should ask user a password to get root access and re-run itself. Now it uses the following code: if [ $(id -u) -ne 0 ]; then su root -- $0 $@ ; ... fi That works fine, but there are some OS like Ubuntu that has n...