Sunday, May 17, 2009

Terminate a socket without terminating a process:HP-UX

PROBLEM

Terminate a socket without terminating a process

RESOLUTION

Refer to man page on ndd:

#man 1m ndd

ndd -h supported (will display supported ndd parameters)
ndd -h unsupported (will display unsupported ndd parameters)

Here is an example using the tcp_discon parameter:

#ndd -get /dev/tcp tcp_discon number

NOTE: This number is obtained by running the following command:

#ndd -get /dev/tcp tcp_status

The tcp_status will give you a long list of connected sockets. Find the one
that needs to be killed (use netstat -a (if you have the name of the
host, use the -n option if you have the IP of the host you are looking
for) and then compare to ouput of the -get command below to find the
hostname or the ip). Then use the number on the far left of the output
(LEADING ZEROS must be removed from the number) and prepend it with a 0x to
show its hex.

Example of commands:

* #ndd -get /dev/tcp tcp_status
* #ndd -set /dev/tcp tcp_discon 0x010203404

If using the tcp_discon_by_addr variable convert the ip address into the
hexadecimal representation.

#ndd -set /dev/tcp tcp_discon_by_addr [hex number]

Where '[hex number]' is the one that needs to be killed.

:ciao..

Wednesday, May 6, 2009

Crontab : HP-UX

Many times admins forget the field order of the crontab file
and alway reference the man pages over-and-over.

Make your life easy. Just put the field definitions in your crontab file
and comment (#) the lines out so the crontab file ignores it.

# minute (0-59),
# | hour (0-23),
# | | day of the month (1-31),
# | | | month of the year (1-12),
# | | | | day of the week (0-6 with 0=Sunday).
# | | | | | commands
3 2 * * 0,6 /some/command/to/run
3 2 * * 1-5 /another/command/to/run

export EDITOR=vi ;to specify a editor to open crontab file.

crontab -e Edit your crontab file, or create one if it doesn't already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)


Here are some examples.

0 0 * * * -- midnight every day
0 0 * * 1-5 -- midnight every weekday
0 0 1,15 * * -- midnight on 1st and 15th of month
0 0 1 * 5 -- midnight on 1st of month and every Friday

Crontab example:

A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.

30 18 * * * rm /home/someuser/tmp/*


Cheers !!!

Sunday, May 3, 2009

Pacquiao Blows Out Hatton in Two


Sun, 03 May 2009...It was two rounds of brutal action and a two round blowout for Filipino sensation Manny “The Pacman” Pacquiao as he walked through, around, and all over Ricky “The Hitman” Hatton (45-2 with 32 KOs).


Saturday, May 2, 2009

HP-UX How can I disable non-root logins?

Add the following to /etc/profile, then 'touch /etc/nologin'; this will disable all new logins, except by root:

uid=`id -u`
if [ -f /etc/nologin -a $uid -ne 0 ]; then
echo "Sorry, no logins allowed; try later!"
sleep 5
exit 0
fi

::gudluck!

Friday, May 1, 2009

Root Lost Password : HP-UX... ;)

... but... what if your system is trusted mode???
..you can use some steps of this procedure if you want re-stablish a password than can not be set by cyclic problems...

The steps to reactivate the root account:
1. Boot the system in to single user mode.
2. Mount /usr file systems.# mount /usr
Note: The file system might need file system check (fsck) before mounting.
3. Systems that are not using Trusted System security skip to step #4.For Trusted Systems (presence of a /tcb directory), follow these additionalsteps:
a) Use the following command to reactivate the 'root' account:# /usr/lbin/modprpw -k root
b) Use the 'modprpw' command to null the password, so that the passwd commanddoes not prompt for the old password.
10.x# /usr/lbin/modprpw -w "" root
11.x# /usr/sam/lbin/usermod.sam -F -p "" root
NOTE: To untrust the system, use: tsconvert -r
4. Change the root account password.# passwd root
5. Boot the system in to multi user mode.

fyi la....

Wednesday, April 29, 2009

HP-UX : Extract one file from a make_tape_Recovery

To check the contents of the recovery tape ( assuming the tar archive and 0m/n as device file )
# mt -f /dev/rmt/0mn rew
# mt -f /dev/rmt/0mn fsf 1
# tar tvf /dev/rmt/0m

To extract a file from the archive
# mt -f /dev/rmt/0mn rew
# mt -f /dev/rmt/0mn fsf 1
# tar xvf /dev/rmt/0m

:: Don't try this at work :-)


Wednesday, April 22, 2009

HP-UX File Processing

:: Viewing contents of a file

The cat (concatenate) command can be used to view the contents of a file.

% cat friends
Sally Johnson 123 Ellesmere Lane Athens GA 12876 (413)345-8976
Bob Beamon 913 Mockingbird Lane Annapolis MD 17701 (201)962-8765
Kim Smith 234 Working Street Hollywood CA 18765 (678)987-9876
%
You will find on large files that the output of cat will not fit on your screen. The output will scroll across the screen and you will not be able to view the information. The more command is used to display file information in screen sized chunks. If the file is more than one screen long the word -More- followed by the percentage of the file displayed is placed at the bottom of the screen. Press the SpaceBar to see the next screen of the file or press q or to quit. It is better to use more if your output is going directly to the screen and to use cat if your output is going to a file or pipe.

::Pattern Searching

The grep (global regular expression print) command is used to search for a particular word or phrase in a file. The format of the grep command is:

grep [options] string file(s)

Where string is the word, phrase or regular expression you want to find, and file is the file to be searched. Lets find all lines that contain the string Sally in our friends file.

% grep Sally friends
Sally Johnson 123 Ellesmere Lane Athens GA 12876 (413)345-8976
Sally Miller 510 Epping Way Hobe Sound FL 33455 (654)546-4526
%
To find a pattern that is more than one word long, enclose the string within single or double quotation marks.

% grep 'Sally Miller' friends
Sally Miller 510 Epping Way Hobe Sound FL 33455 (654)546-4526
%
So far we have seen how grep prints all lines which contain the given character string. The -v (invert) option instructs grep to print all lines except those which match the string. This is usefull when you want to remove lines from a file. Lets find all the lines in a file that do not contain the string Sally and place the output into the friends.new file.

% grep -v 'Sally' > friends.new
% more friends.new
Bob Beamon 913 Mockingbird Lane Annapolis MD 17701 (201)962-8765
Kim Smith 234 Working Street Hollywood CA 18765 (678)987-9876
Eddy Murphy 210 W. Hollywood Los Angles CA 90210 (876)238-9987
%
The grep command can be used with regular expressions to match a pattern.
% grep '26$' friends
Sally Miller 510 Epping Way Hobe Sound FL 33455 (654)546-4526
%
This will find all the lines that end in "26".

The grep command can search for a string in groups of files. When it finds a pattern that matches in more that one file, it prints the name of the file, followed by a colon before the line matching the pattern. The -i (ignore) option to grep will ignore the case.

% grep -i bob *
friends:Bob Beamon 913 Mockingbird Lane Annapolis MD 17701 (201)962-8765
friends.new:Bob Beamon 913 Mockingbird Lane Annapolis MD 17701 (201)962-8765
%

:: Comparisons between files

The cmp (compare) command is used to compare any two files, including executable files. The diff (differential file operator) command is used to display the differences between text files or directories. The order of the diff command is important. The format of the diff command is:

diff [options] old_file new_file diff [options] old_dir new_dir

The diff command will display a listing of the editing actions that need to be performed on the old file to change it into the new file. The three ways in which diff indicated changes to a file are a (lines are added), c (lines are changed) and d(lines are deleted). Lets find the difference between the friends and the friends.new files.

% diff friends friends.new
1d0
< Sally Johnson 123 Ellesmere Lane Athens GA 12876 (413)345-8976
4d2
< Sally Miller 510 Epping Way Hobe Sound FL 33455 (654)546-4526
%
This tells us that deletions need to be made to the friends file to get the friend.new file. The 1d0 tells us that line 1 of the friend file has to be deleted, and the 4d2 tells us that line 4 of the friend file has to be deleted.

The output of diff can be sent to the ed command to convert the first file into the second. In fact, the using diff with the -e option will produce output suitable for input to the ed command.

% diff -e friends friends.new > ed.script
% ( cat ed.script ; echo w ) | ed friends
415
249
% diff friends friends.new
%
If you eliminated the echo w command, ed would read the input from the cat ed.script, perform the operation and then exit. With the echo w command you are telling ed to write to the file friends. The semicolon between the cat ed.script and echo w tells the shell that these are separate commands.

:: Counting things in a file

The wc (word count) command counts the number of lines, words, and characters in a file. This is especially usefull for counting the number of lines of source code in a program orthe number of words in a document.

% wc friends
3 28 249 friends
%
The first number indicates the number of lines, followed by the number of words and the number of characters(including newlines).

:: Modifying character strings

The sed (stream editor) command reads lines, one by one, from an input file and applies a set of editing commands to the lines. The sed command is like grep except that it allows you to make changes to file. The format of the sed command is:

sed [options] action/string/newstring file(s)

% sed "s/(201)962-8765/(201)962-9999/" friends
Bob Beamon 913 Mockingbird Lane Annapolis MD 17701 (201)962-9999
Kim Smith 234 Working Street Hollywood CA 18765 (678)987-9876
Eddy Murphy 210 W. Hollywood Los Angles CA 90210 (876)238-9987
%
The s (substitute) option tells sed to substitute. We have changed the phone number. If we wanted to save these changes we would redirect the output to a file.

The sed command also accepts regular expressions.

% sed '/^$/d' hello.cc
#include
main() {
cout << "Hello, cruel world! \n";
}
%
The d option is tells sed to delete. In this case we are using a regular expression to tell sed to remove all blank lines from our hello.cc file.

:: Sorting data in files

The sort command is used to sort the contents of a file into alphabetic or numerical order.

% sort +1 friends
Bob Beamon 913 Mockingbird Lane Annapolis MD 17701 (201)962-8765
Eddy Murphy 210 W. Hollywood Los Angles CA 90210 (876)238-9987
Kim Smith 234 Working Street Hollywood CA 18765 (678)987-9876
%
The +1 option tells sort to use the second field of the sort key rather than the beginning of the line. Fields are separated by whitespace, however you can use the -t option to separate by any character. The -n options tells sort to sort a numeric key, otherwise it will sort by the corresponding ASCii values.

Another command that is usefull when you are sorting is the uniq command. The uniq command will write only one instance of each line, whereas the sort will print every line. Usually the output of the sort command is piped to the uniq command.


::enjoy life...