Help for scripting sh / Add user auto


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help for scripting sh / Add user auto
# 8  
Old 05-23-2010
I found the solution:

Code:
  1 #!/bin/sh
  2 #
  3 # Script de création auto d'utilisateur
  4
  5
  6
  7 if [ -e $1 ];
  8 then
  9
 10         while read ligne
 11                 do
 12                         prenom= $(echo $ligne | cut user.txt -d: :)
 13                         nom= $(echo $ligne | cut user.txt -d: :)
 14                         login= $(echo $prenom"."$nom)
 15                         echo $login
 16                         mdp= $(pwgen 4 1)
 17                         echo  $mdp
 18                         mdpcrypt= $(mkpasswd -S $mdp)
 19                         useradd -p $mdpcrypt  $login
 20                         echo "****************************************"
 21                         echo "    Creation des utilisateurs en cours .... "
 22                         echo "          Veuillez patienter "
 23                         echo "****************************************"
 24                         echo $login ":" $mdp >> comptes.txt
 25         done < "user.txt"
 26
 27         else
 28                 echo "Erreur : Le fichier n'existe pas"
 29 fi

Line 25 --> I replaced $1 by "user.txt"
This is the file that contains the nicknames, names and groups of my users comem this:
nickname:name:group
nickname2:name2:group2
...

---------- Post updated at 02:29 AM ---------- Previous update was at 02:27 AM ----------

But now I do not understand the error of the cut command :

Code:
[root@SHKsrv Scripts]# ./autouser.sh user.txt
cut: Une liste d'octets, de caractères, ou de champs doit être spécifiée.
Pour en savoir davantage, faites: « cut --help ».
cut: Une liste d'octets, de caractères, ou de champs doit être spécifiée.
Pour en savoir davantage, faites: « cut --help ».
./autouser.sh: line 14: .: filename argument required
.: usage: . filename [arguments]



---------- Post updated at 02:46 AM ---------- Previous update was at 02:29 AM ----------

I find the solution for the cut command error:

Code:
 12                         prenom= $(echo $ligne | cut -d: -f1 )
 13                         nom= $(echo $ligne | cut -d: -f2 )

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Auto Increasing Quota for User.

Hi, I would like to know wheather we can increase the quota for particular user automatically? I am having requirement to increase the quota only for 2 days in a week. but that shoule be automatically instead of manualy modification. is it possible? (3 Replies)
Discussion started by: manoj.solaris
3 Replies

2. OS X (Apple)

Scripting User Account Removal

Ok, so I've been looking all over the place for how exactly to do this and I've become so bombarded with information I finally decided I'll pose the question here. I'm not a programmer or anything that hardcore, but if I see things already implemented and working examples I can easily learn and... (17 Replies)
Discussion started by: panacea
17 Replies

3. Shell Programming and Scripting

Auto answer option in scripting.

Hi masters, How to get auto answer option in scripting. for example in my script i uses the gpg command , in that beginning it will ask passpharse : ( in that i need to type my passpharase) and once i typed it will ask Use this key anyway? ( for that answer will be yes) for... (1 Reply)
Discussion started by: anishkumarv
1 Replies

4. UNIX for Dummies Questions & Answers

Scripting - process and user ids...Help please

Hello all: Working on a job I was asked get a simple script to perform the following task and would like to ask for some help. I'm looking forward to learning more and diving deeper into the World of Open Source servers. I need a script for a Unix server, using as few lines as possible, that... (4 Replies)
Discussion started by: moahten
4 Replies

5. UNIX for Dummies Questions & Answers

scripting for user accounts info in UX

Hi guys, May I know how do I list out in UX for - all existing user accounts; sorted by activated/disabled - primary/sec groups of each user - date when the user accounts are created, - user last logon date - last password change date Anyone had done scripting for these info?... (0 Replies)
Discussion started by: doom10
0 Replies

6. Shell Programming and Scripting

auto login to Super User account

i want to write to script which will login to su account without hving user interaction.( i know Super user password) i wrote following script its also able to log into su account. but seesion gets terminates soon. what can be done ??? or is there any other solution. i don't want to use expect... (6 Replies)
Discussion started by: anup13
6 Replies

7. AIX

AIX; Auto clearing of 'too many invalid login attempts by user'

Does anyone have a good script / cron job that handles this? I have looked in smit and see it is clearing this count with: chsec -f /etc/security/lastlog -a "unsuccessful_login_count=0" -s '{userid}' However when I looked around to find ways to automate this I have not found an easy... (0 Replies)
Discussion started by: Keith Johnson
0 Replies

8. Solaris

Auto Locking user accounts

Hi, I am trying to setup account locking in Solaris 9. I have made the changes in /etc/default/login where RETRIES=5 and SYSLOG_FAILED_LOGINS=5 and in /etc/user_attr I am having: test_user::::lock_after_retries=yes Still I am not able to lock test_user after successive unsuccessful... (1 Reply)
Discussion started by: run_time_error
1 Replies

9. UNIX for Dummies Questions & Answers

freebsd auto login user at boot / i'm stuck

I run freebsd 4.8 and try to find the way or 'a' way to log in a certain user i created automaticaly at pc boot. I have searched the net, the manuals, but found nothing... could anyone please get me going by showing me an example or what file(s) i need to take a look at. i am not working... (6 Replies)
Discussion started by: termiEEE
6 Replies
Login or Register to Ask a Question