Help with script to stop a user giving kill command on a server!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with script to stop a user giving kill command on a server!!
# 1  
Old 01-04-2010
Help with script to stop a user giving kill command on a server!!

Hi,

I am new to shell scripting and want to create a script with the follwoing description:

I want to restrict the users from giving a kill command on a unix server. The server have a restricted logins with login id and passwords. I want a script that will find out if a user has given a kill command and if finded soem user that has given kill command, then promt that user not to give kill command. It should give an option to the logged in person " You should not use kill command but if you still wish to continue type yes else type no"
If the person types yes then he should give his details (unix id and password) that the script will authenticate and if passed then the person can give the kill command, provided i get his login details.

Please help Smilie
# 2  
Old 01-04-2010
One way is to create an alias. Most users do not know anything about /usr/bin/kill,
they just use kill [pid]. This is a start on your requirements - I don't know what you mean by authenticate. Relogin?
Instead of specifying things like that, just tell us what you want to have happen.


You need to put this script somewhere that all of the users you describe have access to the file - just read/execute access:
Code:
#!/bin/ksh
# fake "kill" script
typeset -u ok

echo "" You should not use kill command but if you still wish to continue type yes else type no: yes/no"

read ok
if [[$ok = "YES" ]] then
   /usr/bin/kill $1 $2
else
   echo 'no process killed'
fi

Call the script, for example, /path/you/created/for/fake_kill.sh

Be sure to chmod +x /path/you/created/for/fake_kill.sh
Be sure all the directories of the path allow execute access for restricted users.

Add this to your login script for restricted users
Code:
alias kill=/path/you/created/for/fake_kill.sh

# 3  
Old 01-04-2010
And maybe add:

who am i >>/usr/boss/kill.log
or
mail -s "Job Killed" boss <`who am i`

just before the /usr/bin/kill $1 $2 line
# 4  
Old 01-05-2010
Hey,
Thanks for the suggesstion. But i am a little confused. As mentioned in the script above, a fake_kill script will be created, so what will happen to /usr/bin/kill. Should that be deleted??
My requirement goes like this:
I want to warn the users if they are using kill command to kill some logins. I want to run this script on a server which has three login id's permitted(say abc/passowrd, cde, password, fgh/password). A user can telnet to that server and login using only these permitted id's whch are shared globally in our team. So the issue that we are facing is we are unaware which person gave kill command and forced out a person doing some activity on the server.
So, the script should check if anyone has given KILL command; it should warn the person; " not to use kill command" and then display an option yes/no as mentioned in the script above and stop the execution of kill command if the person enters no. And if the person enters yes, then it should ask the person to provide his unix id as he is logged into the server with some other login and after verifying his login details, we can allow that person to use kill command execution normally, as we will be aware who has given kill command.
I hope i made my requirement clear this time.
Thanks in advance
# 5  
Old 01-05-2010
if your users are cooperative - simple wrapper is enough .
If they are malicious - it takes 3 min to write kill.c and compile it ( in case compiler is available )
# 6  
Old 01-05-2010
Why don't you use sudoers ?
# 7  
Old 01-05-2010
Hey
As i am new to acripting. Could you please help me in explaining this in detail..........
Thanks in advance

Last edited by shell_scripting; 01-05-2010 at 09:21 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to stop and start server

Hi, I need to create a shell script for automated server patching, with the following scenario: I have two Linux servers Primary and secondary. Server patching should start on Primary 1st and then secondary. 1st check both servers are up and running. Then stop primary and patching will... (1 Reply)
Discussion started by: rcroyal88
1 Replies

2. Shell Programming and Scripting

script to kill a pid giving error

Hi, I simply want to kill a running process using a script that read pid from a file and tries to kill it .Getting error as shown below code.. cat $HOME/BackupScript.ksh.run | head -1 | while read pid do ps -p $pid > /dev/null 2>&1 if ; then kill -9 $pid else echo "no running $pid... (5 Replies)
Discussion started by: dhirajdsharma
5 Replies

3. Shell Programming and Scripting

Creating oracle user and giving him grants using shell script

Hi , I want to write a shell script that can create oracle database user and grants permission to this user. Thanks & Regards, Deepak (4 Replies)
Discussion started by: Deepakjha
4 Replies

4. Shell Programming and Scripting

How to stop a script running in remote server from local script

Hi, I have googled for quite some time and couldn't able to get what exactly I am looking for.. My query is "how to stop a shell script which is running inside a remote server, using a script"??? can any one give some suggestions to sort this out. (1 Reply)
Discussion started by: mannepalli
1 Replies

5. UNIX for Dummies Questions & Answers

crontab or looping script to Kill process from user

I am looking for a way to kill 2 processes from a user through some kind of script. Using an oracle script, I get two process ids that need to be killed. SQL> select ssn.process as client_process_id, pcs.spid as oracle_process_id, ssn.sid, ssn.serial# 2 from v$session ssn inner join... (5 Replies)
Discussion started by: Meert
5 Replies

6. Shell Programming and Scripting

mv command is giving error in shell script

Hi, In my shell script when I am using mv command using shell variables it is giving me error of syntax. Following is the shell script: file_edifice="*.txt" fquote="'" fdquote=\" for file in $file_edifice do file_name=$fquote$file$fquote tofile_name=`date... (5 Replies)
Discussion started by: gammit
5 Replies

7. AIX

Script allows user to kill other users: I'd like to know HOW...

Hello list, Have a problem that's highlighting gaps in my knowledge; can you assist? We have a script that's tacked onto our trading application which allows branch managers etc. to kill off the sessions of other users at their branch. A menu option in the application spawns a shell running... (8 Replies)
Discussion started by: alexop
8 Replies

8. Shell Programming and Scripting

Stop / kill the process individually

Hi , I have a situation, where I have 10 indivudal processess started by similar instance.I say similar instance because each of them being started as a new thread: Say I've following unix process running process1_ADAP process2_ADAP process3_ADAP Current scenario: Now I have SHUTDOWN... (5 Replies)
Discussion started by: braindrain
5 Replies

9. UNIX for Dummies Questions & Answers

How do I stop or kill Netscape FastTrack Server?

After installing Apache and configuring the httpd.conf file to listen to port 80, I have come to find that there is another server on the Sco box I'm working on. Would someone please tell me how to stop or kill this server. The server is Netscape FastTrack Server. Also, how might I remove all... (2 Replies)
Discussion started by: cstovall
2 Replies
Login or Register to Ask a Question