[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[K12OSN] 0D 0A (CR/LF) vs. 0A (LF) problem



Red Hat Linux release 7.3 (Valhalla)
Kernel: 2.4.18-3smp
vim: 6.1-2
 
I have been receiving the following error messages when attempting to run /etc/add-users.sh.
 
[root ANNA-K12LTSP /etc]# bash2 add-users.sh
: command not found
: command not found
'dd-users.sh: line 11: syntax error near unexpected token `md5crypt()
'dd-users.sh: line 11: `md5crypt()
 
One of the things I attempted to narrow down the problem was to recreate the add-users.sh file manually using the vi (or rather vim) editor that comes with the K12LTSP software.  I found that when I created the initial few lines of the file manually, I did not get error messages.  After a bit more head scratching and using a debugger, I came to find that the lines in the original add-users.sh file are terminated with 0D 0A characters (CR/LF), while the lines in my test file are terminated only with 0A characters (LF).
 
To make a long story short, is there a way that I can, using vim or some other editor, save the original add-users.sh file with 0A (LF) line delimiters only?  I would rather not have to retype the whole shebang.
 
Is this a normal situation: shell scripts with lines terminated with CR/LF cause the shell to spit out errors?
 
Here is the add-users.sh file from my server:
 
#!/bin/bash2
# Script to add many student accounts at once.  This is the
# RedHat version.  Run as root only.
# See the "disable-user" script to disable accounts before
# permanently removing them with 'remove-user'.
#
# Written 2002 by Wayne Pollock, Tampa FL USA.
 
PATH=/bin:/sbin:/usr/bin:/usr/sbin
 
md5crypt()
{
echo "$1" |openssl passwd -1 -stdin
}
 
if test "`whoami`" != "root"
then echo "You must be root to run this script.  Good-bye!"
    exit 1
fi
 
echo
echo "Enter class prefix(es) (e.g.: ua ub uc)"
echo -n "A good choice is the first 3 letters of the instructor's name: "
read CLASSES
set -- $CLASSES
if test $# = 0
then    echo "No classes entered, good-bye!"
        exit 1
fi
 
echo
echo -n "Enter number of accounts to create (e.g.: 25): "
read NUM JUNK
if test -z "$NUM"
then    echo "No value entered, good-bye!"
        exit 1
fi
if test "$JUNK"
then    echo "Only enter a single value, good-bye!"
        exit 1
fi
 
shopt -s extglob  # Allow extended pattern matching in bash
case "$NUM" in
+([0-9])) if test "$NUM" -eq 0
          then echo "You must create at least one account, good-bye!"
               exit 1
          elif test "$NUM" -gt 50
          then echo -n "$NUM are a lot of accounts, are you sure? "
               read ANS
               if test "$ANS" != 'y'
               then  echo "Good-bye!"
                     exit 1
               fi
          fi
          ;;
*)        echo "You must enter a number, good-bye!"
          exit 1
          ;;
esac
 
TODAY=$(date +%D)
echo
echo "For security accounts are created locked (disabled)."
echo -n "Enter the date the accounts should be unlocked (e.g. \"$TODAY\"): "
read UnlockDate JUNK
if test -z "$UnlockDate" -o -n "$JUNK"
then echo "You must enter a date such as \"mm/dd/yy\".  Good-bye!"
     exit 1
fi
CANONIZEDDATE=$(date --date="$UnlockDate" +%D)
if test "$TODAY" = "$CANONIZEDDATE"
then pwPrefix=""
     echo "Accounts will be created unlocked (enabled)!"
else pwPrefix="!"
     echo "Accounts will be unlocked at midnight on $CANONIZEDDATE."
fi
 
echo
echo "For highest security, accounts can be created with default"
echo "passwords.  If you chose this option the account names and"
echo "their passwords will be emailled to you.  If not, accounts"
echo "will not have passwords (users are be forced to change the"
echo "passwords when they first login, regardless."
echo
echo -n "Create accounts with initial passwords? (y/n)"
read REPLY
case "$REPLY" in
  y*|y*) GenPW=yes
         echo
         echo -n "Enter email address to send password report to: "
         read InstructorEmail JUNK
         echo "Passwords will be sent to $InstructorEmail"
         ;;
  *)     GenPW=no
         echo "No passwords will be generated!"
         ;;
esac
 
echo
if test "$NUM" -lt 10
then DISP_NUM="0$NUM"
else DISP_NUM="$NUM"
fi
if test $# -gt 1
then
    echo -n "Creating $# classes of $((NUM + 1)) students each "
    echo "(\"${1}00 - ${1}$DISP_NUM, ...)"
else
    echo -n "Creating 1 class of $((NUM + 1)) students "
    echo "(\"${1}00 - ${1}$DISP_NUM)"
fi
echo -n "OK to proceed? (y/n)? "
read answer
if test "$answer" != "y"
then
    echo "You ARE the weakest link...good-bye!"
    exit 1
fi
 
test "$GenPW" = "yes" && \
    exec 3> >(/bin/mail -s "New YborStudent Account Passwords" "$InstructorEmail")
 
logger -t "add-users" "Creation of $CLASSES accounts requested."
 
for CLASS in $CLASSES
do
    if grep "^$CLASS" /etc/passwd >/dev/null 2>&1
    then echo "Class \"$CLASS\" already exists, skipping..."
         logger -p warn -t "add-users" \
             "Skipping acount creation for $CLASS, already exists."
         continue
    fi
 
    logger -t "add-users" "Creating new user accounts for $CLASS."
 
    for i in $(seq -f "%02.0f" 0 $NUM)
    do
        User="$CLASS$i"
        echo -n "Adding user $User..."
        # Create group account for user:
        groupadd $User
 
        # Set the password: "" = no pw, unlocked, "!" = no pw, locked,
        # "Xy1Abc" = pw and unlocked, and "!Xy1Abc" = pw, locked.
        if test "$GenPW" = "yes"
        then
            # pronouncable with at least one digit and capital leter:
            pass=$(pwgen -cn)
            crypt=$(md5crypt "$pass")
            PASSWORD="$pwPrefix$crypt"
            echo -e "$User\t$pass" >&3
        fi
 
        # Create user: -m means create home dir and copy /etc/skel,
        #              -p '!' means create NULL (no) password for Linux
        #                 but initially lock (disable) the account,
        #              -g $User means put the user in his/her own group
 
        useradd -m -p "$PASSWORD" -g $User $User
 
        # This forces the password to be change every 150 days, and
        # sets the date of last change to be 1/1/1970.  Thus a user
        # is forced to set a password the first time they log in, and
        # that password should be valid for one semester (plus a few
        # extra weeks).
        chage -M 150 -d 1 $User #Linux
 
        # Set the quotas for the user:
        setquota -u $User 6000 8000 0 0 /dev/sda5 # /home
        setquota -u $User 1000 1500 0 0 /dev/sda8 # /var
 
        echo "done!"
    done
done
 
# Close the pipe to mail (which will send the email):
test "$GenPW" = "yes" && exec 3>&-
 
# Create an "at" job to unlock accounts on the specified date
# if necessary:
if test "$pwPrefix" = '!'
then
at midnight $CANONIZEDDATE >/dev/null 2>&1 <<-EOF
        for c in $CLASSES
        do
            for i in `seq -s ' ' -f "%02.0f" 0 $NUM`
            do
                usermod -U "\$c\$i"
            done
        done >/dev/null 2>&1
        logger -t "add-users" "Enabling $CLASSES student accounts."
        EOF
fi
 
Larry Mateo
Network Technician II
Fairfield-Suisun Unified School District
larrym fsusd k12 ca us

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]