LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell scripting (https://www.linuxquestions.org/questions/linux-newbie-8/shell-scripting-4175509015/)

sekhar.hai 06-24-2014 09:02 AM

Shell scripting
 
Hi everyone,

I am A.chandrasekhar, a beginner of Linux admin and i want to study
shell scripting, please any one can help me how to write a script?

1. Write a shell script it needs to create a user with necessary fields like firstname,lastname,username,password,confirm pwd, and here
we have some conditions like pwd and confirm pwd doesnot match it needs to print pwd doesnot match and later user will create.

Please help me out to write this script in a easy way, so i can understand easily as a beginner.

Thanks & Regards,
A.Chandrasekhar

schneidz 06-24-2014 09:07 AM

please post the code that you have written so far and we will help debug.

TB0ne 06-24-2014 09:09 AM

Quote:

Originally Posted by sekhar.hai (Post 5193114)
Hi everyone,
I am A.chandrasekhar, a beginner of Linux admin and i want to study shell scripting, please any one can help me how to write a script?

1. Write a shell script it needs to create a user with necessary fields like firstname,lastname,username,password,confirm pwd, and here we have some conditions like pwd and confirm pwd doesnot match it needs to print pwd doesnot match and later user will create.

Please help me out to write this script in a easy way, so i can understand easily as a beginner.

Please read the LQ Rules about posting verbatim homework questions. And yes, we will be happy to help you...but 'help' is where YOU do your share of the work, not just ask someone for a handout. If you want to 'study', what have you done/tried so far? What have you written?

There are THOUSANDS of very easily-found shell scripting tutorials you can find with a brief Google search...since you want to 'study', which one(s) have you looked up so far?

grail 06-24-2014 10:41 AM

Help .... yes

Write it for you ... no

rtmistler 06-24-2014 12:18 PM

Blog entry on scripting

Also see Habitual's list of useful links, many of which are BASH scripting guides.

Start your own homework and if/when you get stuck, ask more well informed questions; you'll get some assistance that way.

DJ Shaji 06-25-2014 01:35 PM

Quote:

Originally Posted by sekhar.hai (Post 5193114)
a beginner of Linux admin

Bit contradictory, don't you think :)

You can use e.g useradd and read. Really very easy to do. Wouldn't take more than a minute or two.

szboardstretcher 06-25-2014 02:35 PM

Typed in 'shell script add user' at Google.com

Here is the first of millions of results.

Code:

#!/bin/bash
# Script to add a user to Linux system
if [ $(id -u) -eq 0 ]; then
        read -p "Enter username : " username
        read -s -p "Enter password : " password
        egrep "^$username" /etc/passwd >/dev/null
        if [ $? -eq 0 ]; then
                echo "$username exists!"
                exit 1
        else
                pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
                useradd -m -p $pass $username
                [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
        fi
else
        echo "Only root may add a user to the system"
        exit 2
fi

Source http://www.cyberciti.biz/tips/howto-...-add-user.html


All times are GMT -5. The time now is 12:49 PM.