Kudithipudi.Org

May 21, 2009

HOW TO : Pass environment variables when using sudo

Filed under: Databases,HOWTO,Linux,Technology — Vinay @ 12:27 am

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 Comments »

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

    Pingback by Keeping Green » Kudithipudi.Org » Blog Archive » HOW TO : Pass environment … — May 21, 2009 @ 3:17 am

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

    Thanks

    Comment by environmental information — June 28, 2009 @ 9:40 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress