The pup_save file. That's where your operating system is, (for frugal users). It's the file you really want to keep free of errors. It's also the file most susceptible to errors.

A primary obstacle is; we can only safely check and repair filesystems when they are not mounted. The pup_save file gets mounted early in the boot process.

Moreover, over the last several releases, Barry has implemented various techniques for dealing with this. Considering the changes, I can't come up with a one solution.

Version 4.00 did the e2fsck automatically, people complained it was taking too long.

On newer versions, I've noted a variable which can be set puppy pfix=fsck

From the way I read the forum, most people are probably using a version with this variable. From that standpoint, maybe there isn't even a problem to solve.

I have no desire or intention of running Puppy or any Linux on filesystems with errors, so, if I were the admin over Puppy computers, I'd put the pfix=fsck line in GRUB.

The other partition of importance is the pup_save host partition. I modified my init to remove all checking of the pup_save file and set it to check the host and the pup_save file before anything of consequence occurs. Code excerpt to follow:

I prepare these posts with Puppy's excellent outliner 'notecase'. Notecase allows multiple instances of itself. It also allows multiple instances of the same file.

To make things easy, I have a shell script called tui to open notecase with tui.ncd also loaded. Problem is notecase can open more than one tui.ncd and I can damage a document by editing a document open elsewhere.

I wish to demonstrate in this chapter how we can be assured we only have one instance of file open, using conditional checking and branching.

Remember how we can uses grep's exit code to verify conditions? We'll do it again here.

Notes:
/dev/null is a mysterious black hole where things disappear forever and ever. You've see me use it before, now you know why, I don't want to see the output.

grep -v grep is saying: do not show any lines containing grep. problem is ps shows all processes, when we ran 'grep tui.ncd', which is a match, it became a process and we need filter it out with the -v switch. now we won't have a false positive.

The last argument in our pipe chain is the exit code which will be used. If 0, then tui.ncd is already running, (a true condition) we print a message and the shell having nothing else to do exits at the end.

else is a false condition, but that's not why it executes commands. It runs commands because nothing else did, (if that were the case).

If else runs, we start notecase tui.ncd with the & key to put it in the background so we can have our prompt back.

Assignment - Nothing to do with this code except understand it - if you want, modify it and come up with something useful for you.

The code in this chapter is unique, you might have to pay very careful attention.

First

I want you to be able to easily open .bashrc, edit it and source it. Here is the command I want you to copy and paste:
alias ea='mp /root/.bashrc ; source /root/.bashrc'

Notes: if you don't like mp, use another editor. Also, when using spaces in your .bashrc file always use ' after the = and ' at the end of line.

ea means 'edit alias'

Second

Copy and paste this command to .bashrc;

alias rf='source /root/.bashrc'

This will easily re-source an existing instance of bash. Suppose you have five instances open and change one. The other four need sourced again.

Third

Remember, we can change directories with aliases. I can type usrbin faster and easier than I can type cd /usr/bin.

I now give you a script which will add change directory aliases from the command line, without the need to open .bashrc and edit it. I call the script acd for auto change directories

To use, simply type acd + the name of the shortcut you want- when you are in the directory you want to add a shortcut to.

Example: when in /root/.mozilla, you can type acd .mozilla and your shortcut is added. You no longer need to type cd /root/.mozilla. Just type .mozilla Then use 'rf' to activate it in the current shell. Otherwise, it will activate next time you open it.

Forth

Using colors: I gave you colors to work with, this is the first script where I added colors. If you didn't install colors, then you must change the cecho to echo. If the colors are not to your liking you need to modify them

As a part of our computing tasks, we often want to jot down a few notes. With the GUI, this might involve opening a text editor, making our notes, saving changes and closing.

This task can be made much easier with a simple script, considering command line users often have the emulator open at all times.

For purpose of this chapter we will call our script note.

Code:

#!/bin/bash
cat >> /root/my-documents/note.txt

That's an easy enough script. When done jotting the notes, hit ctrl+d to close note and save your changes.

Like many, if not most scripts, they can be enhanced with features added, we'll do it.

Some scripts we plan to distribute, they need to have maximum portability. As a rule, we want all our scripts to be as portable as is reasonably possible. But for ourselves we might do non conventional things to make them easier.

In this case, if I type note and any character it brings up a menu. For example:

We've seen examples of nesting loop and if statements. Here we see an example of nesting a function.

Reinforcement: Bash reads from top to bottom. We must read the function before calling it. This is why main is at the bottom and in the case of the nested function, it is read before called.

Sometimes we want to take notes without giving someone an opportunity to read over our shoulder. I included functionality to lower contrast. My background is black so I used black. If you want to use this script, you may need to modify these colors according to your background.

If you didn't install cecho, well, modify the script accordingly.

Typically our terminal is black with a light gray text. With Puppy it might be a white bg with a black fg.

I like colors for their own sake. Also, I think colors can give a nice finished look to our scripts.

In this script I've used 'dialog' for some of the options. But, I haven't taught dialog yet. I would like to emphasize dialog is not a graphics program. Everything you are looking at in dialog is text.

See how you like the command line note utility, what you can learn or do with it.

I suppose any shell programmer will want to know 'dialog'. I've used it a couple times, in this series. This is your first lesson on dialog. We'll be using its 'menu' feature in this chapter. Here is the code:

I've attached the file host, which isn't included in Puppy, so you can make your own DNS queries and test the lines in this chapter. Put it in your /root/bin directory. Don't confuse the name with hosts, they are two different files.

We've seen many examples of piping to binary files. This is the first time we've made a script for piping.

My main point is to demonstrate we can pipe to our scripts, if we build them for that purpose. And considering we might want a successful return code we add one.

It would be easier to say:
< infile ucase

than
< infile tr [:lower:] [:upper:]

But frankly, I think ucase and lcase are too seldom used to even bother with. However, I think it good to know about the utilities in your tool box. With tr, if we want to change case in our files or even filenames, it's fairly easy.

My main purpose in this chapter is to make an exercise where you can practice updating an application if it needs updated. In other words: practice developing skills

While visiting the Dialog Web Site, I noticed my Puppy version of dialog was old. So I updated it.

To check your dialog version:

dialog --versionVersion: 1.1-20080819 (my current one)

If yours is older and you want to accept the assignment of updating it, you can go to the Dialog home page, linked above. Then to the 'download the latest section'. The file you would want would be dialog_1.1-20080819-1_i386.deb

I think your training level should be such that you can install this Debian package using 'disrpm' and 'mc' without much explanation.

Listed below are the package contents, note; they all go in /usr. You may choose not to install foriegn locales.

Please note: Lots of documentation to reference and learn from. And you can place documentation in different directories or make convenient symlinks.

Puppy comes with an useful utility called cal. I won't say much about it except, familiarize yourself with it.

I'm attaching to this post a similar utility which has been around for ages called ccal. Apart from displaying a colored calendar, it has the ability to keep appointments, birthdays, dates and other items for you.

I'm working and have about completed a script to make data entry for this utility very easy. A day or three maybe?

This is version 3.5 and I think a slightly newer version is available from at least the Debian repositories. But in reading the release notes, I didn't see a particular advantage to it.

Writing programs for yourself is different than writing for distribution. You already know many of the conditions on your computer. You don't necessarily know all you need to know on your client's computer. For this reason, you may want to check some conditions prior to running the meat of your script. This of course especially applies if damage can be done.

Example 1 - do we have all dependent files?

Sometimes the successful operation of our script requires other files. Here is an example of how to check for dependent files:

Code:

for i in which man2html foobar
do
file=`which $i`
if [ x$file = x ] ; then
echo $i missing
missing=1
fi
done

[ x$missing = x1 ] && exit 1

Explanation

for loop with three arguments: which, man2html, foobar

which reports the location of a file, if found

if the variable file is empty we display problem on screen and set missing=1

test for missing=1, if true, exit

we didn't find the file 'foobar' and we branch to exit the script with an exit code of 1 which we may or may not need or even want.

For this chapter, I'd like you, if you are following the course, to download and install a curses browser. Ultimately, I think we'll have two or three browsers, but currently I'd like you to install 'links' from Puppy's official server.

links-2.1pre30.pet in the pet packages 4 directory ( there is an earlier version in the 3 directory, so make sure you get it from the 4 directory )

links differs from other ncurses browsers in that it also has a graphics mode which when running X can be enabled with the -g switch.

You could make a script called xlinks to save extra typing.

Code:

#!/bin/bash
links -g "$@"

or make an alias

Code:

alias xlinks='links -g'

To install it, download it with mc from ftp.ibiblio.org. After download, select file, hit enter key, navigate to usr/bin in the virtual file system and copy links to /root/bin. It's just a one file install.

Important! Then add a variable to /etc/profile.local

export PAGER=links

links can be used as a browser, local file viewer for web documents, man pages and text pages. And we have a couple upcoming scripts which will use links.

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum