Results 1 to 6 of 6

Thread: Desperate, shell script not working,please help

  1. #1
    Join Date
    May 2018
    Beans
    2

    Desperate, shell script not working,please help

    Hello everybody,
    Im trying to get this script working but what I get is:
    14: Syntax error: "(" unexpected (expecting "fi").

    Hope you guys can solve my problem...

    Thanks in advance.


    Here is the script:

    Code:
    #!/bin/bash
    #========================================
    #Eb  
    #Date:  15/5/2018
    #Nombre:ID:Telefono:Direccion:DOB:Departamento:Salario
    #
    #=========================================
    filein="proyecto3.csv"
    IFS=$'\n'
    if [ ! -f "$filein" ]
    then
    echo "Cannot find file $filein"
    else
      groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`)
      fullnames=(`cut -d: -f 1 "$filein"`)
      userid=(`cut -d: -f 2 "$filein"`)
      usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`)
    fi
    for group in ${groups[*]}
    do
    grep -q "^$group" /etc/group ; let x=$?
    if [ $x -eq 1 ]
    then
    groupadd "$group"
    fi
    done
      x=0
      created=0
    for user in ${usernames[*]}
    do
    useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null
    if [ $? -eq 0 ]
    then
    let created=$created+1
    fi
    echo "${usernames[$x]}" | passwd --stdin "$user" > /dev/null
    echo "Complete. $created accounts have been created."
    fi
    Last edited by 13bubus; May 24th, 2018 at 03:22 AM.

  2. #2
    Join Date
    Jul 2008
    Location
    The Left Coast of the USA
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Desperate, shell script not working,please help

    Hello!

    Have you consulted with your instructor or your classmates?
    Please read The Forum Rules and The Forum Posting Guidelines

    A thing discovered and kept to oneself must be discovered time and again by others. A thing discovered and shared with others need be discovered only the once.
    This universe is crazy. I'm going back to my own.

  3. #3
    Join Date
    May 2018
    Beans
    2

    Re: Desperate, shell script not working,please help

    Quote Originally Posted by QIII View Post
    Hello!

    Have you consulted with your instructor or your classmates?
    I don't go to school and honestly I do not see the usefulness of your answer.

  4. #4
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: Desperate, shell script not working,please help

    all wrong, you can't just add on any which way.

    read up on> if elif else<- https://www.google.com/search?client...utf-8&oe=utf-8

  5. #5
    Join Date
    Jul 2008
    Location
    The Left Coast of the USA
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Desperate, shell script not working,please help

    Quote Originally Posted by 13bubus View Post
    I don't go to school and honestly I do not see the usefulness of your answer.
    That was not an answer. It was a question, asked by a Forum Admin for a purpose.
    Please read The Forum Rules and The Forum Posting Guidelines

    A thing discovered and kept to oneself must be discovered time and again by others. A thing discovered and shared with others need be discovered only the once.
    This universe is crazy. I'm going back to my own.

  6. #6
    Join Date
    Jun 2018
    Beans
    Hidden!

    Re: Desperate, shell script not working,please help

    Code:
    #!/bin/bash
    #========================================
    #Eb  
    #Date:  15/5/2018
    #Nombre:ID:Telefono:Direccion:DOB:Departamento:Salario
    #
    #=========================================
    filein="proyecto3.csv"
    IFS=$'\n'
    if [ ! -f "$filein" ]
    then
    echo "Cannot find file $filein"
    else
      groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`)
      fullnames=(`cut -d: -f 1 "$filein"`)
      userid=(`cut -d: -f 2 "$filein"`)
      usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`)
    fi
    for group in ${groups[*]}
    do
    grep -q "^$group" /etc/group ; let x=$?
    if [ $x -eq 1 ]
    then
    groupadd "$group"
    fi
    done
      x=0
      created=0
    for user in ${usernames[*]}
    do
    useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null
    if [ $? -eq 0 ]
    then
    let created=$created+1
    fi
    echo "${usernames[$x]}" | passwd --stdin "$user" > /dev/null
    echo "Complete. $created accounts have been created."
    should work better. But the previous answers are relevant, it was VERY easy to find out based on the if-else-then logic, except if you are ABSOLUTELY not at ease with computing.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •