HOW TO : Pass environment variables when using sudo

Say you need to sudo as a particular user and run a command and at the same time you need to pass an environmental variable to the command, you can do it by passing the command in doublequotes.

For example, I want to start Oracle while I am logged in as another user (vinay), I can start the database using dbstart by issues

"sudo su - oracle -c "dbstart /$ORACLE_HOME"

$ORACLE_HOME is an environmental variable listed under user oracle’s environment.

Needless to say, you need to ensure that you have sudo configured to allow your userID to su to oracle.

2 Responses to “HOW TO : Pass environment variables when using sudo”

  1. [...] here to read the rest: Kudithipudi.Org » Blog Archive » HOW TO : Pass environment … Share and [...]

  2. Hi, Excellent post, some really useful environmental information here and well worth knowing about.

    Thanks

Leave a Reply