LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell Script (https://www.linuxquestions.org/questions/programming-9/shell-script-92214/)

Stinger 09-12-2003 11:12 PM

Shell Script
 
Hey Everyone.

Im new to Linux and i have been asked at work to write a script. Im sort of struggling with it. anyway what i need it to do is:

Have a file called "userlist" and a script called "addusers". the userlist file has the fields "username, password, group, fullname". ok i need this script to read the userlist file (i got that working)

Ive also been trying the grep command to search for certian words etc.

But now i need to be able to capture those words that grep finds and make them global varibles or something so i can then create a user account from the data grep found.

Can anyone steer me in the right direction, any help is very much appreciated.

Thank you so much

richhill 09-13-2003 06:51 AM

Stinger,

If you post your script, you should get the comments you are looking for.

Hko 09-13-2003 07:15 AM

Not complete, but something to start with:
Code:

#!/bin/bash

cat userlist | while read LINE ; do
        test "${#LINE}" = "0" && break
        set $LINE
        # now fields are available as $1, $2, ...

        echo "User = $1 :"
        echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        echo "    Password:  $2"
        echo "    Group:    $3"
        echo "    Full name: $4"
        echo
        echo
done


SaTaN 09-13-2003 09:30 AM

I suppose this would do the job for you
Code:

#!/bin/sh
num=`wc -l userlist |awk '{print $1}'`
for (( i=1 ; i <= $num ; i++ ))
do
useradd `cat userlist| head -n $i | tail -n 1 | awk '{print $1}'` ;
cat userlist | awk '{print $2}' | passwd --stdin `cat userlist | head -n $i |tail -n 1 | awk '{print $1}'`;
usermod -g `cat userlist | head -n $i | tail -n 1 | awk '{print $3}'` `cat userlist |head -n $i |tail -n 1  | awk '{print $1}'`;
chfn -f `cat userlist | head -n $i | tail -n 1 | awk '{print $4}'` `cat userlist |head -n $i |tail -n 1  | awk '{print $1}'`;
done


Stinger 09-13-2003 05:10 PM

Thank you everyone, now i have got some ideas and i will go write my own version :)


All times are GMT -5. The time now is 01:06 AM.