Ambiguous error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ambiguous error
# 1  
Old 06-25-2012
Ambiguous error

Hello everybody,
I just took over this job from someone else and in the past this script they built worked but i recently upgraded from openSuSe 11.4 to 12.1

Now when i run the script i get an ambiguous error at line 25 (the first line after add() )
I have edited out the webpath and any passwords other than that the code is identical.

Code:
#!/bin/sh

# Version 1.1 Updated to new path /server/path/
# Version 1.0 Script created, tested and released

#Modified by Creater (creator@email) for OpenSUSE 11
#BULK add new user and delete users script from following website
#Arne Aase  Blog Archive  Guide: Simple shell script - Adding users to linux from file

#Added CHMOD command to stop users from reading other folders
#Added MySQL database (called username) setup for user using same username and password
#added MySQL database delete command when deleting user

#usage - add new students:
#sh students.sh -a add.txt
#text file format:
#add new user (1 username / password per line): username,passowrd,

#usage - delete students:
#sh students.sh -d del.txt
#text file format:
#delete user (1 per line): username

add()
{
        while read line
        do
                username=`echo $line | cut -d',' -f1`
                #removed  | mkpasswd -H md5 -s from the end of line
                password=`echo $line | cut -d',' -f2`
                echo "Accounts created for $username"
                sudo /usr/sbin/useradd -m $username -g 1001 -k /server/path/student/skel/ -d /server/path/student/$username

                #from http://www.kylecorey.ca/bash_scripting
                #assigns the password for the user
                echo "$password" | passwd --stdin "$username"
                #echos password for terminal display
                echo "Password for $username is $password"

                #set permissions so user cannot read other folders
                chmod g-rx /server/path/student/$username


                #create new database for user
                #from RBBOT on Grant priviledge for a user to a database via bash scripting - Web Hosting Talk
                mysql --user user --password=myawesomepassword --execute="CREATE USER $username@'localhost' IDENTIFIED BY '$password'"
                mysql --user user --password=myawesomepassword --execute="CREATE DATABASE $username"
                mysql --user user --password=myawesomepassword  --database mysql --execute="grant select , insert , update , delete , alter , create , drop on $username.* to $username@localhost iden
tified by '$password'"

                done < $1
                exit 1
}

del()
{
        while read line
        do
                username=`echo $line | cut -d',' -f1`
                #added -r to delete user directory
                sudo /usr/sbin/userdel -r $username

                #added MySQL command to drop user database
                #from RBBOT on Grant priviledge for a user to a database via bash scripting - Web Hosting Talk
                mysql --user user --password=myawesomepassword --execute="DROP DATABASE $username"
                mysql --user user --password=myawesomepassword --execute="DROP USER $username@'localhost'"

                echo "Accounts deleted $username"
        done < $1
        exit 1
}

help()
{
        echo "usage: -a -d -h <file>"
        echo "    -a add users listed in file"
        echo "    -d delete users listed in file"
        echo "    -h print help"
        exit 1
}

while getopts adh opt
do
        case ${opt} in
                a ) add ${!#};;
                d ) del ${!#};;
                h ) help;;
                \? ) help;;
        esac
done

help

# 2  
Old 06-26-2012
line is a command in Linux - newer bash versions complain when you use a command as variable.

line means read one line from stdin - the standard input device
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

$1”: ambiguous redirect

New to the site, please let me know I'm not meeting the post guidelines. I'm creating a bash script to generate a report with output from a grep command. The goal is to direct the output to a different log file by using a 'logger file'. But I get this error during the run: $1: ambiguous... (5 Replies)
Discussion started by: dallas88
5 Replies

2. Red Hat

ISO C++ ambiguous error

String.h has the following operator overloading function which is an user defined //declaration int operator==(char *ch) //definition int String::operator==(char *ch) { if (strcmp(_text, ch) == 0) { return TRUE; } else { ... (4 Replies)
Discussion started by: dany2704
4 Replies

3. Linux

Ambiguous redirect error and syntax error when using on multiple files

Hi, I need help on following linux bash script. When I linux commands for loop or while loop on individual file it runs great. but now I want the script to run on N number of files so it gives me ambiguous redirect error on line 12 and syntax error on line 22 : (pls help ); #!/bin/bash #... (16 Replies)
Discussion started by: Madhusudan Das
16 Replies

4. UNIX for Dummies Questions & Answers

Ambiguous command

I have run the following command and getting $fout: Ambiguous. set fout = `echo "$fnameLst" | awk '{gsub(/-dc*/,""); print}' | sort -u` (2 Replies)
Discussion started by: kristinu
2 Replies

5. Shell Programming and Scripting

ambiguous redirect error

This script has ambiguous redirect error. ... cd $HOME cd folder/work # search all subfolders in work directory find -mindepth 1 -maxdepth 1 -type d | while read directory do CUR_FOLDER="${directory#"./"}" cd $CUR_FOLDER chmod 644 * for ff in *; do if ; then ... (5 Replies)
Discussion started by: candyme
5 Replies

6. Shell Programming and Scripting

Ambiguous output redirect error

Hi everyone, While I was trying to do DATE=`date +"%Y%m%d_%H%M%S"` STARTLOG=$TUXSTDDIR/start_$DATE.log tmboot -y > $STARTLOG 2>&1 I got an error i.e. Ambiguous output redirect error. Here the first part is to boot the account so there is nothing wrong with that.... (6 Replies)
Discussion started by: pareshan
6 Replies

7. Shell Programming and Scripting

Ambiguous and Command not found Error in UNIX

Hi,All I wrote below script(Example1.sh) and i ran but i got error. it's excuted yesterday. SYSTEM_TIME=`date '+%H:%M:%S'` CMP_LOG_TIME=`head -1 runcmp-HINET.log` CMP_ENDED1=`grep 'HINET CMP ended' runcmp-HINET.log` CMP_ENDED2=`echo "HINET CMP ended"` CMP_FAILED2=`echo "HINET CMP... (2 Replies)
Discussion started by: koti_rama
2 Replies

8. UNIX for Dummies Questions & Answers

Ambiguous and Command not found Error in UNIX

Hi,All I wrote below script(Example1.sh) and i ran but it giveing error. it's excuted yesterday. SYSTEM_TIME=`date '+%H:%M:%S'` CMP_LOG_TIME=`head -1 runcmp-HINET.log` CMP_ENDED1=`grep 'HINET CMP ended' runcmp-HINET.log` CMP_ENDED2=`echo "HINET CMP ended"` CMP_FAILED2=`echo "HINET... (2 Replies)
Discussion started by: koti_rama
2 Replies

9. Shell Programming and Scripting

`ls -l`: Ambiguous

Hi, I'm trying to code a simple script (c-shell) on a Solaris box and I'm getting an "Ambiguous" error. These are the lines that cause the error: On c-shell: > set var = "" > @ var = `ls -l` `ls -l`: Ambiguous However if I change the second line to: > set var = `ls -l` This works... (2 Replies)
Discussion started by: Guillermo Lopez
2 Replies

10. Shell Programming and Scripting

getting Ambiguous error on kill -9 @pid from csh

Hello all i have simple script that executing program every 10 seconds im invoke this script as daemon with second script that put it in the background this is my first script (IsAliveTester.csh) #!/bin/csh -f @ iSleep = 10 set processName = "ClientTester" while(1) $processName ... (0 Replies)
Discussion started by: umen
0 Replies
Login or Register to Ask a Question