Link to home
Start Free TrialLog in
Avatar of 1Tsupp
1Tsupp

asked on

login script for every user does not work

I want files to be copied for every user when they log in to RHEL 5 workstation.
I modified /etc/gdm/PostLogin/Default to execute a script.
This script works if run manually in the terminal by a user account after logging in.
However although it appears to be run when they log in, it does not copy the files and I cannot see any reason why. The echo statements were added for debugging and /var/log/login.log shows it is executed when a user logs in except no files are copied to the home directory.
What am I missing here and how can I debug why files are not being copied?
localroot="root"
if [ $USER != $localroot ]
then
 date
 echo "   ---Not root" >>/dev/null
 echo "   ---`date` Not root" >>/var/log/login.log
 if [ ! -d /home/$USER/.mplayer ]
  then
   echo "   ---setting up mplayer PostLogin to /home/$USER" >>/var/log/login.log
   `/bin/cp -Rd /etc/skel/.mplayer /home/$USER/`
   `/bin/chown -R $USER /home/$USER/.mplayer`
  fi
 if [ ! -d /home/$USER/.mozilla ]
  then
   echo "   ---setting up mozilla PostLogin to /home/$USER" >>/var/log/login.log
   `/bin/cp -Rd /etc/skel/.mozilla /home/$USER/`
   `/bin/chown -R $USER /home/$USER/.mozilla`
  fi
else
 echo "   --- ROOT user" >>/dev/null
fi
exit 0

Open in new window

SOLUTION
Avatar of svelarsen
svelarsen
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1Tsupp
1Tsupp

ASKER

I did but it still does not work.
What's bizarre is that the script works with or without `` when executed after a user logs in,
/var/log/login.log shows:
---Tue Jul 8 10:33:47 BST 2008 Not root
---setting up mplayer PostLogin to /home/tempx
---setting up mozilla PostLogin to /home/tempx

However the files are not copied. the /etc/skel files have chmod 755 permissions, any way to debug why it's not doing it?
Are you sure that the files are not copied?
They start with a dot and are hidden by default.
You har to do "ls -a" to see them.
Avatar of 1Tsupp

ASKER

yes obviously I have checked for hidden files with the command ls -a

It appears the echo is executed but the cp command in the script is not being executed during the login & I would like to see the reason why. After logging in as a user & via terminal  manually executing the script works flawlessly.
Any ideas?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1Tsupp

ASKER

using echo $? the results are:
Tue Jul 8 14:41:14 BST 2008
---Tue Jul 8 14:41:14 BST 2008 Not root
---setting up mplayer PostLogin to /home/temp98
1
---setting up mozilla PostLogin to /home/temp98
1
So it looks as if cp thinks it has successfully executed it but it does not:
ls -a
. .cshrc .gconf .gnome2_private .mailrc .profile Desktop .dmrc .gconfd .gstreamer-0.10 .metacity .redhat .ICEauthority .eggcups .gnome .gtkrc-1.2-gnome2 .nautilus .solregis
.Trash .esd_auth .gnome2 .login .nt .xsession-errors
both .mozilla & .mplayers folders are missing.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or even

`/bin/cp -Rd /etc/skel/.mozilla /home/$USER/ >> /var/log/login.log`
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1Tsupp

ASKER

both ways of trying to get cp output fails.
without a doubt the script is being executed:

Tue Jul 8 15:09:01 BST 2008
---Tue Jul 8 15:09:01 BST 2008 Not root
---setting up mplayer PostLogin to /home/temp98
1
---setting up mozilla PostLogin to /home/temp98
1

but cp does not give any output even with with vf options enabled.
as a suggestion try to put your script in /etc/profile.d/

and try to login via SSH sometiimes errors shows on the console when you login..
Avatar of 1Tsupp

ASKER

I tried ssh login - no errors
I've also tried tar but again without success.

This is a mystery...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hmmm.. there something wrong.. okie..

go to /tmp/
do this:

mkdir /tmp/.test
echo "AAAAA" > /tmp/.test/a.txt

cd /etc/profile.d/
echo "cp -R /tmp/.test /home/$USER/" > copyt.sh
chmod 755 /etc/profile.d/copyt.sh

*just to be sure verify if every file and directory is there..
ls -l /etc/profile.d/copyt.sh
ls -l /tmp/.test/a.txt

open a new SSH connection or just if your are already logged in issue a su - [USER]

* then do a ls -la /home/[USER]

tell me the result

Avatar of 1Tsupp

ASKER

got a result:

/bin/cp: cannot create directory `/home/temp98/.mozilla': Permission denied

I think the login script is run as root, the user home autofs mounted from the network & permissions are restricted to user only. I think perhaps I need to run the cp command as the user so i'll try this.
Avatar of 1Tsupp

ASKER

solved it!

The 2>&1 output helped to debug it.
 
the command su $USER -c "cp ..." in the script fixed it.

Thank you all for your help.

Is sharing points or solution allowed or do I have to one user?
If the moderator is watching please share the points equally between brutuz & svelarsen.
you have to remove the backticks `from all /bin/cp and /bin/chmod lines
Lunchy, beside your complains about posts, the given anser that should solve the problem is not wrong but:

 > the command su $USER -c "cp ..."
is a useless command as it is exactly the same as:
   cp ...
(unless $USER was set to another user than the login user, which would be a very, very, very bad idea)
hence my last comment results in exactly that:
   cp ...
strange grading again, as it can't work with the backticks this way ...
Anyway, leave it as is