Greg's Tech blog

My technical journal where I record my challenges with Linux, open source SW, Tiki, PowerShell, Brewing beer, AD, LDAP and more...

grabbing a single line of command output

Saturday 10 of January, 2004
grabbing a single line of command output

I wrote this Windows script (batch file) to grab a single line of output from a command


set /a max=1

typeperf "\memory\Pages/sec" -f csv -sc 1 -o c:\temp\1.tmp -y

for /f "usebackq skip=1 tokens=1*" %%a in ("c:\temp\1.tmp") do (

call :onlyone %%a%%b)

goto :eof


set /a counter = NaV + 1

if /i NaV gtr NaV goto :EOF

echo %* >>c:\temp\2.tmp

goto :EOF



The for command reads the file line by lines and calls only one with parameters.
:onlyone does something (in this case echo), then increments a counter to keep track of how many it has done then returns
Next time onlyone is called the counter = max, so it returns without doing anything

Note: tried to execute typeperf from within the for command but the command must write directly to the screen on a non-line oriented mode. For could not capture the output correctly

Setting Linux Time

Monday 05 of January, 2004

Running gnome on Linux2 and the time was off. I tried to use gnome to set the time but it said no program was configured to change time. I don't get it.

Found a nice discussion on the clock here (cache)

Needed to use hwclock. Here are the commands

hwclock set date hh:mm:ss (to set the time)

hwclock --localtime (tells linux the rtc is set to local time)

hwclock --hctosys (to set system time from hwclock)


Smarthost Relaying

Friday 28 of November, 2003

in my last post I spent a lot of time discussing how to install SASL and configure Sendmail to do SMTP AUTH.
I was confusing smartthost authentication with user authentication. I found an article on comp.mail.sendmail
that hinted to the problem and directed me to the sendmail README in /usr/share/sendmail/cf/

All I needed to do was

  • configure the sendmail smarthost

    • in gmartin.mc


  • tell sendmail where to relay mail

    • configure access.db to tell sendmail how & where to store access information.

FEATURE(`access_db', `hash -T<TMPF> /etc/mail/access')dnl

  • modify access.db
    • Edit /etc/mail/access
    • Add the login info:
    • Authinfo:outgoing.verizon.net "U:vze1jt1m" "I:vze1jt1m@verizon.net" "P:xxxxxx" "R:outgoing.verizon.net" "M:PLAIN"
    • Rebuld access.db

makemap hash access <access

Note: The other entries in access.db are the hosts to accept as relay hosts

Sendmail, SASL & Smarthost

Tuesday 25 of November, 2003

We need to start forwarding mail through verizon because sites like AOL are not accepting mail from mail servers on
soft-links(based on IP range). I started researching this and found that first I need:

  • SASL version of sendmail
  • sendmail configured with a smarthost
  • sendmail configured to do SMTP Auth

SASL & Sendmail

Found this page that lead me down the right path (cache)

So I downloaded SASL and followed the instructions to build it, but received and error during 'make':

"kerberos4.c:49:17: krb.h: No such file or directory "

This was resolved by modifying the ./configure step. I used this command-line based on a a link to
http://www.irbs.net/internet/info-cyrus/0207/0196.html (cache):
./configure with-saslauthd=/usr/lib/sasl2 enable-cram \

enable-digest enable-plain disable-anon disable-gssapi \

disable-krb4 disable-otp --with-openssl

Sendmail 8.12.10

Next I had to compile Sendmail. Based on the sendmail book I ran
./Build -c -n (create clean build, no make)
./Build -c
./Build install
Then I restarted sendmail and all was well
(Actually, I received an error:
"libsasl.so.7: cannot open shared object file: No such file or directory"
At this point I remembered that my SASL build had an error which I resolved and documented above).
Never stop in the middle of something!

Sendmail and SMTP AUTH

Useful links:
http://dbforums.com/arch/181/2002/12/574316 (cache)

Still not getting AUTH from EHLO command

Printing Exchange Distribution List Members

Thursday 15 of May, 2003
HOWTO Print Exchange 5.5 Distribution List Members

We had a need recently to print the contents of an Exchange 5.5 distribution list. We've looked in thre past for a tool to do this and never had any luck.
I found a python script that did this and since I don't know python(yet), I converted it to vbscript. Run the script (cscript getmembers.vbs) to see the Usage.
You'll need ADO & ADSI installed locally. E-mail with questions/bugs. Let me know if it works for Exch2k

I hope you'll find this of value. (save as getmembers.vbs)

'getmembers.vbs - Greg Martin - CSC May 2003
'If you use this regularly, you can define sUser & sPwd with a user from your local site
'Run with cscript to prevent a gazillion pop up windows

dim oIADs
dim MyContainer
dim objRecipients
dim item

CRLF = Chr(13) & Chr(10)

sUsage =    "Getmembers.vbs - Greg Martin, CSC  2003" & CRLF & CRLF
sUsage = sUsage & "Returns the entries of an Exchange distribution list and nested lists" & CRLF
sUsage = sUsage & "Usage:  cscript getmembers.vbs      " & CRLF & CRLF
sUsage = sUsage & "Where:" & CRLF  
sUsage = sUsage & "Servername is the name of an exchange server" & CRLF  & CRLF
sUsage = sUsage & "Listname is the alias of the list to be enumerated" & CRLF   & CRLF
sUsage = sUsage & "UserDN is the DN of an exchange user(used to login via LDAP)" & CRLF 
sUsage = sUsage & "Note: User DN typically looks like 'cn=alias, ou=site, o=org'" & CRLF
sUsage = sUsage & "      Specifying the recipients container is not necessary and does not work" & CRLF &CRLF
sUsage = sUsage & "Password is the password for user" & CRLF  & CRLF
sUsage = sUsage & "1 Recurses list members. 0 does not recurse (optional - must be supplied if CN|UID id specified) " & CRLF  & CRLF
sUsage = sUsage & "CN prints Exch CN of list member; UID prints Exch alias (optional)" & CRLF & CRLF
sUsage = sUsage & "Example: cscript getmembers.vbs Rosnt47 " & chr(34) & "cn=tcs_users,cn=Distribution_
Lists,ou=ets,o=ets" & chr(34) & " " & chr(34) & "cn=juser, ou=ETS, o=ETS" & chr(34) & " p@ssw0rd 1 CN" & CRLF & CRLF

Set oArgs = WScript.Arguments

Tikiwiki 1.6 upgrade

Saturday 26 of April, 2003

coolHey, we upgraded the site to TikiWiki 1.6 back two weeks ago. A couple things to note. Pages (actualy templates) are compiled on first use. This speeds up access. However, it broke the Admin page. Had to grant php rights to use 32MB and 120 secs of run time. The Admin page is by far the most complex. After that compile, all was well and we're back to 24MB & 30 seconds


Mailman running as the wrong user

Saturday 08 of March, 2003

Mailman errors
Had a problem posting to mailing lists. It would return an error saying the script ran as the wrong user.
The answer was adding 'mail' as the default user in sendmail.cf


Mailman URL Info

Monday 24 of February, 2003

Resetting URL for a mailing list

From the /usr/local/mailman/bin directory

'./withlist -l -r fix_url MOC -u www.gmartin.org'

(where MOC is the listname
and www.gmartin.org is the new URL)

Check it using bin/dumpdb ../lists/moc/config.pck

Look for web_page_url near the end of the dump


Saturday 22 of February, 2003

I loaded phpMyAdmin to manage MySql. Very slick

software: /usr/local/phpMyAdmin
link: /var/www/htdocs/dbAdmin
URL: /data

Directory is locked down using .htaccess


SNMP Trap daemon

Tuesday 04 of February, 2003

SNMP trap daemon:

./snmptrapd -P -F "%02.2h:%02.2j TRAPNo value assignedq from %A: %v \n" /var/log/snmp.log &