Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

add user script

Posted on 2012-09-16
5
Medium Priority
?
907 Views
Last Modified: 2012-09-16
#!/bin/bash
cat  $1 | while read  un  gn  pw fn
      do
            cat  /etc/group  |  egrep $gn
                  if  [ $? == 0 ]; then
                        echo “Group $gn  already exists”
                  else
                        groupadd  $gn
                  fi
            pass=$(perl –e ‘print crypt($ARGV[0], “password”)’ $pw)
            cat /etc/passwd | egrep $un
                  if  [  $? == 0 ]; then
                        echo “user $un already exists”
                  else
                        useradd –p $pass –g $gn  $un
                        if  [ $? == 0 ]; then
                              echo “user added successfully added”
                        fi
                  fi
      done
In the code given above is the test.sh.
first I made a user.txt which contains username group name password and when I excute
./test.sh user.txt it gives me errors at line 10 unexpected EDF while looking for matching ')' and at line 21 syntex error.

What seems to be the problem
thank you for your help.
0
Comment
Question by:bt1942
  • 2
  • 2
5 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38402847
Could it be that a password in your input file contains an opening parenthesis?

If so, try "$pw" in the perl command.
0
 
LVL 85

Accepted Solution

by:
ozo earned 1000 total points
ID: 38402980
perl –e ‘print crypt($ARGV[0], “password”)’ $pw
should be
perl -e 'print crypt($ARGV[0], "password")' $pw
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 1000 total points
ID: 38403000
Wow, hard to see! Compliment to your excellent eyesight, ozo!

The same is true then for this line:

useradd –p $pass –g $gn  $un
should be
useradd -p $pass -g $gn  $un
0
 
LVL 85

Expert Comment

by:ozo
ID: 38403009
likewise, you probably meant
 echo "Group $gn  already exists"
when you said
 echo “Group $gn  already exists”
0
 

Author Comment

by:bt1942
ID: 38403018
I don't know why it shows –p but I wrote -p. I think there's something wrong with expert exchange website.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question