SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Remote job running as root

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Remote job running as root
Author Message
seanc217



Joined: 23 May 2007
Posts: 272

Post Remote job running as root Reply with quote
I have a remote agent setup and it connects fine.
The remote job I have is a simple shell script as such

echo $HOME /home/srv_etl/testfile.txt

When I setup the job I told the scheduler to login as srv_etl

When I run this job, I get in the text file "/root"

I was expecting it to be "/home/srv_etl"

Does the job run in the context of how the agent runs?

What's the recommended way to get it to run as the user I specified in the job definition?

Thanks
Wed Dec 05, 2007 4:18 pm View user's profile Send private message
seanc217



Joined: 23 May 2007
Posts: 272

Post Reply with quote
OK I did an whoami > /home/srv_etl/TESTFILE.txt and got the expected user which is srv_etl.

Now the question is how do I get my $HOME variable to set properly when the scheduler logs in?

Thanks.
Wed Dec 05, 2007 4:35 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
The process is run in the context of the specified user. But... the environment is not set the same way as you would expect for an interactive logon, because this is just a user switch, not a login. If the environment setup is required, the first thing your job script needs to do is to run the profile for the specified account.
Wed Dec 05, 2007 8:53 pm View user's profile Send private message
seanc217



Joined: 23 May 2007
Posts: 272

Post Reply with quote
Is there a way to set the HOME envirionment variable to point to the users home instead of root's home?

I want to do things dynamically so I don't want to hard code the HOME envirionment variable.

Thanks.
Thu Dec 06, 2007 11:32 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
The best way is to make the job script to run the .profile script, which will set the complete environment including HOME and other things.
Thu Dec 06, 2007 12:01 pm View user's profile Send private message
seanc217



Joined: 23 May 2007
Posts: 272

Post Reply with quote
When I login my default shell is bash.

I tried to source my .bash_profile but this did not set the HOME environment variable.

Here's my .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME



I thought that users home is set in /etc/passwd

So when you login it reads this file and sets your HOME is this correct?

What am I missing here?

Thanks for all the help!
Thu Dec 06, 2007 12:14 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
No it doesn't load the profile. Technically it is a user-switch, not an interactive login. That's why I am suggesting to load .profile fro ma job, or in your case - .bash_profile. If you are going to use multiple user accounts for job running, you should do it in every job script. If you are going to use just one profile you can modify runas.pl in the agent directory and make it always call .bash profile before running the job command line or even better run the agent using that user's account and add profile loading into agent.sh startup script. Hope this helps.
Thu Dec 06, 2007 12:30 pm View user's profile Send private message
seanc217



Joined: 23 May 2007
Posts: 272

Post Reply with quote
OK so I executed .bash_profile in my script, but HOME still does not get set properly.

Do I have to hard code this?

I guess if I do I can export HOME=`pwd` as long as I start in the home directory all the time.

Is there a better way to do this?

Thanks again for the help!
Thu Dec 06, 2007 12:49 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
After taking a second look at your bash_profile, I figured out that HOME is not defined there.
Can you add HOME definition to bash_profile?
Thu Dec 06, 2007 1:50 pm View user's profile Send private message
seanc217



Joined: 23 May 2007
Posts: 272

Post Reply with quote
I know I can add the definition for home there then it will work properly.
I was trying to make this as dynamic as possible, in case we ever change accounts and a new home is setup.

I think I have a way of doing it...

~srv_etl in this case will refer to the home directory for this user.

So, I'm going to setup a file with the following in it:

#!/bin/ksh

USERHOME=~`whoami`
echo $USERHOME
eval HOME=$USERHOME


Then source this file when I run any jobs.

Thanks For the help.

Sean
Thu Dec 06, 2007 2:47 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.