You're going to have the same problem with the other cut command:
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:
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:
With this you could also elminate the need to get the tty information from the ps output.
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)
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)
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)
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)
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)
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
LEARN ABOUT OSF1
tty
tty(1) General Commands Manual tty(1)NAME
tty - Returns pathname of terminal device
SYNOPSIS
tty [-s]
The tty command writes the full pathname of your terminal device to standard output. The tty command may also be used to determine if
standard input is a terminal.
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
tty: XCU5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
OPTIONS
Suppresses reporting the pathname.
The XCU specification states that -s option is obsolete and recommends the portable applications use test -t 0 instead of tty -s.
OPERANDS
None
DESCRIPTION
The command tty -s evaluates as TRUE if standard input is a display and FALSE if it is not.
[Tru64 UNIX] The file /dev/tty is a special file always refers to your controlling terminal, although it also may have another name like
/dev/console or /dev/tty2. To avoid writing undesirable output to an output file--for example, to write a prompt in a shell script to the
screen, while writing the response to the prompt to an output file--redirect standard output to /dev/tty.
NOTES
While the -s option is useful if only the exit code is wanted, it does not rely on any ability to form a valid pathname. For a portable
application you should use the command test -t 0.
EXIT STATUS
The following exit values are returned: Successful completion. Standard input is not a display. [Tru64 UNIX] Invalid options specified.
[Tru64 UNIX] An error occurred.
DIAGNOSTICS
[Tru64 UNIX] Your standard input is not a display and you did not specify the -s option.
EXAMPLES
To display full pathname of your terminal device, enter: tty To test whether or not the standard input is a terminal device, create a shell
script containing the following: if tty -s then echo 'Output is a display' else echo 'Output is not a display' fi
If the standard input is a terminal device, this displays the Output is a display message. If the standard input is not a terminal
device, it displays the Output is not a display message.
ENVIRONMENT VARIABLES
The following environment variables affect the execution of tty: Provides a default value for the internationalization variables that are
unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari-
ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value,
overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the for-
mat and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of
LC_MESSAGES.
FILES
Pseudodevice representing the user's controlling terminal.
SEE ALSO
Commands: stty(1), test(1)
Routines: ttyname(3)
Files: tty(7)
Standards: standards(5)tty(1)