- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script running root but one command need to be run...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 06:40 AM
08-18-2008 06:40 AM
I've a script running with root to execute some root commands and in this same script some commands needs to be run under another user.
My script:
1. root command
2. root command
3. here user2 command
4. root command
5. root command
6. here user2 command
I need to run 3 and 6 with the user2 because some processes will be started and the owner of the process must be user2 !
How to do this ?
note: I don't want two scripts.
Is it possible ?
Regards
Den
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 06:46 AM
08-18-2008 06:46 AM
Re: Script running root but one command need to be run with another user
For your non-root tasks, you can do:
# su - someuser -c "some_command;another_command"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 06:48 AM
08-18-2008 06:48 AM
Re: Script running root but one command need to be run with another user
1. root command
2. root command
3. su - user2 -c "command1; command2; command3"
4. root command
5. root command
6. su - user2 -c "command4; command5; command6"
since you are root to start running this script, there should not be any problem su'ing into user2 account without a password.
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 06:51 AM
08-18-2008 06:51 AM
Re: Script running root but one command need to be run with another user
su - username -c "command to be executed"
You can refer manpages for su
Thanks
SKR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 07:45 AM
08-18-2008 07:45 AM
Re: Script running root but one command need to be run with another user
In my script I've try with:
su - oracle -c "$ORACLE_HOME/mycommand.ksh"
The problem is that $ORACLE_HOME is not defined and of course I've the error: ksh: /mycommand.ksh: not found.
How to fix this. I Need to work with ORACLE_HOME to have only one generic script ...
Regards
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 07:54 AM
08-18-2008 07:54 AM
Re: Script running root but one command need to be run with another user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 07:54 AM
08-18-2008 07:54 AM
SolutionIn addition to ORACLE_HOME and depending what the "su - oracle" command does, you may also need to setup the TNS_ADMIN, SHLIB_PATH, LD_LIBRARY_PATH variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 08:00 AM
08-18-2008 08:00 AM
Re: Script running root but one command need to be run with another user
I need to have this.
Is it possible to load the user profile with something like that (but this does not work), so just in the idea :
su - applopus -c "(. /home/applopus/.profile >/dev/null; $ORACLE_HOME/backup_restore/bkp_restore.sh -m backup_instance_online)"
(huh!)
Regards
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 08:34 AM
08-18-2008 08:34 AM
Re: Script running root but one command need to be run with another user
su - applopus -c "(. /home/applopus/.profile >/dev/null; $ORACLE_HOME/backup_restore/bkp_restore.sh -m backup_instance_online)"
Try it with single quotes (as noted previously) , and note that running the .profile in the command string isn't necessary here, as the "-" in the su causes that to happen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 09:55 AM
08-18-2008 09:55 AM
Re: Script running root but one command need to be run with another user
Thanks