LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-22-2006, 08:56 AM   #1
syedabdul
Member
 
Registered: Nov 2005
Location: india
Posts: 32

Rep: Reputation: 15
Thumbs up Where to run this script


Hi Buddies,

In my organisation the home directory is kerberoised(in the sense that only the actual user can write into his directory not even the ROOT can't write into anybody's home directory).

I want to write a script which copies some files into the user's home directory
My Plan is when the user logins i want to run the script(WHICH COPIES FILES) with his credentials but i don't know where to place the script.

I have tried placing in /etc/gdm/Presession and Post session but GDM is run with ROOt Priveleges.
Is there any place i can place the script to fulfill my Idea.

Thanks,
Abdul
 
Old 12-22-2006, 09:14 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,263

Rep: Reputation: 297Reputation: 297Reputation: 297
Hi

You are root on that server, right?

What about "/etc/profile"?
 
Old 12-22-2006, 10:41 AM   #3
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
How about using sudo to change to the user and doing the copying as him?

Groetjes,

Kees-Jan
 
Old 12-23-2006, 01:07 AM   #4
syedabdul
Member
 
Registered: Nov 2005
Location: india
Posts: 32

Original Poster
Rep: Reputation: 15
I have to execute the script at the client side bcoz.I don't have access to the server.But i'm part in the sudoers list of evry machine.As i told you earlier even the root can't write to anyone's home directory .I have to run the script under the user's credentials.

Abdul.
 
Old 12-23-2006, 01:09 AM   #5
syedabdul
Member
 
Registered: Nov 2005
Location: india
Posts: 32

Original Poster
Rep: Reputation: 15
Hi Kees,

Thanks for the tought but where in the startup should i do this

Abdul
 
Old 12-23-2006, 03:26 AM   #6
syedabdul
Member
 
Registered: Nov 2005
Location: india
Posts: 32

Original Poster
Rep: Reputation: 15
Does .profile in the user's home directory overrides the global settings in the /etc/profile?

Abdul
 
Old 12-23-2006, 03:38 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
When a person logs in, the /etc/profile script is run as well as the users personal ~/.bash_profile or ~/.bash_login or ~/.profile script. There may be an /etc/profile.local script sourced from the /etc/profile script, which would be a better place to do this.

If the system runs the login shells with the -noprofile option, none of the bash login scripts will be run.

Remember that a user may have changed his default shell, you will need to find which shells are available and read the manpages to determine whether you need to edit different login scripts as well.
Code:
$ cat /etc/shells
/bin/sh
/bin/bash
/bin/ksh
/bin/pdksh
/bin/tcsh
/bin/zsh
/usr/bin/sh
/usr/bin/bash
/usr/bin/ksh
/usr/bin/pdksh
/usr/bin/tcsh
/usr/bin/zsh
This list is from a cygwin install. The bash and sh are actually the same program. That leaves 4 others to check in this example.

Last edited by jschiwal; 12-23-2006 at 03:41 AM.
 
Old 12-23-2006, 06:13 AM   #8
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
Hi Abdul,

The point is that you don't need to do this in the startup scripts any more. You just type
Code:
sudo -u username scriptname
and the script will be executed under the users credentials

I think this is a better way than editing /etc/profile and equivalents.

Groetjes,

Kees-Jan
 
Old 12-23-2006, 11:06 AM   #9
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 23, 24, RHL 5.2
Posts: 560

Rep: Reputation: 56
Does this script have to run each time the user performs a login or is it a one time deal to get them setup? If it is a one time deal then kees-jan suggestion is the way to correct the current users. Notice that by using the -u option with sudo you execute the script as that user. After that, if you want to do this for each user when they are created then take a look at the /etc/skel directory. It contains the default files that are copied to a users directory when they are created with useradd. This is documented on the useradd man page.

If it needs to happen everytime they login for every user on the system there are several options. You'll want to keep this at the /etc/profile level. You could add the script to /etc/profile, but that will get messy in the long run. A number of distributions have a /etc/profile.d directory where scripts are stored. Inside /etc/profile is a bit of scripting to execute the shell scripts located in that directory.
Code:
for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        . $i
    fi
done
You could place your script in that directory and it would be executed for all users whenever they login.

It sounds like this is a global deal and I would stay away from individual user .bash_profile, .bash_login, .profile or whatever shell startup files they have.

Bill

Last edited by wmakowski; 12-23-2006 at 11:08 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run a shell script in the perl script sharad Linux - General 1 05-24-2006 04:23 AM
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 03:53 AM
Shell script to run pl/sql script. colly Linux - General 1 09-09-2004 07:49 AM
Script to run script in multiple directories... seabass55 Linux - General 5 07-06-2004 01:44 AM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 10:34 AM


All times are GMT -5. The time now is 11:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration