- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need script for profile changes on new users
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2003 11:18 PM
07-01-2003 11:18 PM
Need script for profile changes on new users
I need to write a script that can run to make a new user's .profile.
It has to ask me the user's home dir and plant name and then copies a standard .profile into their place.
Thanks
Regards
Rudi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2003 11:34 PM
07-01-2003 11:34 PM
Re: Need script for profile changes on new users
LOGIN=$1
UID=$2
GID=$3
HOME="/home/$LOGIN"
SHELL="/usr/bin/ksh"
SKEL_DIR="/etc/skel"
echo "useradd -u $UID -g $GID -d $HOME -s $SHELL -m -k $SKEL_DIR $LOGIN"
useradd -u $UID -g $GID -d $HOME -s $SHELL
-m -k $SKEL_DIR $LOGIN
This script would accept your login name,Userid,GroupID as arguments and create
a user for you.
It would also copy the standard initialization files ( including .profile from /etc/skel directory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2003 12:14 AM
07-02-2003 12:14 AM
Re: Need script for profile changes on new users
I think you can only offer the username, because the home directory of the user is defined in /etc/passwd. So the script like this:
#!/usr/bin/sh
dest_dir=`more /etc/passwd|grep "^$1:"|cut -d : -f 6`
cp -p /etc/skel/.profile $dest_dir
unset dest_dir
If you want to supply user's home directory ,that's more easy:
#!/usr/bin/sh
cp -p /etc/skel/.profile $1
-ux
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2003 01:12 AM
07-02-2003 01:12 AM
Re: Need script for profile changes on new users
do you absolutely need to create the .profile for each new user manually?
The obvious solution would be to use /etc/profile instead of copying the same info for each profile:
------------------
# man 4 profile
profile(4)
NAME
profile - set up user's environment at login time
DESCRIPTION
If the file /etc/profile exists, it is executed by the shell for every
user who logs in. The file /etc/profile should be set up to do only
those things that are desirable for every user on the system, or to
set reasonable defaults. If a user's login (home) directory contains
a file named .profile, that file is executed (via the shell's exec
.profile) before the session begins. .profile files are useful for
setting various environment parameters, setting terminal modes, or
overriding some or all of the results of executing /etc/profile.
----------------
Hope this helps,
FiX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2003 04:29 AM
07-02-2003 04:29 AM
Re: Need script for profile changes on new users
#! /usr/bin/ksh
if [ `id|cut -c5-11` != "0(root)" ]
then
echo " Quitting - you must run this script as root"
exit 1
fi
BOLD="`tput smso`"
NORMAL="`tput rmso`"
if [ "$1" = "" ]
then
x=1
elif [ "$1" != " " ] && [ "$2" != " " ] &&
[ "$3" != " " ] && [ "$4" != " " ] ;
then
x=2
fi
case $x in
1)
echo "${BOLD}too few arguments${NORMAL}"
echo "usage: `basename $0` {first name} {last name} {uid} {site}"
;;
2)
five=$(echo $2 | cut -c 1-5)
three=$(echo $1 | cut -c 1-3)
usname=$(echo $five$three)
username=$(echo $usname | awk '{print tolower($1)}')
uidnum=$3
site=$4
if [ "$site" = "" ]
then site=MTO
fi
echo "useradd -u $uidnum -g 20 -m -d /home/$username -s /usr/bin/ksh -c \"$1 $2,$site\" $username"
useradd -u $uidnum -g 20 -m -d /home/$username -s /usr/bin/ksh -c "$1 $2,$site" $username
cp .profile.default /home/$username/.
passwd $username
;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2003 05:56 AM
07-02-2003 05:56 AM
Re: Need script for profile changes on new users
If so you could create a /etc/whatever directory and in it you could create any type of profile and environment files you wanted for those users. When adding their logins just specify the /etc/whatever instead of /etc/skel, i.e.
useradd -u 123 -g users -d /home/being -s /bin/ksh -m -k /etc/whatever being
If you already have the users and want to make a bulk change, get a list of the user IDs into a file;
ll /home |awk '{print $9}' > /tmp/filname
you can edit /tmp/filename to make any last minute changes, then
for i in `cat /tmp/filename`
do
if [ -f /home/$i/.profile ]; then
cp /etc/whatever /home/$i/.profile
chown $i /home/$i/.profile
ll /home/$i/.profile # for your verification
done
later