This is the 2nd ssh-related issue for which I cannot seem to find a solution that I ran into, but it is more immediate so I will start with it.
We have a script (call it env, since it is setting up some env vars) that gets invoked from .bashrc when a user U1 (not really U1, but that shouldn't make any difference) logs in.
Before my change, env was setting some env variable (call it VAR) to a fixed string. Because of some changes that I have been working on, we can no longer set it to a fixed string. Instead, we need to set it to a string returned by
$(ssh -oStrictHostKeyChecking=no U2@$HOSTNAME "sudo ls -l /proc/$PID/cwd 2>/dev/null" | awk '{print $11}'|sed 's/\/dbs//')
I am forced to use ssh because
- only root can examine /proc/$PID/cwd and
- U1 cannot sudo to root but U2 can, and U1 can ssh as U2
When one logs in as U1 (e.g. by issuing sudo su -l U1) , everything works exactly as intended (including VAR getting set to a correct value), but if a user who has privileges to sudo to U1 tries to issue
sudo su - U1 <<EOF
pwd
EOF
no output is produced. I know that the problem does not lie with sudo in the above expression because when I replaced the above expression used to set VAR with
$(ssh -oStrictHostKeyChecking=no U2@$HOSTNAME "echo some_string 2>/dev/null")
the problem did not go away, but when I replaced it with
$(echo /u02/app/oracle/product/19.0.0.0/dbhome_1 2>/dev/null)
sudo su - U1 <<EOF
pwd
EOF
produced
/home/U1
which is what was expected.
Any thoughts, suggestions, pointers?
Many thanks