Operating System - HP-UX
1826141 Members
4593 Online
109690 Solutions
New Discussion

unable to invoke under name userdel.org error

 
SOLVED
Go to solution
Tapas Jha
Valued Contributor

unable to invoke under name userdel.org error

Hi,
I am trying to write one shell script which will delete users as well as it will delete from ftpusers entry and cron.allow entry and remove from cron.
But i am getting two problem. One and the main problem is userdel itself.
I have move /usr/sbin/userdel as /usr/sbin/userdel.org and i am invoking that userdel.org from userdel script which i kept in /usr/sbin directory.
When running /usr/sbin/userdel script i am getting below error message:
"Unable to invoke under name 'userdel.org' "

Please assist how to overcome this and what is the reason behind this.

Also if the above problem solve then one more problem exist. On that script how do i invoke userdel -r option?

Attached is my script.

Any help or suggestion is highly appreciated.

Regards
Tapas
Tapas Jha
7 REPLIES 7
Darren Prior
Honored Contributor

Re: unable to invoke under name userdel.org error

Hi Tapas,

I should imagine that this is done for security reasons. Certainly someone has gone to the trouble of detecting that it has been renamed and reporting that!

regards,

Darren.
Calm down. It's only ones and zeros...
Manish Srivastava
Trusted Contributor

Re: unable to invoke under name userdel.org error

Hi,

You cannot use userdel if you change its name.

manish
Tapas Jha
Valued Contributor

Re: unable to invoke under name userdel.org error

Well, if i can not , can you specify what is the reson behind this? Or what is the reason that one is not able to run the same file if that file is renamed?

Also, can you tell me how to include -r option in my script? Below(attached) is my script. Please specify where to change.

Rgds
Tapas

#!/usr/bin/sh
Usage() {
echo "\nUsage: $1 [-r] \n\n"
echo "-r: To remove the home directory user this option\n"
exit
}
deletelogin() {
login=$1
echo "deleting User ${login}" >> $USR_DEL_LOG
/usr/sbin/userdel.org $login
}

if [ $# -lt 1 ]
then
Usage $0
fi

until [ -z "$1" ]
do
deletelogin $1
shift
done
Tapas Jha
Bill Hassell
Honored Contributor

Re: unable to invoke under name userdel.org error

Tools for system administration can be dangerous so code writers often put checks in place about the name used to run the program. Writing a single program that does different things based on the runtime name is fairly common. The w and uptime commands are the same file. You can see this with ls:

ls -li /usr/bin/w /usr/bin/uptime

Another well-known set of commands are the dos and ls family. dosls, dosmkdir, dosll, dosrm, etc are links (8) and ls, ll, lsf, lsr, etc are also links (7).

There is no workaround since the program checks it's runtime name $0 when it starts. You'll have to rename userdel.org back to userdel and rename your script to deluser or something similar. Since userdel will not allow non-root user to run it, there doesn't seem to be much point in renaming the command. If your script is performing additional deletion steps, you can use SAM's task customization to accomplish these tasks.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor
Solution

Re: unable to invoke under name userdel.org error

And to answer the question about -r, just add -r to the command line as in:

/usr/sbin/userdel -r $login

Since this type of script requires root privileges to run, I would definitely rename the script to something like deluser and place it into a local root directory so you'll remember where it is. A lot of root-only tools get created by sysadmins and then are forgotten when installing or upgrading. root's $HOME is always /root and I use /root/bin for these specialized scripts.

Another technique is to lockout non-root user at the front of the script:

if [ $(id -u) -ne 0 ]
then
echo "\nRequires root to run\n"
exit 1
fi

You may want to takewaway the root password from most of your helpers and instead, give them sudo to run these special commands. The advantage with sudo is that you can prevent users from even attempting to run certain commands (like userdel) but allow them to run a command (script) like yours. And all sudo runs, successful or not, will be logged.


Bill Hassell, sysadmin
Tapas Jha
Valued Contributor

Re: unable to invoke under name userdel.org error

Hassel,

Thanks for your beutiful reply. I think your point is right.

I have moved original userdel to /usr/local/bin and place my userdel
script to /usr/sbin. This solves the problem.

Regarding -r option : In my script you can put several users name.
Like ::: userdel test1 test2 test3 . It will delete all users as well as it will delete from ftpusers and cron file. (test1, test2 test3 are loginname)

My question was if i use : userdel -r test1 test2 test3 Then how do i parse -r?

In my script main program is calling deletelogin $1 (in deletelogin it is like: /usr/local/bin/userdel login. I don't want to put -r here) and after that shift is changing $1.

Rgds
Tapas

Tapas Jha
Bill Hassell
Honored Contributor

Re: unable to invoke under name userdel.org error

You can make the script test for -r as the first parameter. This means that if it is the first parameter, it affects all the users. I don't think you want to allow something like this:

userdel -r test1 -r test2 test3 -r test4

So your script would look more like this (I have added validation code for users, tests to prevent removing root users and a different way to count the runtime parameters at the bottom):

#!/usr/bin/sh

set -u
export PATH=/usr/bin
USR_DEL_LOG=/var/tmp/userdel.log

function Usage
{
echo "\nUsage: $1 [-r] [ ]\n\n"
echo "-r: To remove the home directory user this option\n"
exit
}

function Deletelogin
{
OPTION="$1"
LOGIN=$2

if [ $(logins -l $LOGIN | awk '{print $1}') != $LOGIN ]
then
echo "\nUser $LOGIN not found - ignored"
elif [ $(id -u $LOGIN) -eq 0 ]
then
echo "\nUser $LOGIN is superuser - ignored"
else
echo "deleting User ${LOGIN}" >> $USR_DEL_LOG
/usr/sbin/userdel "$MINUSR" $LOGIN
fi
}

# check usage

if [ $# -lt 1 ]
then
Usage $0
fi

# Check if -r was specified

MINUSR=""
if [ "$1" = "-r" ]
then
MINUSR="-r"
shift
fi
COUNT=$#

# loop for all user logins on the line

until [ $# -lt 1 ]
do
Deletelogin "$MINUSR" $1
shift
done


Bill Hassell, sysadmin