DæmonNews: News and views for the BSD community

Daemon News Ezine BSD News BSD Mall BSD Support Forum BSD Advocacy BSD Updates

The Answer Men

Gary Kline, David Leonard, and Dirk Myers

Greetings, salutations, and New Years best from your faithful Answer Team.

This column addresses its usual wide variety of questions. Most are directed at the newer BSD user...but even long-time users are not current on the hows and whys of using grep. Or would rather not invest the hour or two to figure out how to get locate updating its database daily instead of weekly.

If you understand the difference between the cua and tty /device files, then you may be well ahead of the majority of us BSD'ers. We make no pretense at being profound; instead we attempt to answer questions and de-mystify the idea that "Unix is so impossibly hard that it is only for the hard-core nerd".

So settle back, take a twenty-minute break, and see what we did with the following six questions.





Q1) Whenever I use grep to find a pattern over several directories, for example:
    $ grep pattern  * */*  */*/*
sometimes grep finds a binary file and the output will destroy my display. Is there any way to keep this from happening?

A. To skip binary files altogether, just use the -I flag.

Another thing to mention while we're here is that the -r flag will recurse through directories, so there's no need to use * wildcards to descend through directories. Combining these tips, the command you want is

    $ grep -Ir pattern  *




Q2) What's the right way to change how often one of the daily-weekly-monthly cron scripts runs? I'd like to change the locate program to run every day rather than once a week. My files change too often and I'm tired of using find! Also, how do I get locate to stash my /home/<user> files in the database?

A. In FreeBSD, changing when any periodic script task runs is just a matter of moving the NNN.<function_filename> file to the /etc/periodic directory that has the frequency you want and updating /etc/periodic.conf. Within each directory, these scripts are run in lexicographical order, so you can adjust the order within one of these directories by changing the NNN number on the scripts.

To have cron run update the locate database daily instead of weekly, move /etc/periodic/weekly/310.locate to /etc/periodic/weekly/350.locate and copy /etc/defaults/periodic.conf to /etc/periodic.conf. Then, edit /etc/periodic.conf, and insert the 350.locate entry within the daily listing. (You don't have to change the variable name weekly_locate_enable unless you really want to!)

To get locate/updatedb to include your home directory instead of the default paths, edit /etc/locate.rc and uncomment the section that reads

# directories to be put in the database
#SEARCHPATHS="/"
Add your home directory to this section, for example:
# directories to be put in the database
SEARCHPATHS="/ /home/user"

OpenBSD:

Perhaps the cleanest way to make locate run nightly is to edit /etc/weekly, and comment out the block of shell script that rebuilds the locate database.

Next, make a new file /etc/daily.local (note the '.local' suffix) and copy into it that same shell script you just commented out! The daily.local script will now be run by the system daily (it gets called from /etc/daily).

To change which paths are scanned for the locate database, edit/create the file /etc/locate.rc as explained above

If you want to understand this in more depth read the manpages on locate(1) and locate.updatedb(8).




Q3) What's the best way to run my FreeBSD cvs ports-supfile script every night? Every other night?

A: Unless you have something especially complex in your cvsup script, adding the following to /etc/crontab should do what you want:

# update /usr/ports at 4 AM daily.
0 4 * * *   root \
	/usr/bin/cvsup -g -L 2 -z /usr/share/examples/cvsup/ports-supfile \
	| mail root

Of course, this assumes that you've configured your supfile &emdash; replacing the string CHANGE_THIS with a valid host, for example.




Q4) Over the past couple of years I've installed lots of ports on my FreeBSD system and am thinking about upgrading to the latest versions. Can you compare the pkg* utilities and portsupgrade programs and help me get started? I'm wondering if some things are better left as-is?

A. You may be right with that last thought: if something works well now, then why change it? Sometimes it makes sense to have the latest revision. With open-source software, newer code usually means better operation, more bug fixes, and a more robust and secure system overall. In particular, if you're aware of a security update or stability improvements for a program, it may be well worth the effort to change to the newer version. Other times, though, you may find that the changes between versions are minor improvements or ports to new platforms. In those cases, there should be very little difference between versions, so there's not much reason to upgrade.

For an introduction, we'll demonstrate both pkg_version and portupgrade.

An easy way to check simple ports is to use:

$ pkg_version -c >/tmp/uplist.sh

Review /tmp/uplist.sh, and edit the script until it makes sense for your situation. For example, you may not want to install a particularly large port, and you may not want to update ports that have only minor changes.

Once you're happy with the script, run it:


sh -x /tmp/uplist.sh >  /tmp/upgrade.output.

Depending on whether or not you run into dependency problems with pkg_version -c, you may want to use portupgrade. The manual page for portupgrade is clear and concise, so be sure to check it out. To summarize the man page, though, if you've found that your version of ctags is out of date, the following command will automatically update the port:


cd /usr/ports/devel/ctags; portupgrade ctags




Q5) Can you tell me how to display the Latin-1 character set on my screen? I don't care so much about how to create the iso-8859-1 characters (yet), but mostly just how to have them show up?

A: To display the Latin1 characters on the console, all you need do is add the following three lines in your /etc/rc.local. (Or /etc/rc.conf.)


font8x16="iso-8x16.fnt"
font8x14="iso-8x14.fnt"
font8x8 ="iso-8x8.fnt"

Then in your shell initialization or run-command configuration file-- ".rc" file, say your ~/.profile or ~/.bashrc or ~/.zshrc-- add these three lines:


setenv  LESSCHARSET latin1
setenv  LC_CTYPE us_EN.ISO_8859-1
setenv  MM_CHARSET ISO-8859-1

Obviously, replace the "en_US" with your own ISO code.; likewise with the 'MM_CHARSET' if you would use any other ISO code, iso.8859-2, for example.

To create any of the Latin-1 set if you are running X11R6 and xterm:
To get your alt key to create e-aigu by typing i+ALT, you'll need to modify the way that the X Window System maps your keyboard. First, you'll need to run xmodmap from your shell initialization or run-command file. For example, if your name is John Q. Smith and your home account is /home/jqs, add the line:

/usr/X11R6/bin/xmodmap /home/jqs/.xmodmaprc
Next, create the file
/home/jqs/.xmodmaprc
The file should contain the following key mapping:

!
!! adding key re-mapping definitions to turn Alt Left
!! and Alt Right keys into META keys.
!
keycode  64 = Alt_L Meta_L
keycode 113 = Alt_R Meta_R

After you have sourced (activated) your initialization or rc file, pressing ALT+i should give you é.

It is probably worth mentioning the following if you are running X11R6, an xterm, and have a Sun or DEC keyboard with a "Compose" key.

The Compose key is handy for generating many of the Latin1 set. For example, to generate an à (a-grave), press Compose, then type 'a' followed by '`'. Some others:

ö     o "
ø     o /
î     i ^
é     e '

(Can you say, 'ASCII is passé'?)



Q6) Can you discuss the difference between /dev/cua?? and /dev/tty?? ?

A. The story goes like this: people desire to be able to login to their computer using a modem. They plug the modem in, and it is configured so that when DCD (carrier detect) is low, the tty is usable; when the modem hangs up, the tty closes and is inaccessible.

This is all very fine and is what is expected, however, sometimes you also want to be able to call out using the same modem that is waiting for an incoming call. The problem is that the tty is 'inaccessible' when the modem is hung up! (It is waiting for a call.) So, either you do tricks with stty and lock files and so forth, or you use the 'cua' twin device which looks just like a tty except that when the modem is hung up, the cua is available so you can send AT commands to your modem. When the modem is being used, the cua device appears busy.





About the Authors

Gary Kline has been porting code since the late 1970's. When he isn't hacking code, he's hacking prose or pretend poetry, or listening to jazz radio and slurping down espresso.

For four years he has been writing the software equivalent of a mind-machine, dubbed Muuz, and has already released some alpha code for FreeBSD. Check the FreeBSD ports tree if you are interested. A new release in due in the first quarter of the new century...with luck!

His most recent adventures include an ISDL link to the net, including the thrills of learning about the Domain Name System, network and mail administration. Since late in '01 web design--including TABLES and which color do and do not go together--have grabbed his interest. Whether or not you are brave...you have been cautioned!

[home|mail]

David Leonard is a PhD student in the Department of Computer Science and Electrical Engineering at the University of Queensland, Brisbane, Australia.

His area of research is QoS-adaptive component software architectures, and in his spare time is a developer for the OpenBSD project. That said, David enjoys living the quiet life with his wife, Kylie and cat, Mu. He especially enjoys frequenting Moreton Bay's many fabulous places to eat. Mmmmm!

[home|mail]

Dirk Myers does things with words, perl, and Unix.

[mail]

Google
Web daemonnews.org

More Articles
  • Interview with Jan Schaumann
  • Interview with Theo de Raadt
  • Book Review: Virtualization with VMware ESX Server
  • Editorial: Not Quite Dead Yet
  • The Design of OpenBGPd
  • Interview with der Mouse
  • Letter to Steve Jobs
  • Interview with Manuel Bouyer on Xen
  • Apple and Open Source
  • BSDCan 2006
  • BSD Certification Survey Results
  • Lab in a Box
  • Ike Notes on BSDCan 2005
  • BSDCan 2005 Photos
  • FreeBSD Developer Summit Pictures

  • Advertisements




    Author maintains all copyrights on this article.
    Images and layout Copyright © 1998-2006 Dæmon News. All Rights Reserved.