LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash scripting (https://www.linuxquestions.org/questions/linux-newbie-8/bash-scripting-320995/)

vadon 05-07-2005 08:19 AM

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.

trickykid 05-07-2005 08:29 AM

http://www.tldp.org/LDP/abs/html/

Google is your friend.. ;)

And that is probably one of the best online tutorials covering bash scripting.

bathory 05-07-2005 08:41 AM

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

vadon 05-09-2005 10:06 PM

Yep.... still greek to me. I think I'm stuck wiht using Windows for ever. Thanks for the help anyways.

vadon 05-09-2005 10:11 PM

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.

trickykid 05-10-2005 01:03 AM

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.. :tisk:

vadon 05-10-2005 04:07 AM

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


All times are GMT -5. The time now is 08:09 AM.