old-www/LDP/LG/issue24/lg_tips24.html

882 lines
30 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>More 2 Cent Tips & Tricks Issue 24</title>
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>&quot;Linux Gazette...<I>making Linux just a little more fun!</I>
&quot;</H4>
<P> <hr> <P>
<!-- QUICK TIPS SECTION ==================================================
-->
<center>
<H1><A NAME="tips"><IMG ALIGN=MIDDLE ALT="" SRC="../gx/twocent.gif">
More 2&#162; Tips!</A></H1> <BR>
Send Linux Tips and Tricks to <A HREF="mailto:gazette@ssc.com">
gazette@ssc.com
</A></center>
<p><hr><p>
<H3>Contents:</H3>
<ul>
<li><a HREF="./lg_tips24.html#ps/vc">Followup to PostScript and VC Key
Sequences (LG#23)</a>
<li><a HREF="./lg_tips24.html#ps/fu">PostScript $0.02 follow-up</a>
<li><a HREF="./lg_tips24.html#cheap">Yet another cheap tip</a>
<li><a HREF="./lg_tips24.html#dose">2 cent tip - dosemu</a>
<li><a HREF="./lg_tips24.html#find1">Re: 2c Tip "Finding What You Want
with find"</a>
<li><a HREF="./lg_tips24.html#find2">Re: Finding What You Want with find</a>
<li><a HREF="./lg_tips24.html#find3">Finding What You Want with find Part
III</a>
<li><a HREF="./lg_tips24.html#find4">More on finding</a>
<li><a HREF="./lg_tips24.html#find5">Another way to find</a>
<li><a HREF="./lg_tips24.html#find6">Yet another way to find</a>
<li><a HREF="./lg_tips24.html#find7">A final(?) way to find</a>
<li><a HREF="./lg_tips24.html#mozilla">Re: I need some help</a>
<li><a HREF="./lg_tips24.html#spin">Spinning Down Unused HDs</a>
<li><a HREF="./lg_tips24.html#egg1">LG Tips and Tricks (Netscape)</a>
<li><a HREF="./lg_tips24.html#egg2">Easter Eggs in Netscape</a>
<li><a HREF="./lg_tips24.html#calc">Calculator Tip</a>
<li><a HREF="./lg_tips24.html#nohack">Security script</a>
<li><a HREF="./lg_tips24.html#cron">Controlling cron.hourly</a>
<li><a HREF="./lg_tips24.html#ping">Syslog and ping</a>
</ul>
<P> <hr> <P>
<!--================================================================-->
<a name="ps/vc"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Followup to PostScript and VC Key Sequences (LG#23)
</H3>
<p>
Date: Thu, 4 Dec 1997 16:43:47 +0000 (GMT)<br>
From: Ivan Griffin <a
href="mailto:ivan.griffin@ul.ie">ivan.griffin@ul.ie</a>
<p>
I just wanted to point out that some of my 2cent tips in Issue 23 of the
Linux Gazettte (December, 1997) were a little funky in their appearance.
<p>
While it doesn't really matter at all with the VC key sequences, it may
affect someone's understanding of the bad (imho) PostScript generated by
the Microsoft PS driver.
<p>
In this, the PostScript should have been pre-formatted using the
appropriate HTML tags. Basically, the line
<pre>
30000 VM?
</pre>
Is on its own, and not part of any other line.
All that you have to do to remove this artificial restriction on
viewing/converting the PostScript with ghostscript is to delete this line.
<p>
On another note, someone asked me where those key sequences come from.
If you check either keyboard.c or keyb_m68k.c, you will find an array of
function pointers called spec_fn_table[].
<p>
This array contains a list of functions to execute when certain key
combinations are received... The key combinations listed in the
2cent tips execute the functions show_state(), show_mem() and show_regs()
<p>
You will find the source for function show_state() in
/usr/src/linux/kernel/sched.c
<p>
show_mem() is in
/usr/src/linux/arch/i386/mm/init.c
<p>
and show_regs() is in
/usr/src/linux/arch/i386/kernel/process.c
<p>
Best Regards,<br>
Ivan.
<p>
<P> <hr> <P>
<!--================================================================-->
<a name="ps/fu"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
PostScript $0.02 follow-up
</H3>
<p>
Date: Wed, 3 Dec 1997 13:51:48 -0500 (EST)<br>
From: Kyle Ferrio <a href="mailto:kbf@phy.duke.edu">kbf@phy.duke.edu</a>
<p>
In the December issue of LG, Ivan Griffin suggests using pstops from the
psutils package to accomplish two-up printing, gives a helpful example for
A4 paper, and points out that the command line needs to be tweaked for US
letter. If you're using US letter paper, then psnup (also part of
psutils) already does the job nicely with no uncomfortable thinking. It
might even work for A4, but I haven't checked. The psutils are generally
very handy, so folks might want to have a look. An RPM is available in
/contrib at ftp.redhat.com, for instance. Be advised that there seem to
be at least two very distinct packages called psutils floating around
Net-space.
<P> <hr> <P>
<!--================================================================-->
<a name="cheap"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Yet another cheap tip.
</H3>
<p>
Date: Sun, 30 Nov 1997 03:48:40 -0800 (PST)<br>
From: Gary Johnson <a
href="mailto:gjohnson@season.com">gjohnson@season.com</a>
<p>
Sorry if it has been mentioned before, I thought I would throw
it in the Gazette pile just in case it hasn't . . .
<p>
Cat proof keyboard.
<p>
Switching to an unused virtual console is a quick way to blank
the screen and disable the keyboard. To make one available try
<pre>
setterm -clear > /dev/tty12
</pre>
on startup. ALT F12 flips to it, or ALT CTRL F12 from X.
Because there (probably) isn't a login running on that VC it
doesn't do much, which can be a feature. A smart cat may still
luck into a troublesome key sequence.
<P> <hr> <P>
<!--================================================================-->
<a name="dose"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
2 cent tip - dosemu
</H3>
<p>
Date: Fri, 5 Dec 1997 00:55:55 -0500<br>
From: Joey Hess <a href="mailto:joey@kitenet.net">joey@kitenet.net</a>
<p>
I occasionally use dosemu, mainly to run some games I can't live without,
but I hate seeing the C:\> prompt. So I thought it'd be nice if there were a
way to tell dosemu what dos command to run, and it would run that command on
bootup. Here's a perl script that does just that. Read the comments at the
top, they explain some changes you need to make on the dos side of this. The
basic idea is, make a ~/dos_do.bat file, that contains the command you want
to run, and use lredir to let dosemu see your home directory. Then run the
batch file.
<pre>
#!/usr/bin/perl
#
# This runs dosemu.
#
# Any parameters psecified after "--" will be passed in to dosemu to be
# run as dos commands.
#
# Setup: add to autoexec.emu:
# lredir.com h: linux\fs\${home}
# if exist h:\dos_do.bat call h:\dos_do.bat
#
# GPL Copyright 1996, 1997 Joey Hess
# Split params into dosemu parameters and dos commands.
while ($a=shift @ARGV) {
if ($a=~m/--/ ne undef) { last }
$dosemu_command_line.="$a ";
}
$dos_command_line=join(' ',@ARGV);
$dos_command_line=~s/;/\r\n/g;
open (OUT,">$ENV{HOME}/dos_do.bat") || exit print "$ENV{HOME}/dos_do.bat:
$!";
if ($dos_command_line) {
print OUT "$dos_command_line\r\n"; # note dos CR LF
print OUT "exitemu\r\n";
}
close OUT;
system "/usr/bin/dos $dosemu_command_line";
unlink "$ENV{HOME}/dos_do.bat";
</pre>
<P> <hr> <P>
<!--================================================================-->
<a name="find1"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Re: 2c Tip "Finding What You Want with find"
</H3>
<p>
Date: Wed, 03 Dec 1997 16:03:30 +0100<br>
From: Mike Neuhauser <a href="mailto:mike@gams.co.at">mike@gams.co.at</a>
<p>
Jon Rabone, jkr@camcon.co.uk, wrote in the December 97 issue of LG:
<p>
&gt; In the October 97 issue, Dave Nelson suggests using<br>
&gt;<code> find . -type f -exec grep "string" /dev/null {} \;</code><br>
&gt; to persuade grep to print the filenames that it finds the search<br>
&gt; expression in. This starts up a grep for each file, however. A<br>
&gt; shorter
and more efficient way of doing it uses backticks:<br>
&gt;<br>
&gt;<code> grep "string" `find . -type f`</code><br>
&gt;<br>
&gt; Note however, that if the find matches a large number of files you<br>
&gt; may
exceed a command line buffer in the shell and cause it to complain.
<p>
To avoid an overflow of the command line buffer use:
<pre>
find . -type f | xargs grep "string"
</pre>
This may give problems if filenames contain white space (e.g. touch
"test file") -- to avoid use:
<pre>
find . -type f -print0 | xargs -0 grep "string"
</pre>
Note also that find doesn't follow symbolic links to directories per
default. Using find with the option -follow does the trick (find .
-follow ...).
<P> <hr> <P>
<!--================================================================-->
<a name="find2"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Re: Finding What You Want with find
</H3>
<p>
Date: 5 Dec 1997 17:47:50 -0000<br>
From: Dale K. Hawkins <a
href="mailto:dhawkins@mines.edu">dhawkins@mines.edu</a>
<p>
<code> find . -type f -exec grep "string" /dev/null {} \;</code>
<p>
That is how I used to run things too, but a friend showed me the xargs
program. Very nice. So one could turn the above statement to
something like:
<pre>
find . -type f | xargs fgrep "string" /dev/null
</pre>
Again, the /dev/null will force the name of the file to be printed (in
the unlikely case that find only found one file name). This has the
benefit of not invoking a new grep process each time.
<p>
But for a really slick (and much faster search) try this:
<pre>
locate $PWD | grep "^$PWD" |xargs fgrep "string" /dev/null
</pre>
This assumes that your locate database is current for the directory to
be searched. It does have a problem though: it tries to grep
everything, including directories!
<pre>
locate $PWD | grep "^$PWD" |xargs -ifilename sh -c \
"if [ -f filename ]; then echo filename; fi " | \
xargs fgrep "string" /dev/null
</pre>
And as an exercise for the reader: Take a look at lesspipe.sh (if it is
installed; download it
otherwise!)
See if you can create a shell script called supercat (or something)
which preprocesses the input to prevent grep'ing binary files, etc.
<p>
You gotta love UNIX and especially Linux!
<p>
-Dale K. Hawkins
<P> <hr> <P>
<!--================================================================-->
<a name="find3"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Finding What You Want with find Part III
</H3>
<p>
Date: Thu, 11 Dec 1997 17:12:46 +0100 (MET)<br>
From: Axel Dietrich <a
href="mailto:Axel.Dietrich@neuroinformatik.ruhr-uni-bochum.de">Axel.Dietrich@neuroinformatik.ruhr-uni-bochum.de</a>
<p>
&gt;In the October 97 issue, Dave Nelson suggests using<br>
&gt;<br>
&gt;<code> find . -type f -exec grep "string" /dev/null {} \;</code><br>
&gt;<br>
&gt;to persuade grep to print the filenames that it finds the search<br>
&gt;expression in.
<p>
Besides Jon Rabone's "shorter and more efficient" version in the
December 97 issue using backticks:
<pre>
grep "string" `find . -type f`
</pre>
the following variant can be used without the danger of exceeding
a command line buffer limit:
<pre>
find . -type f -exec grep -l "string" {} \;
</pre>
The "-l" switch tells grep to show the name of the file in which
"string" was found.
<p>
To limit such a search on selected files I use a combination of
the -type and -name switches.
<pre>
find . \( -type f -name "*\.html" \) -exec grep -l "string" {} \;
</pre>
This searches in all files with the suffix "html" for the string
"string" and outputs the name(s) of the file(s) in which "string"
was found.
<p>
Axel
<P> <hr> <P>
<!--================================================================-->
<a name="find4"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
More on finding
</H3>
<p>
Date: Tue, 16 Dec 1997 14:12:57 +0100 (MET)<br>
From: Alexander Larsson <a
href="mailto:alla@lysator.liu.se">alla@lysator.liu.se</a>
<p>
In the December 97 issue Jon Rabone wrote:
<p>
------------------------------------<br>
This starts up a grep for each file, however. A shorter and
more efficient way of doing it uses backticks:
<pre>
grep "string" `find . -type f`
</pre>
Note however, that if the find matches a large number of files you may
exceed a command line buffer in the shell and cause it to complain.<br>
------------------------------------
<p>
A better way would be to use:
<pre>
find . -type f | xargs grep "string"
</pre>
which starts up a new grep everytime the command line buffer is full.
<p>
/ Alex
<P> <hr> <P>
<!--================================================================-->
<a name="find5"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Another way to find
</H3>
<p>
Date: Sat, 27 Dec 1997 12:06:47 -0500<br>
From: <a href="mailto:rchandra@letter.com">rchandra@letter.com</a>
<p>
In an article in the LG, it was suggested that, in order to cut down
on having to fork(2)/exec(2) for each grep when you're searching
through a tree of files, you use the shell's capability of command
substitution (for the file names paramaters to the grep command) with
"backquotes," "grave accents," "backticks," etc. as they are commonly
called ("`"). In that little tidbit, it is noted that it has the
limitation of the system-wide imposed limit on number of arguments,
and I possibly think there might be a length issue as well (too many
total bytes). Enter xargs(1).
<p>
The job of the xargs command is to read its stdin and use the
resultant strings as arguments to some command prefix (such as "grep
-n somestring"), much like backquotes work. However, the xargs
program is "aware of" the limitations imposed by the system, and will
run the command prefix as many times as necessary to exhaust the list
provided on stdin, while on each run giving the command only the
maximum number of arguments and the maximum byte count (?) that an
exec(2) call can handle. Thus, provided that the program named in the
command prefix follows the UNIX program protocol of iterating over its
non-option arguments, one can search one, hundreds, thousands, even
millions of files with a line like:
<pre>
find / -type f -print | xargs grep -n 'where is that string?'
</pre>
As usual, consult your favorite source of documentation, such as your
local man pages, for ways to get even craftier with xargs.
<P> <hr> <P>
<!--================================================================-->
<a name="find6"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Yet another way to find
</H3>
<p>
Date: Mon, 29 Dec 1997 10:49:52 +0100<br>
From: Guido Socher <a
href="mailto:eedgus@aken104.eed.ericsson.se">eedgus@aken104.eed.ericsson.se</a>
<p>
In recent Linux Gazette issues there were a couple of ideas on how
to recursively grep around files and directories. Very useful, but it can
cause problems when you have binaries (e.g some executable) in the
directories that contain somewhere the string that you are looking
for.
The result is most of the time an unusable terminal because some control
character from the binary file has set it to graphics mode.
There are, of course, ways to make the terminal readable again but
the best is to avoid it in the first place.
<p>
Let's just remove the unprintable characters. They are unreadable anyway!
The command
<pre> sed -e 's/[^ -~][^ -~]*/ /g'</pre>
removes multiple occurrences of non printable/control characters and
replaces them by a single space. The [^ -~] matches all characters not
in the ASCII range from SPACE to Tilde.
This command can be easily combined (using a pipe) with the find and grep.
Here is a little script, I called it grepfind, that does it all:
<pre>
#!/bin/sh
#save this in a file called grepfind and do a "chmod 755 grepfind"
#
if test $# = 0 -o "$1" = "-h" -o "$1" = "--help" ; then
echo ' grepfind -- recursively descends directories and egrep all files '
echo ''
echo ' Usage: grepfind [--help][-h][start_directory] egrep_search_pattern'
echo ''
echo ' The current directory is used as start_directory if parameter'
echo ' start_directory is omitted. The search is case insensitive.'
echo ' Multiple occurrences of control characters are replaced by a single'
echo ' space. This makes it possible to grep around in files that contain'
echo ' binary data and strings without setting the terminal accidently '
echo ' to graphics mode.'
echo ''
echo ' Example: grepfind /home "hello world" '
else
if [ "$2" = "" ]; then
find . -type f -exec egrep -i "$1" /dev/null {} \; | sed -e 's/[^ -~][^
-~]*/ /g'
else
if [ -d "$1" ];then
find $1 -type f -exec egrep -i "$2" /dev/null {} \; | sed -e 's/[^
-~][^ -~]*/ /g'
else
echo "ERROR: $1 is not a directory"
fi
fi
fi
#__END__OF_grepfind
</pre>
<P> <hr> <P>
<!--================================================================-->
<a name="find7"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
A final(?) way to find
</H3>
<p>
Date: Wed, 31 Dec 1997 14:31:57 PST<br>
From: Marty Leisner <a
href="mailto:leisner@sdsp.mc.xerox.com">leisner@sdsp.mc.xerox.com</a>
<p>
In the last few months, there's been a few letters (by Dave Nelson,
Jon Rabone, some more) on how to grep with file names.
<p>
Instead of using the trick:
<pre>
find . type f -exec grep "string" /dev/null {} \;
</pre>
and other variatiants, or doing
<pre>
grep "string" $(find . -type f)
</pre>
1) use the -H option of grep 2.1 (to print file names, not in 2.0)<br>
2) use xargs to overcome problems with buffer size
<pre>
find . -type f | xargs grep &lt;pattern&gt; -H
</pre>
Marty
<P> <hr> <P>
<!--================================================================-->
<a name="mozilla"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Re: I need some help
</H3>
<p>
Date: Sun, 7 Dec 1997 14:25:25 +0100 (MET)<br>
From: Roland Smith <a href="mailto:rsmit06@ibm.net">rsmit06@ibm.net</a>
<p>
Javier,
<p>
In response to your article in the mailbag of the dec. 97 Linux Gazette:
<p>
You need to set the environment variable MOZILLA to the directory
containing Netscape's files.
<p>
There are two ways of doing this:
You can type `export MOZILLA_HOME=/usr/local/netscape' every time you
start your computer, or you can edit /etc/profile. This is a
file read by the bash shell. Add the following to this file
(assuming the Netscape stuff is in /usr/local/netscape):
<pre>
MOZILLA_HOME="/usr/local/netscape"
export MOZILLA_HOME
</pre>
You also need to add an entry for Netscape to your window-manager's
initialization file, so it shows on the toolbar and/or menu. How to do
this depends on the window manager you use.
<p>
If you're using fvwm2-95, add the following to the .fvwm2rc95 file in your
home directory:
<pre>
# add to this menu:
AddToMenu "Utilities" "Utilities" Title
+ "Netscape%mini-nscape.xpm%" Exec netscape -geometry 931x683+54+9 &
</pre>
Regards, Roland
<P> <hr> <P>
<!--================================================================-->
<a name="spin"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Spinning Down Unused HDs
</H3>
<p>
Date: Mon, 08 Dec 1997 14:21:31 -0500<br>
From: Peter S Galbraith <a
href="mailto:galbraith@mixing.qc.dfo.ca">galbraith@mixing.qc.dfo.ca</a>
<p>
In the December issue of LG tips, you discuss the hdparm command to spin
down disks. I tried this on my old SCSI disk:
<pre>
bash-2.01# hdparm -S6 /dev/sdb
/dev/sdb:
operation not supported on SCSI disks
</pre>
Too bad!
I use the `scsi-idle' kernel patch to do this very same thing on SCSI,
and I was eager to try your trick to finally stop having to patch the
kernel at evey upgrade.
<p>
Too bad it don't seem to work on SCSI disks (it's also strange that the man
page doesn't say this...)
<P> <hr> <P>
<!--================================================================-->
<a name="egg1"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
LG Tips and Tricks (Netscape)
</H3>
<p>
Date: Fri, 12 Dec 1997 02:56:16 -0600<br>
From: Christian J Carlson <a
href="mailto:ccarlson@means.net">carlson@means.net</a>
<p>
* Date: Sun, 9 Nov 1997 22:00:31 +0000 (GMT)<br>
* From: Ivan Griffin ivan.griffin@ul.ie<br>
*<br>
* These special URLs do interesting things in Netscape Navigator and
Communicator.<br>
*<br>
* about:cache gives details on your cache<br>
* about:global gives details about global history<br>
* about:memory-cache<br>
* about:image-cache<br>
* about:document<br>
* about:hype<br>
* about:plugins<br>
* about:editfilenew<br>
*<br>
* view-source:URL opens source window of the URL<br>
*<br>
* Ctrl-Alt-F take you to an interesting site :-)<br>
<p>
This appeared in Linux Gazette, December 1997.
There is one more way cool easter egg that's in Netscape.
<p>
First, type "about:mozilla" to get the Mozilla easter egg. Then,
watch your "N" in the upper right hand corner of Netscape. Whenever
you access a website, Mozilla himself will appear instead of the
boring flying stars, etc. As far as I know, this has been in every
version of Netscape since at least version 2.0.
Of course, this only works in the Linux version (I don't know about
other *nix versions) of Netscape, NOT Windows95 :).
<p>
Christian J. Carlson
<P> <hr> <P>
<!--================================================================-->
<a name="egg2"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Easter Eggs in Netscape
</H3>
<p>
Date: Tue, 30 Dec 1997 0:47:12 +1100 (EADT)<br>
From: Michael Lake <a
href="mailto:mikel@BlueSky.com.au">mikel@BlueSky.com.au</a>
<p>
I have just been reading the Linux gazette Issue 23 about the
easter eggs in Netscape and thought that I would try some URL's
of my own. I am using Netscape 3.01 for Linux. A little
experimentation found the following--
<p>
about:foo
<p>
The message that is returned is: Whatchew talkin' 'bout, Willis?
Instead of foo you can use anything that is not understandable to Netscape.
<p>
A more interesting one that I tried is--
<p>
about:mozilla
<p>
This gives a very interesting quotation which I will leave to the reader
to discover.
<p>
Enjoying the Linux Gazette immensely,
<p>
Best Regards,<br>
Michael Lake<br>
Sydney, Australia
<P> <hr> <P>
<!--================================================================-->
<a name="calc"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Calculator Tip
</H3>
<p>
Date: Sun, 14 Dec 1997 19:23:55 -0500<br>
From: Michael McLay <a href="mailto:mclay@nist.gov">mclay@nist.gov</a>
<p>
The Issue #21 and #23 tips column gave tips for doing calculations
without having to fire up a heavyweight GUI calculator. It is very
handy to be able to do all the number entry through the command line,
but I was surprised to see perl and awk used in the two examples. The
bc has been around forever in Unix and would be the logical first
choice to many oldtimers. And bc can do the calculations to any
precision desired if that is important.
<p>
Another good option is Python. Python can be run in an interactive
mode like bc, so previous calculations can saved as variables and
reused. Python also can be built so that past lines can be edited
using the standard GNU readline library editing operations. For
instance, in the following interactive sequence the previous-line key
will restore the last executed line to the prompt and the line edit
keys, such as backward-char and delete can then be used to edit the
line.
<pre>
~: python
Python 1.5b2 (#2, Dec 12 1997, 16:13:12) [GCC 2.7.2] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
&gt;&gt;&gt; a = (10+3)/7
&gt;&gt;&gt; a
1
&gt;&gt;&gt; a = (10.+3)/7
&gt;&gt;&gt; a
1.85714285714
&gt;&gt;&gt; a/32
0.0580357142857
&gt;&gt;&gt; "it takes %7.2f percent" % a
'it takes 1.86 percent'
&gt;&gt;&gt; "it takes %-7.2f percent" % a
'it takes 1.86 percent'
&gt;&gt;&gt; from Numeric import *
&gt;&gt;&gt; b = array(arange(12))
&gt;&gt;&gt; b.shape = 3,4
&gt;&gt;&gt; b
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
&gt;&gt;&gt; b/a
array([[ 0. , 0.53846154, 1.07692308, 1.61538462],
[ 2.15384615, 2.69230769, 3.23076923, 3.76923077],
[ 4.30769231, 4.84615385, 5.38461538, 5.92307692]])
&gt;&gt;&gt;
</pre>
This example also shows the Python Numeric[1] module being used at the
command line. Any Python module that is installed with the
interpreter can be imported and used in the interactive mode.
<p>
Of course if you want to make Python do a one-liner from the command
line that is possible also:
<pre>
~: python -c "print 34./33"
1.0303030303
</pre>
or to format the output:
<pre>
~: python -c "print 'eat %3.4f %s' % (1.444e5/32,'more fish')"
eat 4512.5000 more fish
</pre>
[1] The Numeric module in this example is not built into the standard
distribution. See the matrix-sig page for details on how to add it to
the module library if you can't find it on your system.
<P> <hr> <P>
<!--================================================================-->
<a name="nohack"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Security script
</H3>
<p>
Date: Mon, 15 Dec 1997 20:49:53 -0600 (CST)<br>
From: Corey G <a
href="mailto:cgaff@interaccess.com">cgaff@interaccess.com</a>
<p>
Often when I leave my machine connected to the Internet for prolonged
periods I worry about hackers. I wanted a program that would know if
a process was started by anyone, including root, that was not originally
on the machine.
<p>
This caused me to program this script. I dont know if something similar
exists but I have tested this very throughly and it works rather well. It
can be frustrating at times when you are active on the machine but works
very well for idle times.
<p>
HOW IT WORKS:
<p>
This scripts grabs all the processes when first invoked and saves them to
a temporary file. After a default of 10 seconds the process table is
checked against any new processes that were started. If these processes
were not listed in the "TRUSTED_ITEMS" variable they will be killed
immediately.
<p>
USAGE:
<p>
Once you have all the necessary processes running on your machine start
the script as root. It will make the necessary directories on the machine
in a safer place than just /tmp. I have created two variables named
"TRUSTED_ITEMS" and "TRUSTED_USERS". These can be used to ignore some
users or programs that you never want killed. Be careful since sometimes
you will need to include more than one item for some programs. For
example, if you dont want xterms killed you must add "xterm" and "bash" if
you are running bash as your default shell.
<p>
Note: When testing this script make certain that nothing important is
running. I take no blame for any wrong doing from this script.
<p>
To start the script:<code> nohup ./secmach &</code>
<p>
I am always looking for ways to improve this script so feel free to e-mail
your comments or suggestions to me.
<p>
Good Luck !!!
<pre>
#!/bin/sh
# Secmach - security program
# v1.0 12-14-97
# By: Corey Gaffney
export PATH=/usr/bin:/bin:/sbin
COUNTER=0
LOCATION=/usr/secmach
CHECK_TIME=10
TRUSTED=/usr/secmach/trusted
UNTRUSTED=/usr/secmach/untrusted
DIFFKILL=/usr/secmach/diffkill
TRUSTED_USERS="johndoe"
TRUSTED_ITEMS="$TRUSTED_USERS|pppd|chat|netscape|xterm|egrep|ps|sed|secmach|awk"
if [ ! -s $LOCATION ]
then
mkdir $LOCATION
chmod 700 $LOCATION
fi
while :
do
COUNTER=`expr $COUNTER + 1`
if [ $COUNTER -eq 1 ]
then
ps -aux | sed -e '1d' | awk '{print $2}' > $TRUSTED
fi
sleep $CHECK_TIME
ps -aux | sed -e '1d' | egrep -v $TRUSTED_ITEMS | awk '{print $2}' >
$UNTRUSTED
diff $TRUSTED $UNTRUSTED > $DIFFKILL
KILL=`grep ">" $DIFFKILL | awk '{print $2}'`
kill -9 $KILL
done
</pre>
<P> <hr> <P>
<!--================================================================-->
<a name="cron"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Controlling cron.hourly
</H3>
<p>
Date: Sun, 21 Dec 1997 10:36:16 -0500 (EST)<br>
From: Jeff Johnson <a href="mailto:jbj@JBJ.ORG">jbj@JBJ.ORG</a>
<p>
According to Gary Turkington:<br>
&gt; I know this one of those *really* simple ones, but it's beating me. How<br>
&gt; do I stop the cron.hourly setup mailing a 'fortune' to root? This used<br>
&gt; to happen daily, no biggie, but when I upgraded to 5.0, its hourly.. spam<br>
&gt; :)
<p>
This is a variant of the "not a typewriter" error that causes loss of
hair when using rlogin :-)
<p>
The analysis goes like this:
<p>
1) Cron runs a job an hourly job as root.<br>
2) To run the job, a non-interactive (i.e. stdin/stdout are *not* connected<br>
to a tty but to cron) shell is started.<br>
3) The shell reads its init files: /etc/profile, ~/.bashrc, whatever.<br>
4) The init files execute fortune.<br>
5) The job is performed.<br>
6) Cron detects output, so it mails it to root.
<p>
Fix by identifying which shell init file is executing fortune and
avoiding fortune when not interactive. There are a couple of
techniques for doing this, often by checking whether PS1 is
set.
<p>
73 de Jeff
<P> <hr> <P>
<!--================================================================-->
<a name="ping"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Syslog and ping
</H3>
<p>
Date: Tue, 30 Dec 1997 17:58:59 -0500 (EST)<BR>
From: Andrew Tucker <a href="mailto:andrew.tucker@kplus2.aces.k12.ct.us">andrew.tucker@kplus2.aces.k12.ct.us</a>
<P>
Hi, this is a small hack I did to allow logging of users's use of ping
through syslog. With more and more larger systems running Linux, and more
and more situations of ICMP abuse, any shortcut a system administrator can
use to prevent such abuse is helpful. Click <A HREF="./syslog-ping.tar.gz">
here</A> to dowload the scripts.
<P>
-- Andrew
<P> <hr> <P>
<!--================================================================-->
<center>Published in Linux Gazette Issue 24, January 1998</center>
<P> <hr> <P>
<!--================================================================-->
<A HREF="./index.html"><IMG SRC="../gx/indexnew.gif" ALT="[ TABLE OF
CONTENTS ]"></A> <A HREF="../index.html"><IMG SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A> <A HREF="./lg_mail24.html"><IMG
SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./lg_bytes24.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<h5>This page maintained by the Editor of <I>Linux Gazette</I>,
<A HREF="mailto: gazette@ssc.com">gazette@ssc.com</A><BR>
Copyright &copy; 1998 Specialized Systems Consultants, Inc. </H5>
<P>
<!--startcut ==========================================================-->
</body>
</html>
<!--endcut ============================================================-->