LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-07-2005, 09:19 AM   #1
vadon
LQ Newbie
 
Registered: May 2005
Distribution: RedHat 9
Posts: 4

Rep: Reputation: 0
bash scripting


I am new to Linux and I'm enrolled in college course. I need help writing a simple bash script, but I have not had any instruction on scripting. We are suppose to use the "man" pages and write the scripts on our own. Can anyone provide links that better describe how to script. The man pages are more for Linux users, not for us Windows users. The pages read more like greek to me. I need to write a script to add users from a list. The list is in the format of Lastname,Firstname and I need to username to first initial last name (flastname) all lower case. What command do I use and where can I find simpler instructions on how to do this.
 
Old 05-07-2005, 09:29 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
http://www.tldp.org/LDP/abs/html/

Google is your friend..

And that is probably one of the best online tutorials covering bash scripting.
 
Old 05-07-2005, 09:41 AM   #3
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,973

Rep: Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343
Welcome to LQ. Take a look at the following links to learn bash scripting:
http://www.tldp.org/LDP/abs/html/
http://www-106.ibm.com/developerwork...ry/l-bash.html
http://www.linuxcommand.org/writing_shell_scripts.php

Regards
 
Old 05-09-2005, 11:06 PM   #4
vadon
LQ Newbie
 
Registered: May 2005
Distribution: RedHat 9
Posts: 4

Original Poster
Rep: Reputation: 0
Yep.... still greek to me. I think I'm stuck wiht using Windows for ever. Thanks for the help anyways.
 
Old 05-09-2005, 11:11 PM   #5
vadon
LQ Newbie
 
Registered: May 2005
Distribution: RedHat 9
Posts: 4

Original Poster
Rep: Reputation: 0
Here's somethign I'd like to see. By the time you read this, my assignment will be over with so don't worry about doing my work for me. Can someone that knows what they are doing post a bash script that adds user from a list? The list format will be Firstname, Lastname. The username is going to be the first initial wit the last name, all lowercase. (flastname). I'd just like to see where I was going wrong. Most of the time my script would just hang and do nothing, or it would return invalid username.
 
Old 05-10-2005, 02:03 AM   #6
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Quote:
Originally posted by vadon
Here's somethign I'd like to see. By the time you read this, my assignment will be over with so don't worry about doing my work for me.
Never planned on doing your work for you.. as this is also stated in our RULES. Which will lead to your next question and my followup...

Quote:
Can someone that knows what they are doing post a bash script that adds user from a list? The list format will be Firstname, Lastname. The username is going to be the first initial wit the last name, all lowercase. (flastname). I'd just like to see where I was going wrong. Most of the time my script would just hang and do nothing, or it would return invalid username.
Now why would would post a script up here for you to copy from? That's not an effecient way to learn and do work your suppose to do yourself and you're never going to learn that way.

If you want help, why not post your script you have and we could perhaps tutor you on your mistakes, instead of giving you the answer.. then you'll actually learn something most likely.. but remember our rules you agreed to and that I linked to above.. don't expect anyone to do the work for you..

Last edited by trickykid; 05-10-2005 at 02:05 AM.
 
Old 05-10-2005, 05:07 AM   #7
vadon
LQ Newbie
 
Registered: May 2005
Distribution: RedHat 9
Posts: 4

Original Poster
Rep: Reputation: 0
userscript.sh

#!/bin/bash
clear
read TheUSER
while [ "TheUSER" != "" ]
do
read TheUSER
echo The User is $TheUSER
useradd $TheUSER

done

echo "All user names have been added"


my list file was cut down to just a sinlge name for testing.

userlist.txt contains:

Howard
Howard1
Fine

I removed the first names and added a 1 to the second Howard to test the script before I tried using the cut command to:


#!/bin/bash
clear
read TheUSER
while [ "TheUSER" != "" ]
do
read TheUSER | cut -f2-1 (I think this would return the first chacter after the comma) | tr [A-Z] [a-z] (I think this would change all caharters to lowercase)
echo The User is $TheUSER
useradd $TheUSER

done

echo "All user names have been added"

The actual userlist.txt will be:

Howard,Moe
Howard,Curly
Fine,Larry
 
  


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
Bash scripting pete1234 Programming 1 09-27-2005 02:48 AM
bash scripting.. kurrupt Programming 3 09-21-2005 01:07 AM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 05:09 AM
Bash scripting JonCooperUK Programming 3 03-04-2004 09:55 PM
Bash scripting kbeaver Programming 5 07-18-2003 09:35 PM


All times are GMT -5. The time now is 11:19 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration