Re: logging with iptables

2024-09-20 Thread Karl Vogel
>> On Thu, 19 Sep 2024, fxkl4...@protonmail.com wrote:
> in my iptables i havetcp LOG flags 0 level 4 prefix "REJECT: "
> this does what i want but how to direct the logging
> it gets written to multiple file in /var/log
> syslog, messages, kern, debug
> can i restrict this to a single file

  You might have better luck if you used rsyslog.  I've appended the
  rsyslog.conf file I used on my last Linux box.  Features:

  * I still use the short date format in typical syslog files -- I don't
need the full year because each logfile is linked to a dated version in
a subdirectory.  This also makes log rotation vastly simpler.  See the
"TEMPLATES" section:

/var/log/cron -> /var/log//MMDD/cron
etc.

  * You can weed out crap messages that fill up logs.  See the "FILTERS"
section for more.

  * The first entry in the "RULES" section shows how to put iptables
stuff in its own "firewall" log.

-- 
Karl Vogel  I don't speak for anyone but myself

Photographing a volcano is just about the most miserable thing you can do.
--Robert B. Goodman, who has clearly never tried to use a PDP-10

# -
# rsyslog v5 configuration file
#
# $Revision: 1.4 $ $Date: 2020-08-31 01:07:59-04 $
# $Source: /doc/sitelog/linuxwks/vcs/etc/rsyslog.conf,v $
# $Host: linuxwks $
# $UUID: 0aac27dd-1bdd-3c91-92e8-857140e878db $
#
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# Problems?  http://www.rsyslog.com/doc/troubleshoot.html

 MODULES =

# provides support for local system logging (e.g. via logger command)
$ModLoad imuxsock

# provides kernel logging support (previously done by rklogd)
$ModLoad imklog

# provides --MARK-- message capability
#$ModLoad immark

# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514

# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
#
 GLOBAL DIRECTIVES ===

# Use short timestamp format
## $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$ActionFileDefaultTemplate ShortForm

# Use high-precision timestamps and timezone information.
## $ActionFileDefaultTemplate RSYSLOG_FileFormat

# File syncing capability is disabled by default.  This feature is
# usually not required, not useful and an extreme performance hit
## $ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

 TEMPLATES ===

$template DYNauth,"/var/log/%$YEAR%/%$MONTH%%$DAY%/secure"
$template DYNcron,"/var/log/%$YEAR%/%$MONTH%%$DAY%/cron"
$template DYNfirewall,"/var/log/%$YEAR%/%$MONTH%%$DAY%/firewall"
$template DYNkern,"/var/log/%$YEAR%/%$MONTH%%$DAY%/kernlog"
$template DYNmail,"/var/log/%$YEAR%/%$MONTH%%$DAY%/maillog"
$template DYNmessages,"/var/log/%$YEAR%/%$MONTH%%$DAY%/messages"

# This is identical to traditional format, without the hostname.
$template ShortForm,"%timegenerated% %syslogtag%%msg%\n"

 FILTERS =

# This apparently comes from Radeon fence code in the kernel: ignore.
#:msg, contains, " armed on ring " ~
#:msg, contains, " signaled from irq context" ~
#:msg, contains, " pending" ~
#:msg, contains, "alloc_contig_range:" ~

 RULES ===

# Log iptables drops to firewall log using discard action.
if \
$syslogfacility-text == 'kern' \
and $msg contains 'Denied' \
then?DYNfirewall
& ~
kern.*  ?DYNkern

# 
# Log all the mail messages in one place.  Postfix stuff must be ID'd
# by looking at the message contents; this has to come before general
# processing so we can discard the message, or postfix entries are
# also logged to "messages".
if \
$msg contains 'postfix/' \
or \
$syslogfacility-text == 'mail' \
then?DYNmail
& ~

# 
# Log anything of level info or higher.
# Don't log private authentication messages!
## authpriv.none;auth.none;kern.none;cron.none;local5.none;*.info
## /var/log/messages

if \
$syslogseverity <= '6' \
and ( \
$syslogfacility-text != 'auth' \
and \
$syslogfacility-text != 'authpriv' \
and \
$syslogfacility-text != 'cron' \
and \
$syslogfacility-text != 'kern' \
and \
$syslogfacility-text !=

Re: BASH reference for those who are "learning by doing"?

2024-09-09 Thread Karl Vogel
On Mon 09 Sep 2024 at 04:47:20 (-0400), Anssi Saari wrote:
> debian-u...@howorth.org.uk writes:
> 
> > As a mere bifocal (well vari-focal) wearer can I suggest a different
> > approach. Stop wearing tri-focals or any other variable focus specs for
> > reading a computer screen. Tell them to get a [very cheap] pair of
> > single focus reading glasses made to suit the distance their screen is
> > away.
> 
> I don't agree at all. I've used fixed focus glasses before but I find
> close range varifocals a huge upgrade. They're extremely useful for
> monitor work *and also* I can see and read things around me that fall
> outside the extremely narrow focus range of single focus reading
> glasses. I wonder if fixed focus even works for modern large two or
> three monitor setups? I suppose it's fine for a single small screen.

Have you tried some different fonts?  My eyesight is poor, and a good
font made all the difference.

https://bezoar.org/posts/2023/0214/font-screenshots/

-- 
Karl Vogel  I don't speak for anyone but myself

Debugging: when you're the detective, the victim, and the criminal.
--seen on Reddit, 11 Jul 2024



Re: bash history

2024-08-01 Thread Karl Vogel
This is how I keep a long-term record of bash commands from different
sessions:
https://www.reddit.com/r/bash/comments/ak9c3r/

HTH

-- 
Karl Vogel  I don't speak for anyone but myself

Comment: I use a screwdriver a lot
Reply:   I'm all out of orange juice.  Will straight vodka work?
--Reddit "What tool helped you as an early sysadmin?"



Re: Markup in mail messages

2024-05-16 Thread Karl Vogel
>> On Thu, May 16, 2024 at 09:48:23AM -0400, to...@tuxteam.de wrote:

> Actually I've been tempted to teach my mail reader to transform HTML
> into some lightweight markup (yeah, you need a bit of heuristics for
> that ;-) -- say Org, but why not its poor sister Markdown.

  https://github.com/aaronsw/html2text/ might interest you.  It converts
  (relatively) sane HTML into Markdown.

  I put html2text.py into $HOME/lib and use this to call it:

#!/bin/sh
#

Re: Zutty fonts - zutty always uses the same font and fontsize

2024-05-01 Thread Karl Vogel
On Wed, May 01, 2024 at 08:32:31AM -0400, Sirius wrote:
> If Debian still packages it, look for rxvt instead, or use xterm. Both
> are well tried and well tested for when you want something.. dated. ;)

  I resemble that remark.  Xterm v390 was released on 19 Feb 2024, and
  building it from source is easy.

  https://invisible-island.net/archives/xterm/xterm-390.tgz{,.asc}

-- 
Karl Vogel  I don't speak for anyone but myself

My mind is like my browser: 19 open tabs, three of them are frozen, and
I have no clue where the music is coming from.



Re: Changing The PSI Definition

2024-01-27 Thread Karl Vogel
>> On Fri, Jan 26, 2024 at 07:42:30AM -0500, Dan Ritter wrote:

> Might be time for a new font. I like Inconsolata, but l1I!
> should never look similar, nor O0@ or S$. 

  My eyesight sucks like a black hole with daddy issues, so I like fonts
  that are a bit larger than most.  My favorites on xterm:

  * xft:Menlo-Regular:pixelsize=20:bold
  * xft:Bitstream Vera Sans Mono:pixelsize=21:bold
  * xft:Cascadia:pixelsize=22:bold
  * xft:FiraMono-Regular:pixelsize=22

  Your examples above are very readable with Menlo.  These aren't bad:

  * xft:Edlo:pixelsize=21:bold
  * xft:Inconsolata-Bold:pixelsize=25:bold
  * xft:Meslo LG S:pixelsize=20:bold
  * xft:Meslo LG S:pixelsize=21:bold
  * xft:UbuntuMono-B:pixelsize=25:bold

  I run two xterms side-by-side on a 23-inch monitor:

/usr/local/bin/xterm -geometry 80x40-0+0 -j -b 10 -sb \
  -si -sk -ls -u8 -sl 4000 -cr blue -bd black -bg white \
  -fa xft:Menlo-Regular:pixelsize=20:bold -title Remote

  For browsing (Firefox), my "prefs.js" file holds:

user_pref("browser.display.use_document_fonts", 0);
user_pref("font.default.x-western", "sans-serif");
user_pref("font.internaluseonly.changed", false);
user_pref("font.minimum-size.x-western", 18);
user_pref("font.name.monospace.x-western", "DejaVu Sans");
user_pref("font.name.sans-serif.x-western", "sans-serif");
user_pref("font.name.serif.x-western", "DejaVu Serif");
user_pref("font.size.fixed.x-western", 18);
user_pref("font.size.variable.x-western", 18);

-- 
Karl Vogel  I don't speak for anyone but myself

Slogan of 105.9, the classic rock radio station in Chicago:
"Of all the radio stations in Chicago...we're one of them."



Re: smartctl cannot access my storage, need syntax help

2024-01-24 Thread Karl Vogel
On Tue, Jan 23, 2024 at 06:05:29AM -0500, gene heskett wrote:
> On 1/23/24 00:30, Karl Vogel wrote:
> >>> On 1/22/24 11:31, gene heskett wrote:
> >
> > G> How does an 8T backup server sound for another $200 in hdwe?  Very
> > G> enticing and I do have the sheckel's.
> >
> > https://www.amazon.com/dp/B07CQJBSQL
> > Seagate Desktop 8TB external Hard Drive, 3.5 Inch, USB 3.0 STGY8000400
> > $168.18
> >
> > What if you buy two, use one for a complete backup and the other for
> > incrementals or differentials?  (I know, more than $200...)
> 
> My disastrous experience with the last pair of seagates preclude exploring
> that path, ever again.

Sorry, the Seagate was just an example -- I prefer Western Digital myself.
My only point was using one or two external drives for backups.

-- 
Karl Vogel  I don't speak for anyone but myself

And as we all know from experiments conducted during the Korean War, Diane,
sleep deprivation is a one-way ticket to temporary psychosis.
--FBI Special Agent Dale Cooper, "Twin Peaks"



Re: smartctl cannot access my storage, need syntax help

2024-01-22 Thread Karl Vogel
>> On 1/22/24 11:31, gene heskett wrote:

G> How does an 8T backup server sound for another $200 in hdwe?  Very
G> enticing and I do have the sheckel's.

https://www.amazon.com/dp/B07CQJBSQL
Seagate Desktop 8TB external Hard Drive, 3.5 Inch, USB 3.0 STGY8000400
$168.18

What if you buy two, use one for a complete backup and the other for
incrementals or differentials?  (I know, more than $200...)

-- 
Karl Vogel  I don't speak for anyone but myself

I yam Popeye of Borg.  You will be askimilgrated.



Re: Isolated Web Co Session crash Firefox-ESR

2023-12-06 Thread Karl Vogel
On Wed, Dec 06, 2023 at 06:04:36AM +0100, to...@tuxteam.de wrote:
> On Wed, Dec 06, 2023 at 02:42:32AM +0800, jeremy ardley wrote:
> 
> > I have discovered a magic bullet for solving running out of memory
> >   sudo sync; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
> > Sadly it looks like I'll need to do this daily,
> 
> It's the browsers eating your memory. That's what they do.

  I've had problems with Firefox eating my swap on both Linux and FreeBSD.
  My fix has been to run the swap2ram script below hourly.

-- 
Karl Vogel  I don't speak for anyone but myself

Constipational carry.
  --NY Post 28 Nov "Suspect found hiding handgun in his rectum" comment #4

# --
#!/bin/ksh
# /dev/null
case "$?" in
0) ;;
*) die "You must be root to $action this." ;;
esac
}

# Make sure we have permission and a safe tempfile.
needroot
systype=$(uname -s | tr A-Z a-z)

tmp=$(mktemp -q "/tmp/$tag.XX")
case "$?" in
0)  test -f "$tmp" || die "$tmp: tempfile not created" ;;
*)  die "$tmp: mktemp failed" ;;
esac

# Real work starts here.  Check for OS-specific instructions.
case "$systype" in
freebsd)
( swapoff -a && swapon -a ) >> $tmp 2>&1
;;

linux)
mem=$(free  | awk '/Mem:/ {print $4}')
swap=$(free | awk '/Swap:/ {print $3}')

if test "$mem" -lt "$swap"; then
logmsg "not enough RAM to recover swap, nothing done"
else
( swapoff -a && swapon -a ) >> $tmp 2>&1
fi
;;
esac

# Cleanup.
test -s "$tmp" && logfile $tmp
rm $tmp
exit 0



Re: Work environment

2023-11-24 Thread Karl Vogel
On Fri, Nov 24, 2023 at 03:28:34AM -0500, Darac Marjal wrote:
> On 23/11/2023 04:34, William Torrez Corea wrote:
> > Why the people use two desktops and one laptop?

> Without any context, it's hard to answer.  But there are some possibilities:
> 
> * Regardless of any other factor, desktops are bigger than laptops, so
> there is room for more hard drives, optical drives, more PCI cards etc.

  It gives me a big monitor, a good mouse, and a keyboard that doesn't suck.

-- 
Karl Vogel  I don't speak for anyone but myself

Drunk Grizzlies Keep Getting Hit By Trains In Montana
  --"Cowboy State Daily" headline, 4 Nov 2023



Re: Too much log for sudo.

2023-10-12 Thread Karl Vogel
On Thu, Oct 12, 2023 at 11:22:00AM -0400, Erwan David wrote:
> I use a script to run borg backup. For it to be able to backup files that
> only root may read, i use sudo --preserv-env=BORG_REPO,BORG_PASSPHRASE.
> 
> However I see that in the logs the VALUE of the env variable is loggued. How
> to change this?

You can either run "sudo -E" to push the entire environment through without
echoing any values in the sudo log, or play some games by re-invoking the
script with a clean environment.  My environment with the BORG variables:

me% export BORG_REPO=/path/to/repo
me% export BORG_PASSPHRASE='horse battery'

me% env | sort
ATTRIBUTION=%f wrote:
BLOCKSIZE=1m
BORG_PASSPHRASE=horse battery
BORG_REPO=/path/to/repo
EDITOR=vim

[diaper-load of other variables]

XDG_CACHE_HOME=/home/vogelke/.cache
XDG_CONFIG_HOME=/home/vogelke/.config
XDG_DATA_HOME=/home/vogelke/.local/share
XDG_RUNTIME_DIR=/home/vogelke/.local/run
XDG_STATE_HOME=/home/vogelke/.local/state

Script to see if I'm running under a regular environment -- if so, restart
the same script with a bare minimum environment plus the BORG variables:

me% cat tst
#!/bin/bash
#

Re: Sunrise and Sunset from terminal

2023-09-29 Thread Karl Vogel
On Fri, Sep 29, 2023 at 12:48:56PM -0400, Bruno Kleinert wrote:
> Am Samstag, dem 23.09.2023 um 23:51 +0200 schrieb s...@gmx.com:
> > Is there a way to get sunrise and sunset time from command interpreter?
> > I want to use its output for a script!
> 
> in case you're looking for a possibility to execute commands at sunset
> and/or sunrise, I use remind for this (apt install remind) to trigger my
> roller blinds.  Pro: Does not rely on any external web service.

Remind is an incredibly useful program.  Give it your latitude and longitude,
and it can tell you sunrise and sunset times.  My coordinates:

  
https://www.google.com/search?q=dayton+ohio+latitude+longitude+degrees+minutes+seconds
  Dayton, OH, USA is located at GPS coordinates of
  39d 45m 32.2164s N and 84d 11m 29.7780s W.

Version of remind:

  me% remind -V 2>&1 | grep Copyright
  REMIND 04.02.04 (English version) Copyright 1992-2023 Dianne Skoll

Remind script:

  me% cat sunrise-sunset.rem
  ; Show sunrise/sunset
  SET $LatDeg  39
  SET $LatMin  45
  SET $LatSec  32
  SET $LongDeg 84
  SET $LongMin 11
  SET $LongSec 29
  MSG sunrise at [sunrise(trigdate())], sunset at [sunset(trigdate())]

Sunrise/sunset for today:

  me% remind -h sunrise-sunset.rem '*1' | sed -e '/^$/d'
  Reminders for Friday, 29th September, 2023 (today):
  sunrise at 07:30, sunset at 19:22

Sunrise/sunset for the next week:

  me% remind -h sunrise-sunset.rem '*7' | sed -e '/^$/d'
  Reminders for Friday, 29th September, 2023 (today):
  sunrise at 07:30, sunset at 19:22
  Reminders for Saturday, 30th September, 2023:
  sunrise at 07:31, sunset at 19:21
  Reminders for Sunday, 1st October, 2023:
  sunrise at 07:32, sunset at 19:19
  Reminders for Monday, 2nd October, 2023:
  sunrise at 07:33, sunset at 19:18
  Reminders for Tuesday, 3rd October, 2023:
  sunrise at 07:34, sunset at 19:15
  Reminders for Wednesday, 4th October, 2023:
  sunrise at 07:35, sunset at 19:15
  Reminders for Thursday, 5th October, 2023:
  sunrise at 07:36, sunset at 19:12

-- 
Karl Vogel  I don't speak for anyone but myself.

German: "Er hat da geparkt, wo ihm die Karre vom Arsch gefallen ist."
English: "He parked where the car fell off his ass."
--Reddit comment about stupid/illegal parking



Re: [a bit OT] Automate a (G o o g l e) search from a list of strings

2023-09-19 Thread Karl Vogel
On Tue, Sep 19, 2023 at 10:42:14AM -0400, steve wrote:
> I have a list of 200 keywords and would like for every one to launch a
> search on a specific website and put the result(s) in a file [...]

Take a list of words and turn it into a single Google query matching any
of them:

me% cat keywords
corsairs
buccaneers
privateers

Desired query:

https://www.google.com/search?q=corsairs+OR+buccaneers+OR+privateers

Script:

me% cat search
#!/bin/sh
export PATH=/usr/local/bin:/bin:/usr/bin
set -o nounset
umask 022

query=$(tr "[:space:]" "+" < keywords |
sed -e 's/ /+OR+/g' -e 's/+$//' -e 's/+/+OR+/g')

curl -s -L -o pirate.htm "https://www.google.com/search?q=${query}";
ls -l pirate.htm
exit 0

Results:

me% ./search
-rw-r--r-- 1 vogelke 220487 19-Sep-2023 21:33:21 pirate.htm

If you want results in text form, lots of programs can do that:

me% lynx -cookies -accept_all_cookies -dump -width 80 pirate.htm
Tampa Bay Buccaneers: Buccaneers Home
www.buccaneers.com
The official source of the latest Bucs headlines, news, videos, photos,
tickets, rosters, stats, schedule and gameday information.
  
People also ask
What is the difference between a pirate and a corsair?
What kind of pirate is a corsair?
What were Spanish pirates called?
What is the history of corsairs?

Pirates, Privateers, Corsairs, Buccaneers: What's the Difference?
www.britannica.com > Demystified > Geography & Travel
Corsairs were essentially privateers, although the term corsair carried
an added religious connotation because the conflict was between Muslim
and Christian...

HTH.

-- 
Karl Vogel  I don't speak for the USAF or my company

Leonardo diCaprio in Titanic: Despite acting like a plank of wood,
he still can't float.  --"Top Ten Most Welcome Movie Deaths", Stylus Magazine



Re: door bell like sound effect

2023-08-30 Thread Karl Vogel
On Wed, Aug 30, 2023 at 07:55:14AM -0400, songbird wrote:
> Karl Vogel wrote:
> ...
> > If nothing else, it's faster to run "locate" and look for file extensions;
> > running "file" on that much crap took nearly 9 hours.
> 
> do you have SSDs or spinning rust?

  I have a 256-Gb SSD and two mirrored Western Digital Blue 1.8-Tb drives.
  About 2 million files are on SSD and the rest are on rust.

  I used "file" v5.45 built from source, which does a nice job but is IO-
  and CPU-intensive.

> when i just did this:
> # find / -type f | wc -l
> it took all of 24 seconds for the 2.4 million files found.

  Generating hashes for SSD files is faster than getting the filetype;
  it takes about 17 minutes for 3.6 million files (153 Gbytes).  I like
  the Blake-2 hash cuz it's fast as hell, among other things:

#!/bin/ksh
#> $work
  done

# Store hashes for SSD datasets.
# The hash file is sorted by filename to make comparisons easier.

logmsg "running b2sum"
fdbdir=$(date '+/var/fdb/%Y/%m%d')
sort -z $work | xargs -0r b2sum -l 128 > "$fdbdir/zroot.sum"
rm $work
exit 0

  Useful for finding changed files -- security, backups, etc.

> what script did you use?

#!/bin/ksh
# $work
logmsg finish

mv $work filetypes
exit 0

-- 
Karl Vogel  I don't speak for the USAF or my company

Assisted in daily preparation of large quantities of consumable items
in a fast-paced setting.  (Translation: Short-order cook)
--from a list of resume' blunders



Re: door bell like sound effect

2023-08-30 Thread Karl Vogel
Out of morbid curiosity (and boredom), I started wondering what types of
audio files I had on my systems.  I ran "file --mime-type" on 6.8 million
files, looked for "audio/whatever" and got the file extensions.

Extension  MIME-type
---
.8svx  audio/x-aiff
.aif   audio/x-aiff
.aifc  audio/x-aiff
.aiff  audio/x-aiff
.ape   audio/x-ape
.arm   audio/amr
.auaudio/basic
.flac  audio/flac
.m4a   audio/x-m4a
.mp3   audio/mpeg
.mpc   audio/x-musepack
.oga   audio/ogg
.ogg   audio/ogg
.opus  audio/ogg
.raaudio/x-pn-realaudio
.voc   audio/x-unknown
.wav   audio/x-wav

If nothing else, it's faster to run "locate" and look for file extensions;
running "file" on that much crap took nearly 9 hours.

-- 
Karl Vogel  I don't speak for anyone but myself

My doctor told me to stop having intimate dinners for four,
unless there are three other people.--Orson Welles



Re: door bell like sound effect

2023-08-29 Thread Karl Vogel
On Tue, Aug 29, 2023 at 10:53:39PM -0400, gene heskett wrote:
> And that is the problem, and why I read thru all those man ages trying to
> find a way to make it log what it did. Sadly no.

  Install and configure file auditing on Debian:
https://www.daemon.be/maarten/auditd.html

  Auditing can help you find anything trying to write to your sound device.
  Look at these manpages:
auditd.conf (5)
audit.rules (7)
audispd (8)
ausearch (8)
aureport (8)
auditctl (8)
augenrules (8)

  To find your sound cards and/or devices:
https://wiki.debian.org/Sound
https://wiki.debian.org/SoundCard
https://wiki.debian.org/PulseAudio

  I don't have a Debian system to play with, but in the (good|bad) old
  days, we had a /devices directory with all sorts of weirdness inside.
  If you have one of those, try
find /devices -print | grep sound

  That might point you to an actual device name.

-- 
Karl Vogel  I don't speak for anyone but myself.

Comment: One of my friends drank half a bottle of rum and refilled it
 with a bodily fluid of similar color.
Reply:   Your friend should see a doctor and drink more water.
   --seen on Reddit, 27 Aug 2023



Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Karl Vogel
On Sat, Aug 26, 2023 at 12:09:57PM -0400, Tom Browder wrote:
> Excellent mind-reading, Greg! So to use your line I will put in that dir:
> "cd /required-dir || exit"
> 
> Thanks so much.  And thanks to all others who responded.

If you're running bash, the safest way to find your current working
directory is capturing the output from /bin/pwd.  Symlinked directories
can surprise you:

me$ cd

me$ ls -ldF today
lrwxr-xr-x  1 me mis   18 Aug 26 00:03 today@ -> notebook/2023/0826

me$ cd today

me$ pwd
/home/me/today

me$ /bin/pwd
/home/me/notebook/2023/0826

me$ echo $PWD
/home/me/today

If you want to know why you had an early exit:

me$ cat try
#!/usr/bin/env bash
# try: test logging.

export PATH=/usr/local/bin:/bin:/usr/bin
set -o nounset  # check for unbound variables.
tag=${0##*/}
umask 022

# Test file descriptor 2 for interactive or cron use.
test -t 2
case "$?" in
0) logmsg () { echo "$(date '+%F %T') $tag: $@"; } ;;
*) logmsg () { logger -t $tag "$@"; }  ;;
esac

warn () { logmsg "WARN: $@" ; }
die ()  { logmsg "FATAL: $@"; exit 1 ; }

# Real work starts here.
case "$#" in
0)  die "need a directory" ;;
*)  dir="$1" ;;
esac

test -d "$dir" || die "$dir: not a directory"
cd "$dir"  || die "$dir: cannot cd"
cwd=$(/bin/pwd)

logmsg "start working in $cwd"
exit 0

On FreeBSD, you can use "daemon" to run something detached from the
controlling terminal, which simulates running a cron job:

me$ ls -ldF /etc /var/authpf
drwxr-xr-x 27 root wheel  120 26-Aug-2023 07:55:02 /etc/
drwxrwx---  2 root authpf   2 05-Jul-2019 00:45:45 /var/authpf/

me$ ./try /etc
2023-08-26 18:31:54 try: start working in /etc

me$ daemon -f $PWD/try /etc
me$ daemon -f $PWD/try /var/authpf

me$ tail -2 /var/log/syslog
Aug 26 18:19:17 myhost try: start working in /etc
Aug 26 18:19:19 myhost try: FATAL: /var/authpf: cannot cd

Hope this helps.

--
Karl Vogel  I don't speak for anyone but myself.

Oh, my darlin' had bronchitis and she barfed up half a lung,
what came up looked quite amazing when she rolled it on her tongue.
   --sung to the tune of "My Darling Clementine"



Re: git setup

2023-08-21 Thread Karl Vogel
On Mon, Aug 21, 2023 at 11:01:21PM -0400, Russell L. Harris wrote:
> I write articles for publication.  I typically spend anywhere from
> several hours to many days on each article.  It is frustrating to work
> for an hour or two on a paragraph or a page and then accidentally to
> erase what I have written.

Heard that.

> The second repository is my backup; it resides on another machine.
> Several times a day, I SSH into the backup machine and pull the
> working repository.  It would be nice to be able to push from WORKING
> to BACKUP, eliminating the need to SSH.

I'd set up a post-commit hook on the production system.  Have it SSH to
your backup system and do a pull automatically whenever you commit a change.

I made an example project to try it:

me% mkdir example
me% cd example
me% git init

Test file:

me% date > testing
me% git add testing
me% git commit -m 'Testing a new file"

me% git log
d5fe2ce 2023-08-22 00:09:21 -0400 vogelke - Testing a new file

Here's a test script to connect from my backup system ("bkup") and simulate
pulling my working repo.  I have an SSH public/private key set up for
passwordless login:

me% cat try
#!/bin/sh
export PATH=/usr/local/bin:/bin:/usr/bin
ssh -q -c aes128-...@openssh.com -i $HOME/.ssh/bkup_ed25519 \
bkup "logger -t autopull git pull whatever"
exit 0

Here's the remote system log when I run this from the command line:

me@bkup% tail -1 /var/log/messages
Aug 22 00:24:44 bkup autopull[60592]: git pull whatever

I copied the test script ("try") to .git/hooks/post-commit and ran a commit:

me% git add try

me% date; git commit -m 'Added hook'
Tue Aug 22 00:31:27 EDT 2023
[master 42cb917] Added hook
 1 file changed, 6 insertions(+)
 create mode 100755 try

me% git log
42cb917 2023-08-22 00:31:27 -0400 vogelke - Added hook
d5fe2ce 2023-08-22 00:09:21 -0400 vogelke - Testing a new file

Here's the system log on the remote system showing my hook ran when the
commit was done:

me@bkup% tail -1 /var/log/messages
Aug 22 00:31:27 bkup autopull[80162]: git pull whatever

Replace the "logger ..." part of post-commit to run "git pull" or whatever.
Hope this helps.

-- 
Karl Vogel  I don't speak for the USAF or my company

There's no kill like overkill.
  --Reddit post about using .45 ACP rounds to dispose of old disk drives



Re: xterm font and other options

2023-08-21 Thread Karl Vogel
On Sun, Aug 20, 2023 at 10:38:34PM -0400, Max Nikulin wrote:
> On 20/08/2023 14:55, Karl Vogel wrote:
> >  #!/bin/sh
> ...
> >  #   -fa 'xft:...'   font size and weight
> ...
> >  ( $XTERM $geo $topts -fa "$FONT" -title "Remote" ) &
> 
> Xterm configuration options may be put to ~/.Xresources, e.g.
> 
> xterm*VT100.faceName: ...
> 
> I am curious if there are actual advantages of usage a wrapper script
> instead of xresources.

  For me, being able to select or change a font based on an environment
  variable is very convenient.

  The script I included is simplified because I didn't want the post to
  get too long.  My production version has other conveniences:

# Don't override COLUMNS and LINES if already set; when my eyes are
# tired, I use an xterm with characters two pixels larger:
##  FONT=xft:Cascadia:pixelsize=22:bold LINES=35 xt

: ${COLUMNS=80}
: ${LINES=40}

  I can check a font and set LINES, COLUMNS, or geometry on the fly without
  having to mess with any configuration options.

-- 
Karl Vogel  I don't speak for the USAF or my company

Tent poles are not for pole dancing.  Please find
alternative ways to disappoint your father.  --seen on boredpanda.com



Re: Looking for a good "default" font (small 'L' vs. capital 'i' problem)

2023-08-20 Thread Karl Vogel
On Sat, Aug 19, 2023 at 03:29:22PM -0400, Christoph K. wrote:
> 
> I'm unsatisfied with the default sans font in debian for use in the
> graphical user interface (in my case XFCE).

I use BSD and Linux, and my eyesight sucks.  For console work (23" monitor
that's about 2 feet away) I use an Xterm with one of the following fonts
(in order of preference):

* xft:Menlo-Regular:pixelsize=20:bold
* xft:Cascadia:pixelsize=22:bold
* xft:Bitstream Vera Sans Mono:pixelsize=21:bold

For browsing (Firefox), my "prefs.js" file holds:

user_pref("browser.display.use_document_fonts", 0);
user_pref("font.default.x-western", "sans-serif");
user_pref("font.internaluseonly.changed", false);
user_pref("font.minimum-size.x-western", 18);
user_pref("font.name.monospace.x-western", "DejaVu Sans");
user_pref("font.name.sans-serif.x-western", "sans-serif");
user_pref("font.name.serif.x-western", "DejaVu Serif");
user_pref("font.size.fixed.x-western", 18);
user_pref("font.size.variable.x-western", 18);

Others I've liked:

* xft:Edlo:pixelsize=21:bold
* xft:FiraMono-Regular:pixelsize=22:bold
* xft:Inconsolata-Bold:pixelsize=25:bold
* xft:Meslo LG S:pixelsize=20:bold
* xft:Meslo LG S:pixelsize=21:bold
* xft:UbuntuMono-B:pixelsize=25:bold

If you get your FONT setting from the environment, it's easy to experiment:

me% echo $FONT   
xft:Cascadia:pixelsize=20:bold

This script starts a new xterm with some tweaks to make it a little nicer:

#!/bin/sh
#https://invisible-island.net/archives/xterm/xterm-384.tgz
https://invisible-island.net/archives/xterm/xterm-384.tgz.asc

To build, unpack the source:

dest=/usr/local
export TERMINFO=/usr/local/share/terminfo

./configure  \
--disable-setgid \
--disable-setuid \
--enable-256-color   \
--enable-narrowproto \
--mandir=$dest/man   \
--with-x \
--with-own-terminfo=$TERMINFO
make
make check
make install

It comes with a nice terminfo file.  I've had problems with "tic" for
ncurses >= version 6, so I use the ncurses-5.9 version to compile it:

root# tic59 -V
ncurses 5.9.20110404

root# tic59 -s -o $TERMINFO terminfo

Hope this gives you some ideas.

-- 
Karl Vogel / vogelke AT pobox DOT com / I don't speak for anyone but myself

The Beatles: "I Get By with a Little Help From Depends"
--Re-released hits for an aging audience



Re: Recommendations for a UPS?

2023-08-01 Thread Karl Vogel
>> On Tue, 01 Aug 2023 03:47:28 -0400,
>> David  may have said:

> What everybody seems to be doing is catering to surge, when a low
> spike can do just as much damage.  Both need to be protected against,
> so any protective appliance selection has to consider that.

  Liebert protects against power surges, brownouts, blackouts or drops
  in voltage.  That's why they're a little more expensive.

--
Karl Vogel / vogelke AT pobox DOT com / I don't speak for anyone at the moment

Skills-wise they suck harder than a black hole with daddy issues.
--Review of Accenture Senior Management


Re: Recommendations for a UPS?

2023-08-01 Thread Karl Vogel
>> On Mon, 31 Jul 2023 13:24:36 -0400,
>> Tom Browder  may have said:

> All the reviews I've seen on Amazon for smaller capacity UPSs
> for APC and Tripp Lite are not that great (I usually concentrate
> on the one- and two-star reviews).

> Any recommenndations from fellow Debian folks?
> Thanks.

  I give a solid vote to Liebert.  I had a near-miss lightning strike
  a few nights ago, and all it did was make my display go out for about
  a second.  It came right back, session intact, didn't lose a thing.

--
Karl Vogel / vogelke AT pobox DOT com / I don't speak for anyone at the moment

Why Trick or Treating is Better than Sex #9:
  If you get tired, you can wait 10 minutes and go at it again.


Re: Expect script does not work on crontab

2012-03-13 Thread Karl Vogel
>> On Tue, 13 Mar 2012 13:59:35 +0530, 
>> Bilal mk  said:

B> The following script is working fine executing from shell. But does not
B> work running on crontab.  How to fix this crontab issue?
B>   #!/usr/bin/expect
B>   spawn /usr/bin/rsync -avz --delete /var/app/ user@somedomain:/var/app/
B>   expect "Password:"
B>   send "somepassword\r"
B>   interact

   I believe the "interact" line is messing you up; when "expect" sees that,
   it wants a terminal or PTY to play with, and cron doesn't give it one.

-- 
Karl Vogel  I don't speak for the USAF or my company

I smile because I don't know what's going on.--bumper sticker


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120313184717.e6d36b...@kev.msw.wpafb.af.mil



Re: Cron, > 1 month but < 2 months

2012-03-11 Thread Karl Vogel
>> On Sun, 11 Mar 2012 01:42:25 -0600, Christofer C. Bell wrote:

C> According to this page[1], the following works for that:
C>* * */45 * * your_scheduled_task
C> I've not tried it myself.

   I'd use a timestamp file in conjunction with find; what happens when
   your 45-day interval crosses Jan 1st?  For example:

 me% date
 Sun Mar 11 21:51:21 EDT 2012

 me% touch -d '45 days ago' timestamp

 me% ls -l --time-style='+%d-%b-%Y %T' timestamp
 -rw-r--r-- 1 me   me   0 26-Jan-2012 20:51:27 timestamp

 me% find timestamp -daystart -mtime +1 -print
 timestamp

 me% find timestamp -daystart -mtime +44 -print
 timestamp

 me% find timestamp -daystart -mtime +45 -print # no output


   Run something like this every day:

 #!/bin/bash
 ts=/time/stamp/file
 interval=45

 set X $(find $ts -daystart -mtime +$interval -print)
 shift
 case "$#" in
 0) logger 'starting' ;;
 *) logger 'skipping'; exit 0 ;;
 esac

 # run your php script or whatever ...
 touch $ts


   Another advantage: you can decide whether to "touch $ts" based on the
   return code from whatever you're trying to run.  If it fails, do you
   want to alert someone and run it tomorrow or wait another 45 days?
   Reschedule by setting the $ts modtime instead of dorking around with cron.

-- 
Karl Vogel  I don't speak for the USAF or my company

Bumper-sticker on Mel Gibson's car: "Swerve If You Love Jesus"


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120312021336.658d0b...@kev.msw.wpafb.af.mil



Re: How to keep track of files installed from sources?

2012-03-09 Thread Karl Vogel
>> On Sat, 18 Feb 2012 21:53:49 +0100, 
>> Csanyi Pal  said:

C> I want to install GNUstep from sources on my Debian GNU/Linux SID sytem.
C> How can I know where come installed files after I did run: ./configure
C> && make && sudo -E make install commands?

C> this is important if I decide later to uninstall files installed from
C> sources.

   If you want a list of what files were installed, the easiest way is
   probably to do the configure/make/make install dance twice.  The first
   time, install under a disposable directory:

 root# mkdir /tmp/local
 root# cd /your/source/directory
 root# ./configure --prefix=/tmp/local --whatever
 root# make && make install

   If you're planning on installing under /usr/local:

 root# find /tmp/local -printf "%y %p %m %u %g %l\n" | sort -k2,2 |
   sed -e 's!/tmp/local!/usr/local!' > list-of-installed-files
 root# rm -rf /tmp/local
 root# make distclean   # or make realclean, start from scratch
 root# ./configure ...  # use real options this time
 root# make && make check && make install

   "find" gives the filetype, path, mode, owner, group, and an optional 6th
   field if the file is a symbolic link; "sort" gives results sorted by
   filename.  Some sample output:

 d /usr/local/bin 755 root bin
 f /usr/local/bin/antiword 755 root bin
 f /usr/local/bin/authlog 755 root bin
 f /usr/local/bin/avg 755 root bin
 l /usr/local/bin/bootlog 777 root bin authlog
 d /usr/local/lib 755 root bin
 ...

   Here, /usr/local/bin/bootlog is a symlink to /usr/local/bin/authlog.
   If you're paranoid, either save the output from "make install" or do a
   separate check to make sure nothing was written outside of /usr/local:

 root# find / /usr -xdev -mtime -1 -ls

-- 
Karl Vogel  I don't speak for the USAF or my company

I put instant coffee in a microwave and went back in time.  --Steven Wright


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120309192354.29d58b...@kev.msw.wpafb.af.mil



Re: Understanding the -depth option of find?

2012-03-08 Thread Karl Vogel
>> On Thu, 8 Mar 2012 17:06:54 + (UTC),  said:

C> I make the backup for my /home directory with plain "tar". What are the
C> benefits/drawbacks of using "cpio" instead?

   Older versions of tar wouldn't read from stdin or any other list of files,
   and they also had really short limits on filename length.  Some still do.

   I like cpio because it accepts output from "find", a list of files, or any
   intermediate filter.  I prefer pax because in addition, it'll accept cpio,
   ustar, or its own internal format.  Other advantages include consistent
   behavior and command-line options on FreeBSD, Linux, and Solaris.
   Doing things like hourly incremental/differential backups is a snap:

 root# touch /backup/etc/drive1

 [ ...an hour later... ]
 root# cd /drive1
 root# dest="$(date '+/backup/drive1/%Y/%m%d/%H%M')"
 root# mkdir -p $dest
 root# find ./userstuff -depth -newer /backup/etc/drive1 -print |
 pax -rwd -pe $dest 

   In this case, the "-depth" option ensures correct timestamps on all
   created directories, and "-pe" preserves owner/group/mode/modtime stuff.

-- 
Karl Vogel  I don't speak for the USAF or my company

Heck, if an omniscient psycho ex offered me discounted, in-stock products I
was going to buy anyway, I might just keep them around.  That's everything
Amazon tries to be already, anyway.
--slashdot response to Target data-mining for pregnant customers


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120308215615.05c7bb...@kev.msw.wpafb.af.mil



Re: history configuration

2012-03-07 Thread Karl Vogel
>> On Wed, 29 Feb 2012 00:19:19 +0800, lina  said:

L> How to configure to make each terminal share one "history"?  I found
L> each terminal saves its own history and no sharing.  Is it possible to
L> let them share?

   You can if you don't mind stretching the definition of "share".  Have a
   look at this page to see how to save your command history to syslog:
  http://jablonskis.org/2011/howto-log-bash-history-to-syslog/

   Here's an example.  I added this to the end of ~/.bashrc to save history
   to my own file and the system log:

  export PROMPT_COMMAND='history -a >(tee -a ~/.bash_history |
logger -p local2.notice -t "$USER [$$] $SSH_CONNECTION")'

   This sends my history to facility "local2" with priority "notice".
   I fixed syslog so local[25] messages only show up in one place; I already
   use local5 for output from a backup program.  Here's the relevant part
   of /etc/syslog.conf -- backslashes must be at the end of the lines:

  # Log anything (except mail) of level info or higher.
  # Don't log private authentication messages!
  *.info;kern.none;mail.none;\
 authpriv.none;auth.none;local2.none;\
 local5.none;cron.none   /var/log/messages
  # Auth logfiles are restricted.
  authpriv.* /var/log/secure
  auth.* /var/log/authlog
  # Local logs.
  local0.*   /var/log/local0log
  local1.*   /var/log/local1log
  local2.*   /var/log/local2log
  local3.*   /var/log/local3log
  local4.*   /var/log/local4log
  local5.*   /var/log/local5log
  local6.*   /var/log/local6log
  # Cron stuff
  cron.* /var/log/cron

   Here's what my history looks like:

  me% tail -3 /var/log/local2log
  Mar 7 22:09:22 svr1 vogelke [149] 1.2.3.4 46555 5.6.7.8 22: which logger
  Mar 7 22:09:31 svr1 vogelke [149] 1.2.3.4 46555 5.6.7.8 22: echo $PATH
  Mar 7 22:09:44 svr1 vogelke [149] 1.2.3.4 46555 5.6.7.8 22: dir 
/var/log/local*

  me% tail -3 $HOME/.bash_history
  which logger
  echo $PATH
  dir /var/log/local*

   "1.2.3.4" is where I'm connecting from, "5.6.7.8" (aka "svr1") is the
   host I'm connecting to via SSH.  If you use the Z-shell instead of bash,
   the method is pretty similar -- add this function to the bottom of your
   ~/.zshrc file:

  # Log commands, return codes and the current working directory.
  # Based on:
  #
  #   http://blogs.sun.com/chrisg/entry/logging_commands_in_korn_shell
  #   Logging commands in korn shell
  #   Chris Gerhard
  #   Thu, 2 Mar 2006 09:47:29 -0500
  #
  # Don't try to put local on the x= line.  If you do,
  # any command arguments (i.e., "ls -la") will throw an error:
  #   precmd:local:2: not an identifier: -la
  precmd () {
  typeset -i stat=$?
  local x
  x=$(fc -ln -1)
  local d="$(/bin/pwd)"
  logger -p local2.notice -t "$LOGNAME $$" $stat: $d: \($x\)
  }

   In order to really share this, you'd probably have to write something to
   grub around in the syslog file.

-- 
Karl Vogel  I don't speak for the USAF or my company

She acts like she's on the phone to avoid certain customers.  One time it rang.
 --Jimmy Fallon, #mycoworkeriscrazy tweets, 2 Mar 2012


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120308040126.7ec1cb...@kev.msw.wpafb.af.mil



Re: [OT] A quick Q: how to check the webpage building time

2012-03-05 Thread Karl Vogel
>> On Mon, 5 Mar 2012 23:28:12 +0800, 
>> lina  said:

L> Sometimes I wish to know the info. on some webpage, which is latest news
L> or 7 years ago.  How can I know the building time of those information.

   For static files, either "curl" or "HEAD" can do this.  For example:

% curl -I 
http://www.hcst.net/~vogelke/pictures/2012/0105-new-year-wishes/p04.jpg
HTTP/1.1 200 OK
Date: Tue, 06 Mar 2012 03:49:27 GMT
Server: Apache
Last-Modified: Thu, 05 Jan 2012 20:04:57 GMT
ETag: "414a07-3a93-4b5cd7246ac40"
Accept-Ranges: bytes
Content-Type: image/jpeg
Content-Length: 14995

   A dynamically-generated page will return the current time.  Also, the
   server may be configured to NOT return the modtime for (say) an
   index.html file, even if it's static.

-- 
Karl Vogel  I don't speak for the USAF or my company

For a nosebleed: Put the nose much lower then the body until the heart stops.
--submitted to science and health teachers, Jr High thru college


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120306035551.74d65b...@kev.msw.wpafb.af.mil



Re: Question about ssh passwords and backup software

2012-02-13 Thread Karl Vogel
>> Alex Mestiashvili  wrote:

A> I would simply use a passwordless ssh-key with a wrapper on the remote
A> side which allows to run only the backup command .

>> On Mon, 13 Feb 2012 18:51:26 +, 
>> Chris Davies  said:

C> I'd agree with this, but use passwordless public/private keys with a
C> restricted target command:
C>  command="backup-service",no-pty,no-port-forwarding ssh-rsa BLAHBLAH...

   If the box from which you're copying has a static hostname or IP
   address, include that as well:

from="1.2.3.4",command="backup-service",no-pty,no-port-forwarding ...

-- 
Karl Vogel  I don't speak for the USAF or my company

Why Trick or Treating is Better than Sex #10:
  You are guaranteed to get at least a little something in the sack.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120214013943.97494b...@kev.msw.wpafb.af.mil



Re: [OT] how to take care of hand

2012-02-08 Thread Karl Vogel
R> On Mon, 6 Feb 2012 14:47:26 -0500 (EST) (Karl Vogel) wrote:

K> I correct shoulder pain by doing 5-10 very slow pushups just before bed,
K> or by holding a dumbbell over my shoulder and letting my hand dangle
K> over the back of the couch while watching TV.

>> On Mon, 6 Feb 2012 20:22:29 +, 
>> richard  said:

R> you are referring to 10 push ups with each arm aren't you?

   Nope.  By "slow", I mean 5 seconds down, hold for a second, then 5 seconds
   up for one pushup; if you need more, knock yourself out.  It's not intended
   to replace your morning jog with Seal Team Six.

...I'm such a snot, it's a wonder I have any friends at all...

R> but I'm in the state of the beggar in "life of Brian".

   Just remember, we're *all* individuals.

-- 
Karl Vogel  I don't speak for the USAF or my company

This punishment is not boring and pointless.
--written on blackboard by Bart Simpson


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120208193510.ce067b...@kev.msw.wpafb.af.mil



Re: [OT] how to take care of hand

2012-02-06 Thread Karl Vogel
>> On Fri, Feb 3, 2012 at 18:57, lina wrote:

L> are there some suggestions about how to take care of hand?

   I've had similar problems with my wrists and shoulders, and the one
   thing that helped most was taking 3 minutes a day to do a set of complete
   range-of-motion wrist exercises with really small dumb-bells (5 pounds
   or less).  Holding the weights palm-up and rolling them from fingertip
   to palm and back really did the trick.

   I correct shoulder pain by doing 5-10 very slow pushups just before bed,
   or by holding a dumbbell over my shoulder and letting my hand dangle over
   the back of the couch while watching TV.  A few minutes of that and my
   arm turns to spaghetti, but it feels better in the morning.

   I've been told that not getting enough B-vitamins drops the effectiveness of
   other supplements you take; they'll be washed out before the body can use
   them, and they tend to get eaten up faster when under stress.  I also take
   cod-liver oil to keep my joints nice and gushy.  Your doctor may disagree.

-- 
Karl Vogel  I don't speak for the USAF or my company

ANTI-TALKSIDENT: A spray carried in a purse or wallet to be used on anyone
too eager to share their life stories with total strangers in elevators.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120206194726.b731db...@kev.msw.wpafb.af.mil



Re: how to check the server can be connected or not

2012-02-06 Thread Karl Vogel
>> On Fri, 3 Feb 2012 11:49:22 +0800, lina  said:

L> Hi, a server is closed, but will start in future, sooner or later, I
L> wish to access in the first time it's open.  I tried:

L> while ( ssh server ) do sleep 60 done
L> wall < server_open.txt

   Instead of polling the server, could you have it send a mail message to
   a special address when starting SSH?  If you're running the while-loop
   on your workstation, set up an extension address like
lina-w...@your.workstation.com
   which forwards incoming mail from the SSH server to /usr/bin/wall.

   If you use Postfix, see the http://www.postfix.org/local.8.html sections
   on ADDRESS EXTENSION and EXTERNAL COMMAND DELIVERY.

-- 
Karl Vogel  I don't speak for the USAF or my company

The patient is tearful and crying constantly.
She also appears to be depressed.--actual comment on hospital chart


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120206194121.43109b...@kev.msw.wpafb.af.mil



Re: how to check 400 files exist

2012-01-20 Thread Karl Vogel
>> On Thu, 19 Jan 2012 00:34:50 +0800, 
>> lina  said:

L> I am choked by how to check more than 400 files exist or not, if not,
L> sleep, but once it's all generated, continue do something.  Those files
L> have a common feature: sys_em_$i.txt

   The script below doesn't do any glob-expansion of filenames, so it won't
   barf if you have a lot of files.  It assumes you're in the same directory
   as the files you're checking.

-- 
Karl Vogel  I don't speak for the USAF or my company

A raccoon tangled with a 23,000 volt line today.  The results blacked
out 1400 homes and, of course, one raccoon.--Steel City News

--
#!/bin/bash
export PATH=/usr/local/bin:/bin:/usr/bin

case "$#" in
0) echo need a number; exit 1 ;;
*) my_number=$1 ;;
esac

while :
do
if [ $(find . -name 'sys_em_*.txt' -print | wc -l) == "$my_number" ]
then
echo 'success'
break
fi

echo 'test'
sleep 5
done

echo 'done'
exit 0


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120120200208.79090b...@kev.msw.wpafb.af.mil



Re: How to do this, fold + split

2012-01-06 Thread Karl Vogel
>> On Fri, 30 Dec 2011 15:09:13 + (UTC), 
>> T o n g  said:

T> I want to split a file every ### of chars. Is it possible not to split
T> on the word but word boundaries?

   Yup, for certain meanings of "split".  GNU fmt is part of "coreutils".
   Here's sample.txt (rulers added for readability):

   me% cat sample.txt
   *1*2*3*4*5*6*7*
   Here is what I normally do.  Here is a skeleton script that creates a
   temporary file, redirects all output there, then if there is output it
   emails it off.  There are many ways to do this and I tinker it as
   needed.

   me% gfmt -65 sample.txt
   *1*2*3*4*5*6*7*
   Here is what I normally do.  Here is a skeleton script that
   creates a temporary file, redirects all output there, then if
   there is output it emails it off.  There are many ways to do
   this and I tinker it as needed.

   me% gfmt -75 sample.txt
   *1*2*3*4*5*6*7*
   Here is what I normally do.  Here is a skeleton script that creates a
   temporary file, redirects all output there, then if there is output it
   emails it off.  There are many ways to do this and I tinker it as needed.

   If you want one word per line, which can be very handy:

   me% gfmt -1 sample.txt
   Here
   is
   what
   [...]
   as
   needed.

-- 
Karl Vogel  I don't speak for the USAF or my company

A map with a bullet hole in it is still a map.  A computer with a
bullet hole in it is a paper-weight.  --why soldiers tend to like paper


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20120106201008.13767b...@kev.msw.wpafb.af.mil



Re: fastcgi too slow in debian squeeze

2011-12-20 Thread Karl Vogel
>> On Tue, 20 Dec 2011 12:26:44 +0530, 
>> "J. Bakshi"  said:

J> I have been suffering with the slow performance of my apache server
J> (2.2.16) running on debian wheezy. I have finally pointed out it is the
J> fastcgi which makes the web server so slow. But I really need it as I am
J> also hosting some sites which do require php 5.2. The symptoms of having
J> the fastcgi is very annoying.

J> 1 All sites need 30 or so sec. to open and after that the browsing is
J> again normal for that site.

   Whenever I've had a 30-sec-delay problem opening a site, it's almost
   always been something DNS-related.  Do you have any other apps requiring
   external host resolution that are seeing similar delays?

   A caching DNS resolver usually fixes things, and it's not hard to set up.

-- 
Karl Vogel  I don't speak for the USAF or my company

You have experienced an Action Request System Error (ARSE).
  --Remedy error message, much funnier if you're in England


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20111221025801.23a8ab...@kev.msw.wpafb.af.mil



Re: Crazy (?) idea: screen locker with simpler password

2011-11-08 Thread Karl Vogel
>> On Mon, 7 Nov 2011 23:40:24 -0700, 
>> Bob Proulx  said:

B> I would create a script that edited the /etc/shadow file directly and
B> manipulated the encrypted passwords.  Then the clear text would never
B> need to exist in any form.  Only the encrypted form of the password is
B> needed.  Use a script to swap between two different encrypted forms.

   If you don't add or delete a lot of accounts or modify /etc/passwd
   frequently, could you change your password to the high-security one,
   copy /etc/shadow to /etc/shadow.hi, then change it back and copy
   /etc/shadow to /etc/shadow.lo?  Then your password-changer could be:

 alias hisec='sudo cp -p /etc/shadow.hi /etc/shadow'
 alias losec='sudo cp -p /etc/shadow.lo /etc/shadow'

-- 
Karl Vogel  I don't speak for the USAF or my company

It's impossible to sneeze with your eyes open.
--item for a lull in conversation


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/2009014634.bd5eab...@kev.msw.wpafb.af.mil



Re: linux friendly hardware inquiry/advise

2011-10-19 Thread Karl Vogel
>> On Wed, 19 Oct 2011 22:24:37 +1000, yudi v  said:

Y> Building a new PC, will be used for coding mostly, running 2-3 VMs
Y> simultaneously.  Debian Linux will be the host OS. I need some
Y> suggestions on Motherboards.  Which manufacturer has good linux support?

   The Ars Technica Guides are great if you're building your own box.  The
   system guides go through parts for a budget box, a hot-rod (better than
   average) and a God box (top-notch, hopefully with someone else's money).
   The most recent system guide I've seen was last March.

   http://arstechnica.com/guides/
   
http://arstechnica.com/gadgets/guides/2011/03/ars-system-guide-march-2011-edition.ars

-- 
Karl Vogel  I don't speak for the USAF or my company

I've seen people with new children before, they go from ultra happy to
looking like something out of a zombie film in about a week.
  --Alan Cox about Linus Torvalds after his 2nd daughter


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20111019210241.bc4a9b...@kev.msw.wpafb.af.mil



Re: Formatting external HDD

2011-10-19 Thread Karl Vogel
>> On Tue, 18 Oct 2011 17:54:32 +0100, Lisi  said:

L> I have just acquired a one T HDD for use as an external HDD.  I now need
L> to decide how to partition it. [...] Would it be feasible to have one
L> large partition on the drive, and then use directories rather than
L> partitions for the different back-ups?

   Yes.  I've been using 1.5Tb Seagate drives for a backup server, and they
   work fine with one large or two smaller partitions:

 Filesystem  1M-blocks Inodes  Mounted
  /dev/sda21372701  362774528   /data1
  /dev/sdb6 699594   11216896   /data2
  /dev/sdb7 699601   11216896   /data3

   I used "mkfs.ext3 -J size=400 -i 65536 -m 2" when creating the sdb
   filesystems, which gave me an extra 27Gb by creating one inode per 64K
   and only reserving 2% for overflow.  I get better performance by using
   the deadline scheduler and setting vm.swappiness = 10.

L> Could I do this with cp (obviously), dd, rsync, Clonezilla, or even
L> something I don't know about yet?

   Sure, cp for the initial copy and then rsync for changes.

L> And what filing system? [...] My box is ill, possibly unto death.

   In that case, now's not the time to experiment.  Use something familiar,
   and play around *after* your stuff is safely backed up.

-- 
Karl Vogel  I don't speak for the USAF or my company

Salesmen welcome.  Dog food is expensive.--seen on a fence


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20111019212911.1c538b...@kev.msw.wpafb.af.mil



Re: a quick Q: how to start run a job after another job finished

2011-10-06 Thread Karl Vogel
>> On Thu, 6 Oct 2011 23:12:46 +0800, 
>> lina  said:

L> I want to run a job after checking another job finished or not, such as
L> another job PID is 5543.  If it's finished then run newjob.sh

   If you own the other process (or you're root) you can use signal 0 to
   verify that it's still alive:

 me% sleep 60 &
 [1] 10175

 me% kill -0 10175  [$? = 0]

 me% kill -0 10176
 kill: kill 10176 failed: no such process   [$? = 1 or 2]

   Try this:

 pid=5543  # or $1 or whatever
 while kill -0 $pid 2> /dev/null; do
 sleep 60
     done
 /path/to/newjob.sh

-- 
Karl Vogel  I don't speak for the USAF or my company

Taxation WITH representation isn't so hot, either.--bumper sticker


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20111007033031.57f74b...@kev.msw.wpafb.af.mil



Re: How do you save passwords for Git/GitHub?

2011-07-21 Thread Karl Vogel
>> On Thu, 21 Jul 2011 12:06:11 -0500, 
>> Jason Hsu  said:

J> I have a script that uses "git clone" multiple times to download all of
J> the repositories I need for my project Swift Linux.  However, I'm asked
J> for my password EVERY TIME the script tries to download a repository. Is
J> there a way to save my password (temporarily) so that I don't have to
J> enter it 20 times?

   Do you have TCL and expect installed?  If so, expect and autoexpect can
   be used to automate just about any interactive process.  Here's an example
   using a long, random key for your SSH passphrase:

 you% cat makekey
 #!/bin/ksh
 # /dev/null | md5sum`
 phrase="$2"
 sleep 1
 set X `dd if=/dev/urandom count=1 2> /dev/null | md5sum`
 phrase="${2}${phrase}"
 echo $phrase

 # Use it to generate SSH keys.
 ssh-keygen -t dsa -b 1024 -f $dir/${name}_dsa -N "$phrase"
 ssh-keygen -t rsa -b 1024 -f $dir/${name}_rsa -N "$phrase"
 exit 0

 you% makekey github
 27262a68bd1f633d1702c599f4cd78ad93be2fa7a40a554c15af86a929339df9
 Generating public/private dsa key pair.
 Your identification has been saved in /home/jhsu/.ssh/github_dsa.
 Your public key has been saved in /home/jhsu/.ssh/github_dsa.pub.
 The key fingerprint is:
 a5:a2:21:82:29:3a:08:d1:bb:e4:38:57:4a:88:cb:bc j...@your.host
 Generating public/private rsa key pair.
 Your identification has been saved in /home/jhsu/.ssh/github_rsa.
 Your public key has been saved in /home/jhsu/.ssh/github_rsa.pub.
 The key fingerprint is:
 ec:ee:45:bd:73:91:47:24:e4:c6:df:a4:17:b6:ea:fd j...@your.host

 you% ls -lF /home/jhsu/.ssh/github*
 -rw--- 1 jhsu  jhsu  736 Jul 21 15:17 /home/jhsu/.ssh/github_dsa
 -rw-r--r-- 1 jhsu  jhsu  621 Jul 21 15:17 /home/jhsu/.ssh/github_dsa.pub
 -rw--- 1 jhsu  jhsu  951 Jul 21 15:17 /home/jhsu/.ssh/github_rsa
 -rw-r--r-- 1 jhsu  jhsu  241 Jul 21 15:17 /home/jhsu/.ssh/github_rsa.pub

   You've got a nice, long key with plenty of entropy.  Here's an expect
   script that logs you into a host using that key, after you put the public
   keys on that host:

  1  #!/usr/local/bin/expect -f
  2  # SSH connect to some host with userid "jhsu".
  3
  4  set timeout -1
  5  set stty_init -echo
  6  spawn ssh -i /home/jhsu/.ssh/github_dsa -c arcfour example.github.org
  7  match_max 10
  8  expect -exact "Enter passphrase for key '/home/jhsu/.ssh/github_dsa':"
  9  send -- "27262a68bd1f633d1702c59...\r"
 10  expect "\r"
 11  stty echo
 12  interact

   "Expect" sends strings on your behalf and takes different actions depending
   on the responses.  Running this script will handle starting the connection
   and sending your key; if the login is successful, you should get a shell
   prompt, or whatever you're used to seeing when you connect.

   line  4: disable any automatic timeouts
   line  5: disable echoing so the passphrase doesn't show up
   line  6: start the SSH connection to the remote host
   line  7: don't try to match more than this many characters
   line  8: look for an exact host response of "Enter passphrase..."
   line  9: then send the key followed by a return
   line 10: look for a return (or some string indicating successful login)
   line 11: enable echoing
   line 12: let expect know that you'll handle any further interaction

   Protect this expect script the same way you do your private SSH keys,
   for exactly the same reason.

   If the interaction here doesn't match what you normally see, use the
   autoexpect program to watch over your shoulder while you do a session by
   hand, and it will write a script for you.

-- 
Karl Vogel  I don't speak for the USAF or my company

The last thing I want to do is hurt you, but it's still on my list.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110721205739.b68edb...@kev.msw.wpafb.af.mil



Re: (hopefully perl) API to /etc/network/interfaces?

2011-06-01 Thread Karl Vogel
>> On Tue, 31 May 2011 23:23:19 -0500, 
>> Mike Mestnik  said:

M> I'm quite certain this is a some-what usable solution.  However it
M> doesn't appear to have any means to preserve order.

   Have a look at the Config::Std module by Damian Conway.  It handles a
   similar problem (reading/writing dot-INI files) but preserves the section
   order.

-- 
Karl Vogel  I don't speak for the USAF or my company

Things that never happen in "Star Trek" #7:
The Enterprise successfully ferries an alien VIP from one place to another
without serious incident.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110602003719.a0b51b...@kev.msw.wpafb.af.mil



Re: Problem with the global weigh of several files

2011-05-26 Thread Karl Vogel
>> On Thu, 26 May 2011 17:12:25 +0200, 
>> "Gorka"  said:

G> I am looking for the best way of appending commands to obtain the global
G> amount of Mb of the modified files of my PC.  Something like this:
G> find ./ -mtime -7 | du -Sch

#!/bin/ksh
# filesize summary; optional argument is starting directory.
export PATH=/usr/local/bin:/bin:/usr/bin

case "$1" in
"") dir="$HOME" ;;
*)  dir="$1" ;;
esac

test -d "$dir" || { echo "$dir: not a directory"; exit 1; }
cd $dir|| { echo "$dir: cannot cd"; exit 2; }
dir=$(pwd)

find . -type f -mtime -7 -printf "%s\n" | gawk -v "d=$dir" \
 'BEGIN { size = 0; }
     { size += $1; }
 END {
   printf "%s: %d new files using %.1f Mb\n", d, NR, size/1048576;
 }'

exit 0

-- 
Karl Vogel  I don't speak for the USAF or my company

Men are like a fine wine.  They start out as grapes and it's up to women
to stomp the sh*t out of them until they turn into something acceptable
to have with dinner.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110526215044.41031b...@kev.msw.wpafb.af.mil



Re: first mkdir takes a long time (on ext3)

2011-05-21 Thread Karl Vogel
>> On 19/05/11 17:01, Hartmut Niemann wrote:
H> It often takes very long time (20s) to mkdir on an ext3 drive

>> Am Fr Mai 20 2011 schrieb Karl Vogel:
K> What does "strace mkdir /some/directory" show?

>> On Fri, 20 May 2011 08:38:41 +0200,  said:
H> $ strace mkdir two
H> execve("/bin/mkdir", ["mkdir", "two"], [/* 18 vars */]) = 0
H> brk(0)   = 0x9342000
H> access("/etc/ld.so.nohwcap", F_OK)   = -1 ENOENT (No such file ...
H> mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS...
H> access("/etc/ld.so.preload", R_OK)   = -1 ENOENT (No such file ...
H> open("/etc/ld.so.cache", O_RDONLY)   = 3
H> fstat64(3, {st_mode=S_IFREG|0644, st_size=41270, ...}) = 0
H> mmap2(NULL, 41270, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb78be000
H> close(3) = 0
H> access("/etc/ld.so.nohwcap", F_OK)   = -1 ENOENT (No such file ...
H> open("/lib/libselinux.so.1", O_RDONLY)  = 3
H> ...

   I installed a more recent version of GNU coreutils from source, and
   compared /bin/mkdir to /usr/local/bin/mkdir.  I found /bin/mkdir gives
   output like yours, but the /usr/local output is much shorter and doesn't
   include any references to selinux:

 me% strace -r /usr/local/bin/mkdir three
 0.00 execve("/usr/local/bin/mkdir", ["mkdir", "three"], ...
 0.000480 brk(0) = 0x196f2000
 0.76 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|...
 0.85 uname({sys="Linux", node="cmswbk002", ...}) = 0
 0.000139 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such ...
 0.99 open("/etc/ld.so.cache", O_RDONLY) = 3
 0.66 fstat(3, {st_mode=S_IFREG|0644, st_size=67370, ...}) = 0
 0.000103 mmap(NULL, 67370, PROT_READ, MAP_PRIVATE, 3, 0) = ...
 0.55 close(3) = 0
 0.71 open("/lib64/libc.so.6", O_RDONLY) = 3
 0.65 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\...
 0.73 fstat(3, {st_mode=S_IFREG|0755, st_size=1717800, ...}) =...
 0.93 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_A...
 0.71 mmap(0x32bce0, 3498328, PROT_READ|PROT_EXEC, MAP_PRI...
 0.79 mprotect(0x32bcf4e000, 2093056, PROT_NONE) = 0
 0.63 mmap(0x32bd14d000, 20480, PROT_READ|PROT_WRITE, MAP_PRIV...
 0.78 mmap(0x32bd152000, 16728, PROT_READ|PROT_WRITE, MAP_PRIV...
 0.62 close(3) = 0
 0.71 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_A...
 0.60 arch_prctl(ARCH_SET_FS, 0x2ae92dd5f230) = 0
 0.000143 mprotect(0x32bd14d000, 16384, PROT_READ) = 0
 0.69 mprotect(0x32bc01b000, 4096, PROT_READ) = 0
 0.56 munmap(0x2ae92dd4d000, 67370) = 0
 0.000141 mkdir("three", 0777) = 0
 0.000148 close(1) = 0
 0.60 close(2) = 0
 0.62 exit_group(0) = ?

   "-r" prints a relative timestamp upon entry to each system call.

H> This run was fast (less than 1 second).  Unfortunately I do not know
H> when mkdir takes long and can't reproduce it today, so I can't tell
H> whether a strace of a slow mkdir is different.

   Try this version of mkdir earlier in your PATH until you find out what
   the delay is.

 you% mkdir /tmp/mkdir
 you% chmod 1777 /tmp/mkdir

 you% cat /usr/local/bin/mkdir
 #!/bin/sh
 tfile=$(date '+%Y%m%d%H%M%S')
 exec /usr/bin/strace -r -o /tmp/mkdir/$tfile /bin/mkdir ${1+"$@"}
 exit 1

-- 
Karl Vogel  I don't speak for the USAF or my company

NyQuil -The stuffy, sneezy, why-the-hell-is-the-room-spinning medicine.
 --seen on T-shirt


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110522020507.468fab...@kev.msw.wpafb.af.mil



Re: first mkdir takes a long time (on ext3)

2011-05-19 Thread Karl Vogel
>> On 19/05/11 17:01, Hartmut Niemann wrote:

H> It often takes very long time (20s) to mkdir on an ext3 drive

   What does "strace mkdir /some/directory" show?

-- 
Karl Vogel  I don't speak for the USAF or my company

Q: What lies on the bottom of the ocean and twitches?
A: A nervous wreck.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110520040714.1196ab...@kev.msw.wpafb.af.mil



Re: Format ext3 hard drives

2011-03-22 Thread Karl Vogel
>> On Tuesday 22 March 2011 02:42:36 pm Dan wrote:

D> I am using the netinst to install Debian. I have one hard drive of 160GB
D> and 2 hard drives of 2TB. Each hard drive has a ext3 partition for the
D> whole drive. I used ext3 instead of ext4, because that is the default
D> value in Squeeze.  The netinst is creating the ext3 partitions but it is
D> taking for ever.

>> On Tue, 22 Mar 2011 15:19:12 -0800, Greg Madden  said:

G> Not sure about the initial format but all subsequent fsck take lots of
G> time with ext3, esp 2 TB.

   If you're really set on ext3, specifying larger files and fewer inodes
   will definitely shorten the partition build and fsck times.  I have some
   Seagate 1.5Tb drives, and I decided on two ~700Gb partitions instead of
   a single giant one.  You might have to fool around with fdisk to get the
   sizes just the way you like.

   Details are below.

-- 
Karl Vogel  I don't speak for the USAF or my company

Q: What's black and tan and looks good on a lawyer?
A: A Rottweiler.--John J. Irvine

---
Disk use:

me% df
Filesystem   1M-blocks  Used AvailableUse%   Mounted on
/dev/sdb1  130 6   117  5%   /boot
/dev/sdb219501   445 18080  3%   /root
/dev/sdb5 7805   418  6997  6%   /var
/dev/sdb6   699594235065450509 35%   /space1
/dev/sdb7   699601161094524487 24%   /space2

me% df -i
Filesystem Inodes  IUsed  IFree  IUse%   Mounted on
/dev/sdb1   34136 11  34125 1%   /boot
/dev/sdb2  313344 11 31 1%   /root
/dev/sdb5  126976 11 126965 1%   /var
/dev/sdb611216896 169292   11047604 2%   /space1
/dev/sdb711216896  64416   11152480 1%   /space2

Partitions:

# partition table of /dev/sdb
unit: sectors

/dev/sdb1 : start=   63, size=   273042, Id=83, bootable
/dev/sdb2 : start=   273105, size= 40017915, Id=83
/dev/sdb3 : start= 40291020, size=  2008125, Id=82
/dev/sdb4 : start= 42299145, size=2887362450, Id= 5
/dev/sdb5 : start= 42299208, size= 16016742, Id=83
/dev/sdb6 : start= 58316013, size=1435664727, Id=83
/dev/sdb7 : start=1493980803, size=1435680792, Id=83

This script ran in about 25 minutes on a CentOS system:

#!/bin/ksh -x
# make filesystems with fewer inodes, larger files.

export PATH=/sbin:/bin:/usr/bin

date; mkfs.ext3   /dev/sdb1
date; mkfs.ext3 -J size=400 -i 65536  /dev/sdb2
date; mkswap -L SWAP-sdb3 /dev/sdb3
date; mkfs.ext3 -J size=400 -i 65536  /dev/sdb5
date; mkfs.ext3 -J size=400 -i 65536 -m 2 /dev/sdb6
date; mkfs.ext3 -J size=400 -i 65536 -m 2 /dev/sdb7
exit 0

Using fewer inodes added a total of nearly 80 Gb of available space on
/space1 and /space2, compared to one huge partition with default inode setup.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110323012350.3a7f2b...@kev.msw.wpafb.af.mil



Re: putting "/tmp" to memory help

2011-01-23 Thread Karl Vogel
>> Dne, 23. 01. 2011 17:19:41 je Pascal Hambourg napisal(a):

P> Tmpfs is not a RAM disk (RAM-based block device), it is a filesystem in
P> virtual memory.

>> On Sun, 23 Jan 2011 20:39:36 +0100, 
>> Klistvud  said:

K> Didn't know that. Damn clever. I stand corrected.

   http://landley.net/writing/rootfs-intro.html has a nice, short
   description of ramdisk vs. ramfs.

-- 
Karl Vogel  I don't speak for the USAF or my company

The San Francisco Cable cars are the only mobile National Monuments.
--odd but true


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110124004048.02cc7b...@kev.msw.wpafb.af.mil



Re: need help making shell script use two CPUs/cores

2011-01-09 Thread Karl Vogel
>> On Sun, 09 Jan 2011 10:05:43 -0600, 
>> Stan Hoeppner  said:

S> #! /bin/sh
S> for k in $(ls *.JPG); do convert $k -resize 1024 $k; done

   Someone was ragging on you to let the shell do the file expansion.  I
   like your way better because most scripting shells aren't smart enough
   to realize that when there aren't any .JPG files, I don't want the
   script to echo '*.JPG' as if that's actually useful.

S> I use the above script to batch re-size digital camera photos after I
S> dump them to my web server.  It takes a very long time with lots of new
S> photos as the server is fairly old, even though it is a 2-way SMP,
S> because the script only runs one convert process at a time serially,
S> only taking advantage of one CPU.

   First things first: are you absolutely certain that running two parallel
   jobs will exercise both CPUs?  I've seen SMP systems that don't exactly
   live up to truth-in-advertising.  If you stuff two "convert" jobs in the
   background and then run "top" (or the moral equivalent) do you SEE both
   CPUs being worked?

   Second: do you have "taskset" installed?  If the work isn't being
   divided up the way you like, you can bind a process to a desired core:
   http://planet.admon.org/how-to-bind-a-certain-process-to-specified-core/

   And last: if you're not using something like LVM, can you do anything to
   make sure you're not hitting the same disk?  If all your new photos are
   on the same drive, any CPU savings you get from parallel processing will
   probably be erased by disk contention.  Better yet, do you have enough
   memory to do the processing on a RAM-backed filesystem?

-- 
Karl Vogel  I don't speak for the USAF or my company

If you're searching for the cause of a ghastly noise and find out that it's
not the cat, leave the area immediately.  --how to survive a horror movie


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/2011011500.46f09b...@kev.msw.wpafb.af.mil



Re: recursively find duplicate filenames

2011-01-05 Thread Karl Vogel
>> On Wed, 5 Jan 2011 03:15:01 -0800 (PST), 
>> S Mathias  said:

S> find duplicate filenames in a folder recursively? how?

   It's a (pretty ugly) one-liner if you have something to reverse strings
   in a file.  Put this in (say) /usr/local/bin/rev:

 #!/usr/bin/perl -n
 chomp;
 print +(scalar reverse), "\n";
 exit(0);

   And then:

 you% cd /some/place
 you% find . -print | rev | cut -f1 -d/ | rev | sort | uniq -c | \
  expand | grep -v ' 1 '

   Or you could replace the uniq-expand-grep with some awk weirdness if
   you're into that.

-- 
Karl Vogel  I don't speak for the USAF or my company

If men ruled the world #18: It would be perfectly legal to steal a sports
car, as long as you returned it the following day with a full tank of gas.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110106024045.89094b...@kev.msw.wpafb.af.mil



Re: recursively count the words occurrence in the text files

2010-12-30 Thread Karl Vogel
>> On Thu, 30 Dec 2010 10:34:59 -0800 (PST), 
>> S Mathias  said:

S> ...recursively count the words occurrence in the text files.

   This assumes words consist of alphanumeric characters only.  If that's
   not the case, you'll need to change the "tr/" line in the script.

   me% head */*
   ==> one/asf.txt <==
   word1 word2 word3

   ==> one/asfcxv.txt <==
   word2 word4, word5

   ==> one/dsgsdg.txt <==
   word1. word2

   ==> three/qwerbdsg.txt <==
   word7, word8 word9 word10

   ==> three/weberg.txt <==
   word4 word3

   ==> three/werdf.txt <==
   asdf, word2

   ==> two/ergd.txt <==
   word6

   ==> two/sdgsddsf.txt <==
   word6, word3


   me% cat words
   #!/usr/bin/perl -w
   use strict;
   my %words;

   while (<>) {
   tr/a-zA-Z0-9/ /cs;
   foreach my $w (split) {
   $words{$w}++;
   }
   }
   foreach (sort keys %words) {
   print "$_ $words{$_}\n";
   }
   exit(0);


   me% ./words */*
   asdf 1
   word1 2
   word10 1
   word2 4
   word3 3
   word4 2
   word5 1
   word6 2
   word7 1
   word8 1
   word9 1

-- 
Karl Vogel  I don't speak for the USAF or my company
Never take a beer to a job interview.  --Martha Stewart's tips for Rednecks


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20101230213326.cc245b...@kev.msw.wpafb.af.mil



Re: Extremely large level 1 backups with dump

2010-12-07 Thread Karl Vogel
>> In an earlier message, I said:

K> This box has ~630,000 files using 640 Gbytes, but not many files change
K> hourly.

>> On Mon, 6 Dec 2010 21:33:01 -0700, Bob Proulx  said:

B> Note that you must have sufficient ram to hold the inodes in buffer cache.
B> Otherwise I would guess that it would be hugely slower due to the need to
B> read the disk while reading directories.  But if there is sufficient ram
B> for filesystem buffer cache then it will be operating at memory speeds.
B> For anyone trying to recreate this goodness but wondering why they aren't
B> seeing it then check that the buffer cache is sufficiently large.

   Here are some machine specifics for perspective.  It's an IBM x3400,
   2 Xeon 2GHz CPUs, 4Gb memory running RedHat.  It has 8 WD4000KS 400-Gb
   drives, 16Mb buffersize, 300 MBps transfer rate, Serial ATA-300, 7200 rpm.

   me% free
total   used   free sharedbuffers cached
   Mem:   19439481576708 367240  0 295304 947900
   -/+ buffers/cache: 3335041610444
   Swap:  20964723362096136

   me% cat /proc/meminfo
   MemTotal:  1943948 kB
   MemFree:689696 kB
   Buffers:394412 kB
   Cached: 461864 kB
   SwapCached:  4 kB
   Active: 500328 kB
   Inactive:   419836 kB
   HighTotal: 1179008 kB
   HighFree:   681396 kB
   LowTotal:   764940 kB
   LowFree:  8300 kB
   SwapTotal: 2096472 kB
   SwapFree:  2096136 kB
   Dirty: 512 kB
   Writeback:   0 kB
   AnonPages:   63836 kB
   Mapped:  24212 kB
   Slab:   321088 kB
   PageTables:   4436 kB
   NFS_Unstable:0 kB
   Bounce:  0 kB
   CommitLimit:   3068444 kB
   Committed_AS:   196428 kB
   VmallocTotal:   114680 kB
   VmallocUsed:  3304 kB
   VmallocChunk:   111332 kB
   HugePages_Total: 0
   HugePages_Free:  0
   HugePages_Rsvd:  0
   Hugepagesize: 4096 kB

   The default setup for read-ahead on the drives was 256 blocks.  I did
   some testing and found my sweet spot was 16k:

  root# blockdev --getra /dev/sda
  256
  root# blockdev --setra 16384 /dev/sda

   The default device scheduler was Completely Fair Queue:

  root# cat /sys/block/sda/queue/scheduler
  noop anticipatory deadline [cfq]

   CFQ is 1% faster than elevator for a single user.  I found a web link
   claiming that, in multi-user tests with 4 users, deadline had 20% better
   performance.  At boot time:

  echo "deadline" > /sys/block/sda/queue/scheduler

   All filesystems are ext3, mounted like so:

  rw,nodev,noatime,nodiratime,data=journal

   They have the largest journal size possible, 400 Mb.  In /etc/sysctl.conf:

  # Better write performance, avoids unnecessary paging.
  vm.swappiness = 10

   Ran a time test concurrently with 49 active Samba sessions:

  date
  touch -d yesterday /tmp/TIME
  # "list" holds 8 340-Gb filesystems, from 42-67% full.
  find $list -newer /tmp/TIME -print | wc -l
  date

   Results:

  Tue Dec  7 13:34:05 EST 2010
  541
  Tue Dec  7 13:39:40 EST 2010

-- 
Karl Vogel  I don't speak for the USAF or my company

Adam was a Canadian.  Nobody but a Canadian would stand
beside a naked woman and worry about an apple.  --Gord Favelle


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20101207191114.c5577b...@kev.msw.wpafb.af.mil



Re: Extremely large level 1 backups with dump

2010-12-06 Thread Karl Vogel
>> On Sun, 5 Dec 2010 19:15:25 -0800, 
>> Peter Tenenbaum  said:

P> After having some difficulty getting rsync to do exactly what I want,
P> I've become convinced to try rsnapshot.  I'll let you know how it goes.

   I'm interested in seeing what kind of grief you're getting from rsync.
   I've had to argue with it in the past; feel free to reply privately if
   you'd rather.

   Don't rule out dumb and strong, it works great for me.  On one of my
   servers, I do incremental backups hourly like so:

  cd /some/where
  find . -newer /some/timestamp -print > LIST
  ... [dork around with LIST]
  pax -rwdv -pe /else/where < LIST
  touch /some/timestamp

   This box has ~630,000 files using 640 Gbytes, but not many files change
   in an hour.  The find command above rarely takes more than a few minutes.
   If you leave out the pax, you'll have a list of recently-changed files
   which you could feed to rsync via the --files-from=LIST argument.

-- 
Karl Vogel  I don't speak for the USAF or my company

I would rather be exposed to the inconveniences attending too much liberty
than to those attending too small a degree of it.--Thomas Jefferson


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20101207033502.e12b7b...@kev.msw.wpafb.af.mil



Re: scripting question: to parse data with varname=value pattern the easiest way?

2010-11-01 Thread Karl Vogel
>> On Mon, 01 Nov 2010 15:49:01 +0800, 
>> Zhang Weiwu  said:

Z> A program output is like this:
Z>   result_01: a="23" b="288" c="A_string" ac="34"
Z>   result_02: a="23" b="28" c="A_string_too" dc="3"
Z>   

Z> I am writing a script to output values of b if b is in the result set.

   If your data is trustworthy and follows shell assignment rules like the
   example above, you can abuse sh/ksh/bash:

 #!/bin/bash

 sample='result_01: a="23" b="288" c="A_string" ac="34"
 result_02: a="23" c="A_string_too" dc="3"
 result_03: a="23" b="28" c="A_string_too" dc="3"'

 echo "$sample" | while read str
 do
 unset b   # or whatever you're looking for
 set $str  # will fail horribly if $str is empty
 result=$1
 shift
     eval "$@"
 test "$b" && echo "$result $b"
 done
 exit 0

   On the other hand, if someone sneaks something like
   result_04: dc="3" rm /something/valuable

   into your program output, you'll get a nasty surprise.

-- 
Karl Vogel  I don't speak for the USAF or my company

Most users (myself included) spend most of their time in front of a computer
in a kind of fuzzy autopilot mode, and anything that creates ripples on that
placid lake of unawareness is going to be noticed as a disproportionately
significant problem. --David Harris, creator of Pegasus Mail


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20101101210436.50fccb...@kev.msw.wpafb.af.mil



Re: see what files are touched by a program

2010-10-19 Thread Karl Vogel
>> On Sun, 17 Oct 2010 21:57:36 +0200, 
>> Steven  said:

S> Can anyone point me to a program that will let me know what files a
S> certain application touches? More importantly, writes to.  Something
S> like "filestouched vi filename" which would then report 'filename' as
S> being used.

   "strace" will do what you want, but it's awkward to use if this app is
   being called by something else.  The easiest way might be to use a
   small script as a placeholder for the application:

 you% mv /path/to/app /path/to/app.bin

 you% cat /path/to/app
 #!/bin/sh
 strace -e trace=open -o /tmp/x$$ /path/to/app.bin ${1+"$@"}
 grep -v RDONLY /tmp/x$$ > /tmp/app$$
 exec rm /tmp/x$$
 exit 1

   Running this using "vim" for the command and "stuff" for the filename
   gave me this trace in /tmp/app21656:

 open("/tmp/stuff.swp", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600) = 4
 open("4913", O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE, 0100644) = 3
 open("stuff", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0644) = 3
 open("/me/.viminfo.tmp", O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE, 0600) = 5

-- 
Karl Vogel  I don't speak for the USAF or my company
He'd make a lovely corpse.  --Charles Dickens


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20101020014828.c184bb...@kev.msw.wpafb.af.mil



Re: how to configure gcc

2010-09-30 Thread Karl Vogel
>> On Thu, 30 Sep 2010 09:20:36 +0530, 
>> Anand Sivaram  said:

AS> On Thu, Sep 30, 2010 at 09:12, Boyd Stephen Smith Jr. wrote:
B> On Wednesday 29 September 2010 15:18:46 abdelkader belahcene wrote:
   A> yes but normally gcc should be configured, where is the config file,

B> It's in the same place as the config file for ls, cp, and rm.  (There
B> isn't one.)

This is where the BSD version of make has an advantage over GNU make.
It checks for system-wide defaults in the file /etc/make.conf:

  me% uname -sr
  FreeBSD 6.2-RELEASE

  me% cat /etc/make.conf
  CPUTYPE?=pentium4
  CFLAGS= -O2 -pipe -funroll-loops
  COPTFLAGS= -O -pipe

AS> I think using an alias 'gcc -lm' is not a good idea.  It may be looking
AS> easier for this particular C file, but '-lm' would be linked always for
AS> even in the case of hello_world.c which is really unnecessary.

The additional linking won't do much besides take an extra millisecond
of time and add around 25 bytes to your binary; that's what I saw when
comparing on a Deadrat Enterprise system.  Build the executable both
ways, run "nm" and chop the first 10 characters to see for yourself.
The results should be identical.

You're right about the alias -- it works fine right up to the part where
someone changes their login shell or alias setup.  It's safer to use a
script as a front-end, so you can check for environment variables in a
global or user-specific config file:

  #!/bin/sh
  # front-end for make with preset preferences.
  export PATH=/usr/local/bin:/bin:/sbin:/usr/sbin:/usr/bin
  cbase='make.conf'
  for cfg in /etc/$cbase $HOME/etc/$cbase; do
  test -f "$cfg" && . $cfg
  done
  exec /usr/bin/make ${1+"$@"}   # Use full path just to be safe...
  exit 1

Under Linux, the config file looks like this:

  me% cat $HOME/etc/make.conf
  # Default values for make.
  export CC="gcc"
  export CFLAGS="-O2 -pipe -funroll-loops"
  export COPTFLAGS="-O -pipe"

Comparison:

  me% cat Makefile
  hello: hello.o
  hello.o: hello.c

  me% cat hello.c
  #include 
  #include 
  main()
  {
  printf("hello, world\n");
  #ifdef unix
  printf("unix defined\n");
  #endif
  exit(0);
  }

  me% make
  cc -c -o hello.o hello.c
  cc hello.o -o hello

  me% ./make   # using the frontend script
  gcc -O2 -pipe -funroll-loops -c -o hello.o hello.c
  gcc hello.o -o hello
  
-- 
Karl Vogel  I don't speak for the USAF or my company

Beauty is only a light switch away.
--Perkins Library, Duke University, Durham, North Carolina


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100930192027.79c5ab...@kev.msw.wpafb.af.mil



Re: root can't sudo

2010-09-28 Thread Karl Vogel
>> On Tue, 28 Sep 2010 09:42:40 -0400 (EDT), 
>> Stephen Powell  said:

S> I don't speak for the OP, but my guess is that the OP has a script that
S> he wants to be able to run either as his non-superuser self or as root.

   Easy.  This preserves arguments including spaces:

 #!/bin/sh
 PATH=/usr/local/bin:/bin:/usr/bin; export PATH
 test "`id -u`" -gt 0 && exec sudo $0 "$@"

 whoami
 for arg in "$@"; do
 echo "[$arg]"
 done
 exit 0

-- 
Karl Vogel  I don't speak for the USAF or my company

EXCUSE FOR GETTING TO WORK LATE #7:
The dog ate my car keys.  We're going to hitchhike to the vet.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100928185441.e2d39b...@kev.msw.wpafb.af.mil



Re: rsync issue

2010-09-12 Thread Karl Vogel
>> On Sun, 12 Sep 2010 18:30:59 +0200, 
>> Rodolfo Medina  said:

R> I wish to copy all my home directory into another machine with the
R> --delete option, but:
R> 1) I don't want hidden files, i.e.: `.*' to be copied;
R> 2) there are some symlinks, beginning with `.', that I want to be copied.

   Instead of copying everything and deleting what you don't want, why not
   make a list of the files you want copied and have rsync use that instead?
   Something like this:

   list=/tmp/list$$ # or use mktemp
   cd $HOME

   # Ignore hidden files and "." directory...
   find . -print | egrep -v '^(./\.|\.$)' > $list

   # ...but keep symlinks starting with a dot.
   find . -type l -name '.*' -print >> $list

   rsync --files-from=$list [other rsync options, destination, etc]
   rm $list

   You can add any other filtering you might want after the last "find",
   you *know* exactly what files are being synced, and you can store that
   list someplace in case there's ever a question of why something did (or
   didn't) get copied.

-- 
Karl Vogel  I don't speak for the USAF or my company
I have never hated a man enough to give his diamonds back.  --Zsa Zsa Gabor


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100913011305.475abb...@kev.msw.wpafb.af.mil



Re: Dumping terminal contents to a file

2010-09-08 Thread Karl Vogel
>> On Wed, 08 Sep 2010 12:52:05 -0400 (EDT), Alois Mahdal wrote:

A> I wonder if there's a simple and universal way to dump output of
A> terminal to a file, particularly for demonstration purposes.

>> On Wed, 8 Sep 2010 13:35:30 -0400 (EDT), Stephen Powell
>>  said:

S> Well, for recording a shell session, there is "script".  And to play it
S> back later, there is "scriptreplay". [...]  I don't know if that's what
S> you want, though.  script puts *everything* in the capture file,
S> including linefeeds, backspaces, ANSI escape sequences, etc.  For
S> example, colorized output from "ls" results in ANSI escape sequences.

   I use a wrapper called "saveon" which tries to correct the worst results
   from "script" putting everything in the capture file:

  #!/bin/sh
  PATH=/bin:/usr/bin:/usr/local/bin
  SAVEON=1
  export PATH SAVEON
  
  case "`whoami`" in
  root) prompt='root#' ;;
  *)prompt='me%'   ;;
  esac
  
  export PS1="
  $prompt "
  
  tmp=`mktemp /tmp/$tag.XX` || {
  echo "$tag: mktemp failed" >&2; exit 1
  }
  trap "rm -f $tmp; exit 0" 0 1 2 3 15
  
  sedscr='
  s/^.*script-is-done://
  s/^.*script-started-on://
  /Script started on /d
  /^me% *$/d
  /^me% exit$/d
  /^root# *$/d
  '
  
  echo "script-started-on:`date '+%a %b %d %T %Y'`" > $tmp
  script -c /bin/sh -a -q $tmp
  echo "script-is-done:`date '+%a %b %d %T %Y'`" >> $tmp
  col -b < $tmp | sed -e "$sedscr" > typescript
  exit 0

   * The date commands give me a consistently-formatted start and finish
 time at the top and bottom of "typescript".

   * The newline in the prompt cleanly separates commands from output.

   * "col -b" gets rid of at least some special characters.

   * The SAVEON environment variable lets me set programs to show colors or
 mess with terminal settings only when it makes sense to do so.  For
     example, my "dir" script looks like this:

  #!/bin/sh
  case "$SAVEON" in
  "") opt='--color=auto' ;;
  *)  opt='' ;;
  esac
  unset BLOCK_SIZE # throws off the results.
  exec ls -lF $opt ${1+"$@"}

-- 
Karl Vogel  I don't speak for the USAF or my company

You do not need a parachute to skydive.  You only need a parachute to
skydive twice.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100909020843.43f0ab...@kev.msw.wpafb.af.mil



Re: match across line using grep

2010-08-02 Thread Karl Vogel
>> On Mon, 02 Aug 2010 14:56:45 +0800, 
>> Zhang Weiwu  said:

Z> I'm grepping a bunch of files each have a segment code that executes a
Z> SQL.  My problem is that the query spans across several lines and I
Z> can't seem to make grep honor (?s) for that.

   Perl Is Our Friend.  Here's some text to search:

  me% cat -n sample
   1  Message-ID: <4c566c2d.7000...@realss.com>
   2  Date: Mon, 02 Aug 2010 14:56:45 +0800
   3  From: Zhang Weiwu 
   4  Organization: Real Softservice
   5  Status: RO
   6  Content-Length: 2410
   7  Lines: 80
   8  
   9  I'm grepping a bunch of files each have a segment code
  10  that executes a SQL.  Both selects should match:
  11  
  12  select * from table1 where id=1;
  13  
  14  select * from table2 where id=1
  15  and name='foo'";
  16  
  17  I tried to use -z parameter for grep, which the manual says
  18  would make grep not treating \n as line terminator.  But
  19  it doesn't work neither.  A simple test shows I might have
  20  misunderstood the use of -z:

   The script below my signature gives these results:

  me% ./pgrep 'select.*from.*;' sample
  [sample:12] select * from table1 where id=1;
  matched >>select * from table1 where id=1;<<
  
  [sample:15] select * from table2 where id=1
  and name='foo'";
  matched >>select * from table2 where id=1
  and name='foo'";<<

   "[sample:15]" means the match happened at or before line 15 in file
   "sample".  You can pass multiple files on the command line.  The
   "matched" stuff is there in case there's some distracting text on the
   line besides the select statement.  If you want matching to be
   case-sensitive, change "si:" to "s:" on the line where $pattern is set.

-- 
Karl Vogel  I don't speak for the USAF or my company

---
#!/usr/bin/perl -w
# Taken from perl-grep3.pl in "Mastering Perl"

use strict;

# Get the desired pattern, make newlines match '.' and ignore case.
my $pattern = shift @ARGV || die "I need a pattern\n";
$pattern = '(?si:' . $pattern . ')';

# Make sure pattern works.
my $regex = eval { qr/$pattern/ };
die "Check your pattern! $@" if $@;

# Use paragraph mode to handle newlines.
$/ = "";
my $line = 0;

while (<>) {
$line += tr/\n/\n/;
chomp;
print "[$ARGV:", $line-1, "] $_\n\t\tmatched >>$&<<\n\n" if m/$regex/;
$line = 0 if eof(ARGV);# reset counter for a new file.
}

exit(0);


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100802214030.a21b6b...@kev.msw.wpafb.af.mil



Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Karl Vogel
>> On Thu, 29 Jul 2010 01:04:27 -, 
>> Cameron Hutchison  said:

C>find $MAGDIR -iname '*.zip' -print0 | xargs -0 some-command
C> -iname matches names case insensitively. Since you then dont need grep,
C> you also dont need tr0.

   I need to think before posting.  I didn't mention that I have FreeBSD,
   Linux, and Solaris boxes, and unfortunately I can't guarantee the same
   access to GNU find.  I can install xargs if the system version doesn't
   recognize the "-0" option, so I usually end up scripting for the lowest
   common denominator.

-- 
Karl Vogel  I don't speak for the USAF or my company

Cute Celebrity Couple Names #6:
Lance Armstrong + Ivanka Trump = Armstump


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100729023745.d8a58b...@kev.msw.wpafb.af.mil



Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Karl Vogel
>> On Wed, 28 Jul 2010 23:58:11 +0200, 
>> Mart Frauenlob  said:

M> One might be better of with some like this:
M>   find /DIR -regextype posix-egrep -regex '.*\.(zip|ZIP)' -exec \
M> some_command {} +

   If the filelist is potentially too big for the max argument list on the
   system, I would do something like this:

 find $MAGDIR -print | grep -i '\.zip$' | tr0 | xargs -0 some command

   We have a ton of filenames with spaces and other crap, so "tr0" just
   replaces newlines with nulls:

 #!/bin/sh
 PATH=/bin:/usr/bin
 export PATH
     exec tr '\012' '\000'
 exit 1

-- 
Karl Vogel  I don't speak for the USAF or my company

Q. Why are New Yorkers always depressed?
A. The light at the end of the tunnel is New Jersey.   --Fredrick Homan


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100729003203.9667cb...@kev.msw.wpafb.af.mil



Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Karl Vogel
>> On 28.07.2010 14:42, Jochen Schulz wrote:

J> I think you meant to write
J> for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]`
J> Another hint: you don't need 'ls' for your case at all.

   I'd recommend keeping the "ls".  Try your script when MAGDIR doesn't
   have any zipfiles, and MAGFILE will hold the expanded value of $MAGDIR
   with the string "*.[Zz][Ii][Pp]" appended.  Bash, sh, and ksh all do
   that for some dopey reason, which is why I would do

  for file in $(ls $MAGDIR/*.[Zz][Ii][Pp] 2> /dev/null); do  ...

   if there's any chance that you won't find any files.

-- 
Karl Vogel  I don't speak for the USAF or my company

Love and respect for the great American experiment
in free government does not appear out of thin air.  --Larry P. Arnn


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100728180522.353a1b...@kev.msw.wpafb.af.mil



Re: Monitoring tools to use on an account

2010-07-28 Thread Karl Vogel
>> On Tue, 27 Jul 2010 17:53:40 +0100, AG wrote:

A> I'm facing a bit of a delicate issue: I have created an account on my
A> machine for someone staying with us, and I have strong suspicions that
A> he is engaging in on-line behaviour that he is not supposed to be doing.
A> Can anyone recommend a tool thatb I can install, that can monitor his
A> on-line activity - specifically sites he visits and how much time he
A> spends on them?

>> On Wed, 28 Jul 2010 11:05:30 + (UTC),  said:

C> If he has nothing to hide, all the steps will be tracked by the browser
C> history and cache files. Also, "/tmp" is a good bucket for holding
C> "shared secrets" (recent files, etc...).

   The problem is if he does have something to hide that the OP might be
   held liable for.  AG, if you're worried about browser activity, can you
   install squid on your system and change his proxy setting accordingly?
   This way he leaves a trace even if he sanitizes his browser cache,
   assuming he doesn't have root privileges.

   Another possibility - running tcpdump or the moral equivalent and
   checking the packet dumps periodically for anything hinky.  This way you
   catch any bad network activity, not just the browser.  Something like
   this at boot to avoid filling your entire drive:

   k=1
   while true; do
   out=/some/dir/dump.$k   # /some/dir owned by you, mode 700
   tcpdump -c 50 -w $out   # season to taste

   # check the dump for anything suspicious, remove it if clean
   tcpdump -r $out ... some filter here ... || rm $out
   k=$((k+1))
   done

   You might also change the permissions on "ps" so he can't see "tcpdump" or
   any other steps you might take.

-- 
Karl Vogel  I don't speak for the USAF or my company
If you can't be kind, at least have the decency to be vague.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100728175429.7333ab...@kev.msw.wpafb.af.mil



Re: Sed or awk: remove a line from a file

2010-06-03 Thread Karl Vogel

Here are some good pages on sed and awk one-liners:

  http://www.catonmat.net/blog/sed-one-liners-explained-part-one/
  Famous Sed One-Liners Explained, Part I: File Spacing, Numbering and
Text Conversion and Substitution
  Wed, 8 Oct 2008 03:00:00 -0400

  http://www.catonmat.net/blog/sed-one-liners-explained-part-two/
  Famous Sed One-Liners Explained, Part II: Selective Printing of Certain
Lines
  Sun, 21 Dec 2008 14:45:00 -0500

  http://www.catonmat.net/blog/sed-one-liners-explained-part-three/
  Famous Sed One-Liners Explained, Part III: Selective Deletion of Certain
Lines and Special Applications
  Wed, 14 Jan 2009 17:10:00 -0500

  http://www.catonmat.net/blog/awk-one-liners-explained-part-one/
  Famous Awk One-Liners Explained, Part I: File Spacing, Numbering and
Calculations
  Sun, 28 Sep 2008 01:00:00 -0400

  http://www.catonmat.net/blog/awk-one-liners-explained-part-two/
  Famous Awk One-Liners Explained, Part II: Text Conversion and Substitution
  Sat, 13 Dec 2008 04:25:00 -0500

  http://www.catonmat.net/blog/awk-one-liners-explained-part-three/
  Famous Awk One-Liners Explained, Part III: Selective Printing and
Deleting of Certain Lines
  Mon, 5 Jan 2009 10:00:00 -0500

  http://www.catonmat.net/blog/update-on-famous-awk-one-liners-explained/
  Update on Famous Awk One-Liners Explained: String and Array Creation
  Mon, 9 Feb 2009 10:25:00 -0500

-- 
Karl Vogel  I don't speak for the USAF or my company

If walking is so good for you, then why does
my mailman look like Jabba the Hut?  --bumper sticker


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100603003304.bb460b...@bsd118.wpafb.af.mil



Re: monitoring internet availability and sending sms alert?

2010-05-16 Thread Karl Vogel

http://www.hcst.net/~vogelke/src/ishostup/

These scripts are good for exactly one thing: sending me (or someone) a
message if a given piece of hardware at a given IP address stops responding
for more than a minute or so.  They rely on fping and regular email.

-- 
Karl Vogel  I don't speak for the USAF or my company
He kept saying I didn't listen to him... or something.  --Tritchen Smith


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100517014401.a0ca8b...@bsd118.wpafb.af.mil



Re: bash scripting question

2010-03-29 Thread Karl Vogel
Here's something I modified as part of a benchmark script called "fdtree".

-- 
Karl Vogel  I don't speak for the USAF or my company
Dijkstra probably hates me. --Linus Torvalds, in kernel/sched.c

#!/bin/bash
# How to use xdate/xtime/persec:
#
#  START=$(date "+%s")
#  count=10
#  xdate
#  tin=$(xtime)
#
#  # do something time-consuming $count times...
#  tout=$(xtime)
#  set $(persec $tin $tout $count); ttot=$1; results=$2
#  xdate
#  echo "TIME IN, OUT, TOTAL = "$tin, $tout, $ttot
#  echo -e "\tWork per second = " $results

PATH=/usr/local/bin:/bin:/usr/bin
export PATH

function xdate
# Display the date in this form: Thu, 10 Sep 2009 21:22:06.494
{
set $(date "+%a, %d %b %Y %T %N")
ms=$(echo $6 | cut -c1-3)
echo "$1 $2 $3 $4 $5.$ms"
}

function xtime
# Display elapsed runtime to the millisecond.
{
set $(date "+%s %N")
sec=$(($1 - $START))
ms=$(echo $2 | cut -c1-3)
echo "$sec.$ms"
}

function persec
# args: start-second, finish-second, count-things
# returns elapsed time and things that happened per second
# to the millisecond.
{
start=$1
finish=$2
count=$3

if test "$finish" = "$start"; then
echo "0 0"
else
echo $(echo "scale=3; $finish-$start;
$count/($finish-$start)" | bc)
fi
}

function dbg
# debugging prints
{
test $DEBUG -gt 0 && echo -e "$@"
}

tmp=/tmp/t1$$
tmp2=/tmp/t2$$

xdate
START=$(date "+%s")
tin=$(xtime)
echo

for k in 1 2 3 4 5 6 7 8 9 10
do
# Read a short amount of random data.
dd if=/dev/random of=$tmp2 bs=1k count=1 2> /dev/null

# Duplicate it a bunch of times.
cat $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 > $tmp
cat $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  > $tmp2
cat $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 > $tmp
cat $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  > $tmp2
cat $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 > $tmp
rm $tmp2

# Generate a hash.
md5sum $tmp
ls -l $tmp
rm $tmp
done

echo
count=10
tout=$(xtime)
set $(persec $tin $tout $count); ttot=$1; results=$2
xdate

echo "TIME IN, OUT, TOTAL = "$tin, $tout, $ttot
echo -e "\tWork per second = " $results
exit 0


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100330012125.34bebb...@bsd118.wpafb.af.mil