Operating System - Linux
1827883 Members
1288 Online
109969 Solutions
New Discussion

Create .elm directory in user home directory in mass

 
SOLVED
Go to solution
Daniel Dumont_1
Advisor

Create .elm directory in user home directory in mass

I am looking for a way to create the .elm directory in users home directory in mass.

Say there are 100 user directory's.
Say 30 already have the .elm directory.
I want to create for all the others.

Below is what user gets when first running elm and has to answer "y" to the 2 prompts.
I do not want users to see this.

Any help would be appreciated.

# elm

Notice:
This version of ELM requires the use of a .elm directory in your home
directory to store your elmrc and alias files. Shall I create the
directory .elm for you and set it up (y/n/q)? Yes.
Great! I'll do it now.

Notice:
ELM requires the use of a folders directory to store your mail folders in.
Shall I create the directory /home/agallajo/Mail for you (y/n/q) Yes.
Great! I'll do it now.
Will assign points for solutions!!
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: Create .elm directory in user home directory in mass

Hi:

Normally 'elm' must be run interactively to setup its directories. However, you can simple do:

# mkdir .elm
# mkdir Mail

...within each user's home directory.

Regards!

...JRF...
Daniel Dumont_1
Advisor

Re: Create .elm directory in user home directory in mass

Thanks JRF.

Any way to do make those 2 directory's in all users who do not have them?
I would like to be sure everyone has them.
Will assign points for solutions!!
James R. Ferguson
Acclaimed Contributor
Solution

Re: Create .elm directory in user home directory in mass

Hi (again) Daniel:

This will automate the creation for you:

# cat ./mkelms
#!/usr/bin/sh
OLDIFS=${IFS}
IFS=":"
while read OWNER X UID X X DIR X
do
[ ${UID} -lt 100 ] && continue
[ -r ${DIR}/.elm ] || { mkdir ${DIR}/.elm; chown ${OWNER} ${DIR}/.elm; }
[ -r ${DIR}/Mail ] || { mkdir ${DIR}/Mail; chown ${OWNER} ${DIR}/Mail; }
done < /etc/passwd
IFS=${OLDIFS}
exit 0

...This uses '/etc/passwd' to deduce the correct HOME directory location of each user whose UID > 100 (the standard fence for "application" accounts). For every /home directory without an '.elm' or 'Mail' directory, one is created and the ownership set to that of the owner. It is assumed that 'root' will run this script.

Regards!

...JRF...
Daniel Dumont_1
Advisor

Re: Create .elm directory in user home directory in mass

Worked perfectly.

Thanks James!
Points awarded.

How would I ensure that the elm/Mail directories are created for every new user from now on?
Will assign points for solutions!!
James R. Ferguson
Acclaimed Contributor

Re: Create .elm directory in user home directory in mass

Hi (again) Daniel:

> How would I ensure that the elm/Mail directories are created for every new user from now on?

If you, as the administrator, use 'useradd' to setup the account, you could craft a simple script that runs the 'useradd' followd by the necessary 'mkdir's.

See the manpages for 'useradd'. By example:

# ./mkuser
#!/usr/bin/sh
UID=$1
NAME=$2
GECOS=$3
useradd -u ${UID} -g 20 -s /usr/bin/sh -c "${GECOS}" -m ${NAME}
if [ $? -eq 0 ]; then
mkdir /home/${NAME}/.elm
chown ${NAME}:users /home/${NAME}/.elm
mkdir /home/${NAME}/Mail
chown ${NAME}:users /home/${NAME}/Mail
fi
exit 0

...run as:

# ./mkuser 2008 somebody "I am somebody"

Regards!

...JRF...