It is currently Tue, 07 Dec 2021 02:34:29 GMT



 
Author Message
 rm won't rm

Can someone please tell me why rm won't rm?

in my version of adduser I have the following lines after I've finished
messing with the passwd file:

echo -n "removing lock..."
rm -f /etc/.pwd.lock      
echo "done."              

and when I run adduser I see on-screen:

removing lock...done.

but the lock file is still there.

To make things even worse, when I needed to add about 20 users I wrote
another script as:

adduser .....
rm -f /etc/.pwd.lock
adduser .....
rm -f /etc/.pwd.lock

and still it didn't work, as only the first adduser worked, and then all
others failed because the lock file exists.

If I delete the file manually then it deletes correctly.

Below is my full adduser script, with the delete highlighted.  Also some of
you out there may like the .forward that I generate for every user I
create.  It emails me a notification every time a user received email so
that I can notify them.  I do this because out of about 150-200 users, only
10% have regulay access to networked pc's.

#!/bin/bash
#
# adduser 1.2: a utility to add users to the system
# modified by Gary Stainburn for use at Ringways
#
# Copyright (C) 1994 Ian A. Murdock <imurd...@shell.portal.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Written for the Debian Linux distribution (01/21/94).  Feel free to use
# it in YOUR distribution, too. :)  Please note that this is just a simple
# script that _somewhat_ automates the really boring and repetitive task
# of creating new user accounts.  It makes no attempt to be sophisticated.
# Let me know if you improve it in any way.
#
# I need to write a man page for this.
#
# Modified by Marc Ewing <m...@redhat.com> for RHS Linux
# Modified by Michael K. Johnson <johns...@redhat.com> for optional
# shadow password support.

# Everything happens too fast, so don't let the user interrupt.
trap "" 1 2 3 15

# Set a few important variables before getting started.
NUMARG=$#
LOGIN="$1"
REALNAME="$2"
if [ "X$REALNAME" = "X" ]; then
  REALNAME="RHS Linux User"
fi

ENAME="$3"
EXIST=0

echo "Login : $LOGIN"
echo "Real  : $REALNAME"
echo "email : $ENAME"

NOHOME=""

PASSWD="/etc/passwd"
PBAK="/etc/passwd-"           # Some programs use /etc/passwd-, others use
                                # /etc/passwd.OLD.  Take your pick.

SHADOW="/etc/shadow"
SBAK="/etc/shadow-"

GROUP="/etc/group"
GBAK="/etc/group-"

PLOCK="/etc/.pwd.lock"                # Standard method of locking the password file.

DSHELL="/bin/bash"
DHOME="/home"
SKEL="/etc/skel"
SPOOL="/var/spool/mail"
FIRST_UID=500
FIRST_GID=500

# A few sanity checks...
if [ `id -u` != 0 ]; then
        echo "Only root may add users to the system." ; exit 1
fi

if [ $NUMARG = 0 ]; then
        echo "You need to specify the login to add; for example, \`adduser" \
                "imurdock \"Ian Murdock\" ian.murdock'." ; exit 1
fi

id $LOGIN >/dev/null 2>/dev/null && EXIST=1

if [ $EXIST = 1 ]; then
        echo "The login $LOGIN already exists."
        exit 1
fi

if [ -f $PLOCK ]; then
        echo "$PASSWD is locked.  Try again later." ; exit 1
fi
touch $PLOCK ;

# And now the program begins:
echo "" ; echo -n "Looking for first available UID..."
NUID=`cut -f 3 -d ":" $PASSWD | sort -n | awk -v uid=$FIRST_UID '
                { if ($1 == uid) uid = uid + 1; }
END             { print uid; }
'`

if [ $NUID -ge 65536 ]; then
        echo "Sorry, ran out of uids."
        exit 1
fi
echo " $NUID"

echo -n "Looking for first available GID..."
NGID=`cut -f 3 -d ":" $GROUP | sort -n | awk -v gid=$FIRST_GID '
                { if ($1 == gid) gid = gid + 1; }
END             { print gid; }
'`

if [ $NGID -lt $FIRST_GID ]; then
        NGID=$FIRST_GID
fi
echo " $NGID"

echo "" ; echo -n "Adding login: $LOGIN..."

cp $PASSWD $PBAK
if [ -f "$SHADOW" ] ; then
  echo "$LOGIN:x:$NUID:$NGID:$REALNAME:$DHOME/$LOGIN:$DSHELL" >> $PASSWD
  cp $SHADOW $SBAK
  # The date invocation is non-standard, but works with GNU date.
  # It fills in the "last changed" field with the number of DAYS
  # since epoch (86400 seconds per day; %s is second since epoch).
  echo "$LOGIN:*:$(($(date '+%s')/86400))::-1:-1:-1:-1:-1:-1" >> $SHADOW
else
  echo "$LOGIN:*:$NUID:$NGID:$REALNAME:$DHOME/$LOGIN:$DSHELL" >> $PASSWD
fi

# Add user to users group
cp $GROUP $GBAK
sed "s/^\(users.*[^:]\)\$/\1,$LOGIN/" < $GBAK |
sed "s/^\(users.*:\)\$/\1$LOGIN/" > $GROUP

#sed "s/^\(users.*[^:]\)$/\1,$LOGIN/" < $GBAK |
#sed "s/^\(users.*:\)$/\1,$LOGIN/" > $GROUP

echo "$LOGIN::$NGID:$LOGIN" >> $GROUP
echo "done."

#----- this delete don't {*filter*}y work
echo -n "removing lock..."
rm -f /etc/.pwd.lock
echo "done."
#-----

if [ "x$NOHOME" = "x" ]; then
        echo -n "Creating home directory: $DHOME/$LOGIN..."
        mkdir $DHOME/$LOGIN
        chmod 2775 $DHOME/$LOGIN
        cp -a $SKEL/.??* $SKEL/* $DHOME/$LOGIN >/dev/null 2>/dev/null
        chown -R $NUID.$NGID $DHOME/$LOGIN
        echo "done."
        echo -n "creating default forward file..."
        echo "\\$LOGIN, \"|mail gary -s \\\"I've got mail\\\" </dev/null
        chown $NUID.$NGID $DHOME/$LOGIN/.forward
        echo "done."
fi

echo -n "Creating mailbox: $SPOOL/$LOGIN..."
touch $SPOOL/$LOGIN ; chmod 660 $SPOOL/$LOGIN ; chown $NUID.mail
$SPOOL/$LOGIN
echo "done."

if [ "x$NOHOME" != "x" ]; then
        echo ""
        echo "The home directory for $LOGIN was set to $DHOME/$LOGIN but the
directory"
        echo "was not created.  Be sure that you set it up properly."
fi

echo ""
echo "Please enter the password for $LOGIN"
passwd $LOGIN
#chfn $LOGIN

if [ "X$ENAME" != "X" ]; then
  echo "setting mail alias for $LOGIN to $ENAME"
  echo -e "$ENAME:\t\t$LOGIN" >> /etc/aliases
  newaliases
fi



 Sat, 10 Jun 2000 03:00:00 GMT   
 
   [ 1 post ] 

Similar Threads

1. (sol8 (intel))alias rm to rm -i in ksh88

2. find rm {} vs. rm -r

3. Bash won't rm files

4. .nfs files won't rm

5. rm -f won't get rid of -i behaviors

6. welcome.rm won't animate on rvplayer 5.0b2

7. rm -r won't work?

8. "rm: can't unlink 'files'",can't delete files

9. alias RM='mv $1 ~/garbage/'


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software