What is it?
DJGPP is a collection of UNIX-like tools for DOS/Windows that has been ported from the GNU project. For a better understanding of what we mean by UNIX-like, see gnu.org. We’ve found DJGPP indespensible for tweaking files for automated installs from the command prompt. With this version you can run the utilities from DOS, Windows95/98, or NT. With csdpmi (in v2misc), you can even create a bootable DOS floppy with your favorite utils for hacking files to get a system back up. This distribution is more feature rich than the commands that come with the resource kit, and DJGPP is free. Commands like du give you much more useful info, and piping to less rather than more is a must! A full version of perl is here too. Even if you aren’t familiar with the UNIX toolset, it might be worth it to start here. There are a lot of other good UNIX tools for NT that are coming out now, check out our Interoperability section in web links for more info.
Obtaining it:
Just find an ftp site. We use cdrom.com. There are other sites listed at Delorie.com. Start with the utilities in v2gnu. Most of the files you will need are in this directory. Just download the xxxb and xxxd files. The xxxs files are only needed if you want to recompile the utilities. GNU has published a book that has both the utilities on CD-ROM and usage documentation. Click here to buy this from Amazon.com.
Installing it:
Extract the zip files to C:djgpp (a good choice).
Add c:djgppin to your path.
Using it:
Note: We have tested these successfully on NT command prompts with DJGPP. The problem is the syntax is a wee bit different between DJGPP and other *NIX OSs. DJGPP is built on the same GNU stuff that Linux is, but there are some peculiarities due to the different platform. To make things worse, a lot of the perl and *NIX scripts we have sprinkled throughout netadmintools were developed and tested on our Linux workstations.
For logon scripts and html pages, these utilities are most wonderful:
Perl the fabulous Swiss Army Knife of utilities. (For more info on perl, check out Our Perl Articles).
perl -pi.bak -e "s|wordtofind|replacewithword|g" *.htm
will replace all instances of a string with another — for all files in the current directory. The .bak is the extension of the backup files of all changed docs. It might also be prudent to copy all files you are hacking to another location. Notice that vertical bars were used instead of the normal ‘/’. This lets you use slashes in your search and replace sections. Of course, html is full of slashes.
There is a utility that comes with perl called s2p (sed to perl) that we used to generate this perl script: remlns.txt. Whenever we want to remove particular lines from all pages, we can use this script to do so.
The key part is:
if (/text1|text2/) {
$printit = 0;
next LINE;
}
Just put the different things you want to search for in text1 or text2.
If you then type: perl -i remlns.txt *.html
All lines on all .html files that contain text1 or text2 will be deleted.
Grep is good for finding where this stuff exists:
grep "wordtofind" doctosearch
You can use a * for doctosearch to look through all docs in the current directory.
With find and xargs, you can list all instances of a text string in a
collection of files and even travel down the directory tree:
find -name '*.htm' | xargs grep "searchstring"
Transporting it:
When you are happy with the collection of files you have, just go to a command prompt, cd to djgpp, and (assuming you have tar and gzip) and type:
tar -cz * --file=myfavorites.tgz
You can then expand this on any machine you like by typing:
tar -xzf myfavorites.tgz.
You might want to put a different path down the parent part of the tree in front of the filename when you create t he archive so you don’t tar up the tar file too!
The less command is very useful:
dir | less
You are probably already familiar with dir | more, but with less you can scroll up and down. Just hit q to exit.
Getting help:
Most of the commands will spit out limited help with –help as the only argument. There are also a lot of help files in gnudocs.
Anyway, play around (on your personal workstation, of course). When you are comfortable, you can edit batch files, logon scripts and unattended installation scripts with ease, among other things.