Sponsored Content
Top Forums Shell Programming and Scripting Cannot kill hacker process with my script Post 302442578 by agama on Wednesday 4th of August 2010 09:49:37 PM
Old 08-04-2010
You're going to have the same problem with the other cut command:

Code:
hackertty=$(ps -fu $(logname)| grep xterm | cut -d ' ' -f10)

For the times that it fails, there are probably enough extra blanks in the line that picking up 'field 10' isn't getting the tty, but some other string. Then when you compare these to your tty name they will never match and you'll kill your session. Use the same technique with awk to pick up the correct tty field from the ps output.

If you want to be doubly sure that you don't kill your xterm, you could pass the process id to the script (it's possible to have the script dig this info out, but easier to pass it in). If your script is called kill_hacker, the command line might look something like:

Code:
kill_hacker $PPID

and the code in the script could be changed to test that the process id you're about to kill isn't the one passed in:

Code:
dont_kill=$1           # get xterm pid that we want not to kill
if [[ -z $dont_kill ]]
then
      echo "abort: missing process-id on command line"
      exit 1
fi
:
:
while (( $j < ${#hackerttycurrent[*]} ))
do   
        if [[ ${hackercurrent[$j]} != $dont_kill ]]
        then
                kill -9 ${hackercurrent[$j]}
                echo " killed: pid=${hackercurrent[$j]} tty=${hackerttycurrent[$j]}"
        else
                echo "skipped: pid=${hackercurrent[$j]} tty=${hackerttycurrent[$j]}"
        fi

        j=$(( j+1 ))
done

With this you could also elminate the need to get the tty information from the ps output.
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to kill process

Hello guys, I have a process named monitoreo, with 'monitoreo start' my process start until i kill them, now i want to do 'monitoreo stop' to kill them. After 'monitoreo start' i have this process running: ps -af UID PID PPID C STIME TTY TIME CMD ati 10958 1495 ... (5 Replies)
Discussion started by: Lestat
5 Replies

2. Shell Programming and Scripting

Script to kill process...

hello Bros, I need to write some script that i can put it on crontab which checks for a process X if running. If the process X is ruuning then take the PID and kill it or display message that says process X is not running. I am using AIX 5.3 Thanks guys.:b: (2 Replies)
Discussion started by: malcomex999
2 Replies

3. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

4. Shell Programming and Scripting

Script to Kill a Process by Name...

Hello all... new to these forums and a bit of a newbie with linux aswell. I need to figure out how to write a shell script to kill a process by name as given to the script as an argument. I've got that part working OK, but i need to make sure that the script does not allow processes that are... (6 Replies)
Discussion started by: cannon1707
6 Replies

5. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

6. Shell Programming and Scripting

kill my processes which are run by hacker

how can I kill my processes which are run by hacker or another person who log in with my username and password (1 Reply)
Discussion started by: thsecmaniac
1 Replies

7. Shell Programming and Scripting

Kill all child process of a script

Hi guys i have a problem with a script... this script creates differents GUI with YAD... well i want that when i press the "Cancel" button on this graphical interface all the child process and even the same script should be killed #!/bin/bash function gui_start { local choice="" ... (4 Replies)
Discussion started by: maaaaarco
4 Replies
INSTALLSIEVE(1) 					      General Commands Manual						   INSTALLSIEVE(1)

 *

NAME
installsieve - user utility for managing sieve scripts SYNOPSIS
installsieve DESCRIPTION
installsieve is a utility that allows users to manage their sieve scripts kept on the server. OPTIONS
-v <name> View script with the given name. The script if retrieved sucessfully is output to standard output. -l List all of the scripts currently on the server. If one of the scripts is active a arrow is printed indicating that it is the active script. -p <port> Port to connect to. If left off this defaults to "sieve" as defined in /etc/services. -i <file> Install a file onto the server. If a script with the same name already exists on the server it is overwritten. Upon sucessfully putting the script on the server the script is set active. If <file> has the extension .script it is chopped when put on the server since sieve names may not contain a '.'. -a <name> Set <name> as the active script. The list of available names can be obtained from the '-l' option.. -d <name> Delete the sieve script on the server with <name>. -m <mechanism> Force installsieve to use <mechanism> for authentication. If not specified the strongest authentication mechanism is chosen. -g <name> Get the sieve script with <name> and save it to disk with a ".script" extension. If a file with that name already exists it is overwritten. -u <user> Userid/Authname to use for authentication; by default, the current user. CMU
Project Cyrus INSTALLSIEVE(1)
All times are GMT -4. The time now is 08:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy