LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-23-2004, 06:53 AM   #1
demetriusp
LQ Newbie
 
Registered: Dec 2004
Posts: 2

Rep: Reputation: 0
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

Last edited by demetriusp; 12-23-2004 at 06:57 AM.
 
Old 12-23-2004, 07:08 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
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.
 
Old 12-23-2004, 08:18 AM   #3
demetriusp
LQ Newbie
 
Registered: Dec 2004
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the fast reply

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


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
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 12:10 PM
Need help running scripts from scripts sdouble Linux - Newbie 3 05-31-2004 12:56 PM
What scripts would you like to see? kittani Linux - Software 1 05-20-2004 03:26 AM
Scripts? zombie killa Linux - Software 5 05-29-2003 05:19 PM
scripts mdjames0 Linux - Newbie 4 08-02-2002 09:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:30 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