Cron job and shell script

I joined DH to find a semi-permanent home for my genealogy research. As part of that, I use a program called GED2HTML which will generate HTML files from a GEDCOM file (a standard genealogical data format). There is a Linux ELF version available which I have downloaded and successfully run from within a DH SSH session.

That being said, I’d like to setup a cron job that can automatically rebuild my pages anytime I upload a new GEDCOM file. The biggest problem seems to be that GED2HTML creates lowercase links within a given document’s HTML file, but the files themselves are created with uppercase names… I’ve cobbled together the following shell script which I think should work as follows:

  1. Go to the directory where I would upload a new GEDCOM
  2. If there is no GEDCOM there with the correct name do nothing; otherwise
  3. Go to the destination directory for the new files and copy everything there to a backup directory
  4. Go back to the GEDCOM directory and run GED2HTML, sending the output to the destination directory
  5. Rename all files in the destination directory to lowercase
  6. Delete the GEDCOM file used to create the HTML files

Here’s the script:


cd $gedhome
for GEDCOM in .
if [ “$GEDCOM” = “$myGED” ]
cd $destdir
for FILES in .
mv -f $FILES "$gedhome/backup"

cd $gedhome

umask 022
./ged2html -f options.g2h -D DESTINATION_DIRECTORY="$destdir" $myGED
cd $destdir
for FILES in .
DEST=$(echo $FILES | tr A-Z a-z)
if [ “$DEST” != “$FILES” ]
mv -f “$FILES” "$DEST"

umask 077
rm '$gedhome/$myGED’
[/code]Any “gotchas” that would prevent this from working as a cron job? Any suggestions for optimizations (I’m sure there’s some)?

Looks ok on a quick glance; your best bet is to test the script and get it working the way you want… then set it up as a cron job.

above the cron job will help make sure you get any errors;

[quote]for GEDCOM in .


Note that “.” is usually redundant. You can probably just use:
You may want to direct stdout to a logfile (or to /dev/null, especially once things are working), but direct stderr to a different logfile and / or have errors mailed to you.

In any event, this looks like a good start - I’d just get the script running the way you want it and set it up as a cron job.

OK, I think I’ve got things working for the most part…

[quote]Note that “.” is usually redundant. You can probably just use: *


Yes, that works (’*’). Coming from a non-UNIX background, I have . ingrained into my being that that’s what you use to select every file in a directory…

Also had problems with using $HOME until I determined that variable substitution does NOT happen inside single-quoted strings (e.g. ‘$HOME/bin/myscript’), but it DOES occur in double-quoted strings (e.g. “$HOME/bin/myscript”).

… Next newbie type question then… Is there anyway to use something besides vi when trying to add something to crontab (I’m trying to use crontab -e as the cron job KBase article suggests – I’ve tried setting VISUAL and/or EDITOR environment variables as man crontab suggests to ‘pico’, and I’ve also tried aliasing ‘editor’ to ‘pico’ in my .bashrc, but to no avail…

Any suggestions?

This has always worked properly for me in the past. What’s the output of:
% echo $VISUAL
– are you sure the environment variable has been set? Also note that you use different syntax to specify this in Bourne compatible shells (sh, ksh, bash, zsh) than with C shells (csh, tcsh).

Since you almost definitely want to use pico with the ‘-w’ switch, and since setting $EDITOR or $VISUAL doesn’t seem to work with quoted strings, you might try:
alias pico=“pico -w” (or the equivalent for your shell), and then set VISUAL to ‘pico’. This worked for a co-worker of mine.

If you’re still having problems with this, send a support message or send me a message on the forum with your username and machine, and I’ll take a look at it.

Of course, you can also simply:

  1. learn how to use vi :>
  2. edit your cronfile in your preferred editor; save it to a file, and then type:
    crontab cronfile
    (where cronfile is the name of your cron file; ie .crontab).

Well, here’s what I get:

[frigga: ~] [08:56:07]$ echo $EDITOR pico [frigga: ~] [08:56:11]$ echo $VISUAL pico [frigga: ~] [08:56:17]$ alias alias cls='clear' alias dir='ls -AlFhX --color=auto' alias editor='pico -w' I’ve set both $EDITOR and $VISUAL in my .bash_profile – if I didn’t do that, then both echos return a nullstring

[quote]1) learn how to use vi :>


Ummm, I’ll pass on that for now – at the risk prompting a flame war, ‘been there, tried that, don’t want to try it again!’

[quote]2) edit your cronfile in your preferred editor; save it to a file, and then type:
crontab cronfile


Yes discovered that worked as well. It’s no big deal to edit a cronfile; it would just be nice to edit the crontab in place (therefore, if you want to take a look at gilkison on frigga, be my guest!)

you needed to change:
export VISUAL=pico

went ahead and left the change in your ~/.bash_profile

ps - i’d still suggest doing:
alias pico="pico -w"
export VISUAL=pico

or something similar. you don’t want to accidentally wrap lines in a crontab.

If you don’t want ‘-w’ all the time, you could do:
alias wpico="pico -w"
export VISUAL=wpico

that’s untested, but I think it will work.

pps - i’m going to hold my tongue w/r/t your vi comment :>

Sorry, my copy of “UNIX for Dummies” didn’t cover the ‘export’ command in BASH (then again, it is only the Quick Reference edition from 1995).

Some experimentation shows that I need to do:

alias pico="pico -w" export VISUAL="pico -w" for nowrap to be available in both regular invocation of pico and via crontab -e; the export command apparently doesn’t expand any previously defined aliases? For the same reason, I presume, your wpico suggestion, while a good one, was ineffectual; thus defined, crontab -e will return:

/bin/sh: wpico: command not found crontab: "wpico" exited with status 127 I’ll also try my best not to disparage vi anymore, lest my accounts get revoked! ;]

hrmm – a co-worker did it the other way, but he was using tcsh… we couldn’t get VISUAL to take a quoted string, but it would expand an alias.

anyway, glad that’s working now.

i’m not a total expert on this, but I believe the difference when you use EXPORT is that the variable is passed on (exported) to subshells (and to your environment).

jazz% bash
[william@jazz]$ FOO=blah
[william@jazz]$ echo $FOO
[william@jazz]$ bash
[william@jazz]$ echo $FOO

[william@jazz]$ exit
[william@jazz]$ export FOO=blah
[william@jazz]$ bash
[william@jazz]$ echo $FOO

Note that in the bourne shell you can’t use this syntax:

bacall% sh
$ export FOO=blah
FOO=blah: is not an identifier
$ FOO=blah ; export FOO
$ echo $FOO