LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   scripts (https://www.linuxquestions.org/questions/programming-9/scripts-269523/)

demetriusp 12-23-2004 06:53 AM

scripts
 
Hello

I was using a script to create user and home dir under Redhat

I have resently change to suse9.2 and my scripts give me an error

here is a sample

At the bottom I included the error message
thanks

##
# Environment Variables Definitions
##

PKG_HME=`pwd` # Sets Package home dir

echo -e

echo -n "Enter Username ==> ";read LOGIN
if [[ -x /home/${LOGIN} ]]; then
echo -e "\nThis User Already Exists"
echo -e "\nPress Any Key";read toto
exit 0
else

echo -n "Enter User Fullname (no spaces) ==> ";read COMMEN
useradd -d /home/$LOGIN -s /bin/bash -c $COMMEN $LOGIN

echo -e "\nCreating Admin ssh Directories \n"
mkdir /home/$LOGIN/.ssh 1>&2

echo -e "\nMove ssh keys to proper directories \n"
if [[ -f ${PKG_HME}/SSH_Keys/${LOGIN}.pub ]]; then
cp $PKG_HME/SSH_Keys/$LOGIN.pub /home/$LOGIN/.ssh/authorized_keys 1>&2
echo -e "\nChanging SSH key permissions "
chown $LOGIN /home/$LOGIN/.ssh/authorized_keys
chmod 755 /home/$LOGIN/.ssh/authorized_keys
else
echo -e "\nUser has no SSH key, User won't be able to login"
fi

# Files created but owned by root

USERDIR="/home/$LOGIN"
UMASK_C=`umask`

echo -e "\nCreating files owned by root"

cd $USERDIR
umask 077

if [[ -x ${USERDIR}/.ssh ]]; then
/bin/touch .shosts
fi

if [[ ! -x .cshrc ]]; then
/bin/mkdir .cshrc
/bin/touch .cshrc/toto
fi

if [[ ! -x .emacs ]]; then
/bin/mkdir .emacs
/bin/touch .emacs/toto
fi

if [[ ! -x .exrc ]]; then
/bin/mkdir .exrc
/bin/touch .exrc/toto
fi

if [[ ! -x .forward ]]; then
/bin/mkdir .forward
/bin/touch .forward/toto
"users-inst.sh" 96L, 2022C

22,29-36 Top

PKG_HME=`pwd` # Sets Package home dir

echo -e

echo -n "Enter Username ==> ";read LOGIN
if [[ -x /home/${LOGIN} ]]; then
echo -e "\nThis User Already Exists"
echo -e "\nPress Any Key";read toto
exit 0
else

echo -n "Enter User Fullname (no spaces) ==> ";read COMMEN
useradd -d /home/$LOGIN -s /bin/bash -c $COMMEN $LOGIN

echo -e "\nCreating Admin ssh Directories \n"
mkdir /home/$LOGIN/.ssh 1>&2

echo -e "\nMove ssh keys to proper directories \n"
if [[ -f ${PKG_HME}/SSH_Keys/${LOGIN}.pub ]]; then
cp $PKG_HME/SSH_Keys/$LOGIN.pub /home/$LOGIN/.ssh/authorized_keys 1>&2
echo -e "\nChanging SSH key permissions "
chown $LOGIN /home/$LOGIN/.ssh/authorized_keys
chmod 755 /home/$LOGIN/.ssh/authorized_keys
else
echo -e "\nUser has no SSH key, User won't be able to login"
fi

# Files created but owned by root

USERDIR="/home/$LOGIN"
UMASK_C=`umask`

echo -e "\nCreating files owned by root"

cd $USERDIR
umask 077

if [[ -x ${USERDIR}/.ssh ]]; then
/bin/touch .shosts
fi

if [[ ! -x .cshrc ]]; then
/bin/mkdir .cshrc
/bin/touch .cshrc/toto
fi

if [[ ! -x .emacs ]]; then
/bin/mkdir .emacs
/bin/touch .emacs/toto
fi

if [[ ! -x .exrc ]]; then
/bin/mkdir .exrc
/bin/touch .exrc/toto
fi

if [[ ! -x .forward ]]; then
/bin/mkdir .forward
/bin/touch .forward/toto
fi

if [[ ! -x .login ]]; then
/bin/mkdir .login
/bin/touch .login/toto
fi

if [[ ! -x .logout ]]; then
/bin/mkdir .logout
/bin/touch .logout/toto
fi

if [[ ! -x .netrc ]]; then
/bin/touch .netrc
fi

if [[ ! -x .rhosts ]]; then
/bin/touch .rhosts
fi

umask $UMASK_C
cd $PKG_HME

fi

echo -e "\nSetting Password for " $LOGIN

/usr/bin/passwd $LOGIN

echo -e "\nPress Any Key To Continue\n"
read toto

works fine under redhat
here is the error i get with suse9.2


Enter Username ==> toto
Enter User Fullname (no spaces) ==> toto
useradd: User `toto' already exists.

Creating Admin ssh Directories

mkdir: cannot create directory `/home/toto/.ssh': No such file or directory

Move ssh keys to proper directories


User has no SSH key, User won't be able to login

Creating files owned by root
/usr/local/teco/Users/users-inst.sh: line 41: cd: /home/toto: No such file or directory

Setting Password for toto
Changing password for toto.
New password: Enter Username ==> toto

acid_kewpie 12-23-2004 07:08 AM

you can't verify if a user exists by just looking at /home.. you should be looking at /etc/passwd really.

not to deflate anything, but you do know that pam and the /etc/skel template can handle all this by default? placing the ssh keys in /etc/skel/.ssh should sort that all out without you needing any of this unweidly script.

demetriusp 12-23-2004 08:18 AM

Thanks for the fast reply

could you point me someware so I could better understand
or if you could help
Thanks


All times are GMT -5. The time now is 01:27 PM.