LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-24-2014, 10:02 AM   #1
sekhar.hai
LQ Newbie
 
Registered: Jun 2014
Posts: 9

Rep: Reputation: Disabled
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
 
Old 06-24-2014, 10:07 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
please post the code that you have written so far and we will help debug.
 
Old 06-24-2014, 10:09 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by sekhar.hai View Post
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?
 
Old 06-24-2014, 11:41 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Help .... yes

Write it for you ... no
 
Old 06-24-2014, 01:18 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,096
Blog Entries: 10

Rep: Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522Reputation: 1522
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.
 
Old 06-25-2014, 02:35 PM   #6
DJ Shaji
Member
 
Registered: Dec 2004
Distribution: Fedora 22 (Twenty Two!), ArchLinux
Posts: 506
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
Quote:
Originally Posted by sekhar.hai View Post
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.
 
Old 06-25-2014, 03:35 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,788
Blog Entries: 1

Rep: Reputation: 1340Reputation: 1340Reputation: 1340Reputation: 1340Reputation: 1340Reputation: 1340Reputation: 1340Reputation: 1340Reputation: 1340Reputation: 1340
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-13-2013 12:20 AM
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM


All times are GMT -5. The time now is 08:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration