Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 21 Oct 2014, 13:32
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
The Text-User Interface
Moderators: Flash, Ian, JohnMurga
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 6 of 8 Posts_count   Goto page: Previous 1, 2, 3, 4, 5, 6, 7, 8 Next
Author Message
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Sat 01 Aug 2009, 20:55    Post_subject:  

78 - select menu

I show a simple way to make a useful menu with bash. When we did the look utility, I used this bash' select command. I didn't however explain it at the time, thinking I'll do it later. Now is later.

In chapter 77 we installed 'links' and set the variable PAGER.

By now, I hope you have some documentation in our 'doc' directory /root/doc, because this script is for perusing the /root/doc directory.

I called this script doks, but as you know you can give it another name.

Code:
#!/bin/bash
main() {

    vars
    menu

}

vars() {

    # $clr
    dir=/root/doc
    [ ! -d $dir ] && echo "$dir doesn't exist, exiting" && exit
    PS3='Please select : '

    # branch example, use different mode for the pager if X is running

    xrun=`pidof X`
    [ x$xrun != x ] && graphics="-g"

}

menu() {

    cd $dir
    clear ; echo -e \\n\\n\\n\\n\\n
    echo "Scripting And Linux Documentation" ; echo
    select fname in * ;
    do
           $PAGER $graphics ${dir}/${fname}
          break;
    done
    exec $0

}

main

# 2009-08-02


With this utility you can type in doks and easily read the files in this directory with your new pager. (if they are the right kind of files)

What I'd like for an assignment is to have you modify this file some, give it colors, change the color of PS3. Change and color the title, so on and so forth.

You can setup these simple little menu systems throughout your system as needs be. For example, I have scripts to run wine supported files. I type in 'winem', short for 'wine menu' and then select the number of the application I want to run.

The wine scripts have their own place in the PATH so I can run them directly also with command line arguments. And while on the subject, you can add lots of paths to grow your system and keep it organized.

A little change of subject, but while I'm thinking about it, when we installed mrxvt it didn't come with a complete rc file. I made a complete file, not all the values are entered, nor should they be, but the options are. With the rc file, it's easy to change the way mrxvt looks and behaves. And of course see the options available which the other file didn't show.

I'll attach it as mrxvtrc and you can download it to /root and use

swapf mrxvtrc .mrxvtrc

Would you like a utility for swapping directories? If so, you can use swapf as the template. Copy it to the name swapd and change it internally, accordingly.

~

78 - select menu
mrxvtrc.zip
Description 
zip

 Download 
Filename  mrxvtrc.zip 
Filesize  1.8 KB 
Downloaded  1105 Time(s) 

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Tue 04 Aug 2009, 04:15    Post_subject:  

Chapter 79 - Line endings

This chapter is important to understand, but I don't know under what circumstances you will need to apply the information.

Unix, MS-DOS, and Mac all use different line endings. Because of this we can end up with a Mac text file, a DOS text file or a Unix text file.

Also we can end up with a hodge podge of line endings if we've been editing with DOS and Linux editors, which don't convert all unchanged line endings on save.

Puppy and most Linux come with utilities called unix2dos and dos2unix, when you port text based documents from one operating systems, it's good to make your line endings consistent.

In order to help you better conceptualize I have hexdump for the three file types

Unix / Linux File - Line Feed (LF) (0x0a)


Code:
74 68 69 73 20 69 73 20  61 20 75 6e 69 78 20 66  |this is a unix f|
69 6c 65 0a 69 74 20 75  73 65 73 20 6c 69 6e 65  |ile.it uses line|
20 66 65 65 64 73 0a 66  6f 72 20 6c 69 6e 65 20  | feeds.for line |
65 6e 64 69 6e 67 73 0a  6e 6f 74 65 20 74 68 65  |endings.note the|
20 30 61 0a 0a                                    | 0a..|


Messy DOS File - (Carriage Return + Line Feed) (CR+LF) (0x0d 0x0a)

7
Code:
4 68 69 73 20 69 73 20  61 20 6d 65 73 73 79 20  |this is a messy |
64 6f 73 0d 0a 66 69 6c  65 2c 20 69 74 20 75 73  |dos..file, it us|
65 73 20 63 61 72 72 69  61 67 65 0d 0a 72 65 74  |es carriage..ret|
75 72 6e 73 20 61 6e 64  20 6c 69 6e 65 20 66 65  |urns and line fe|
65 64 73 0d 0a 66 6f 72  20 6c 69 6e 65 20 65 6e  |eds..for line en|
64 69 6e 67 73 2c 20 6e  6f 74 65 0d 0a 74 68 65  |dings, note..the|
20 30 64 20 61 6e 64 20  30 61 0d 0a              | 0d and 0a..|

Mac File - Carriage Return - 0x0d

Code:
74 68 69 73 20 69 73 20  61 20 73 61 6d 70 6c 65  |this is a sample|
0d 6f 66 20 61 20 4d 61  63 20 66 69 6c 65 0d 6e  |.of a Mac file.n|
6f 74 65 20 74 68 65 20  30 64 2c 20 74 68 65 73  |ote the 0d, thes|
65 0d 61 72 65 20 63 61  72 72 69 61 67 65 20 72  |e.are carriage r|
65 74 72 75 6e 73 0d                              |etruns.|


I'm including a utility called 'tofrodos' with this post. One binary file and one text help file

You can also download the source and compile it yourself from:

http://www.thefreecountry.com/tofrodos/index.shtml

Puppy's equivalent utilities don't have the features tofrodos has, so that's why I'm adding it.

I have an idea it will convert Mac files, even if the help doesn't say so, or prepare them for conversion, with a little help from simple script. But I need to test this first.

The main things to remember from this chapter, I've highlighted in bold.

~

Chapter 79 - Line endings
tofrodos.zip
Description 
zip

 Download 
Filename  tofrodos.zip 
Filesize  6.84 KB 
Downloaded  1056 Time(s) 

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Tue 04 Aug 2009, 04:43    Post_subject:  

Chapter 80 - Clean File Improved

I removed notrail from Chapter 50 for a better utility posted in this chapter.

The contents of notrail are: one shell script called notrail, you will want to replace it with cleanf ( means clean file )

The main change is: I wrote a C program pipe which does more with the characters than the sed command.

Zip file contents are:

cleanf - the script to run
cleanf-bin - the script automatically runs this file
cleanf-bin.c - the source code distributed GNU version 2

That's about it for this chapter, enjoy!

~

Chapter 80 - Clean File Improved
cleanf.zip
Description 
zip

 Download 
Filename  cleanf.zip 
Filesize  2.27 KB 
Downloaded  1050 Time(s) 

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Tue 04 Aug 2009, 05:31    Post_subject:  

Chapter 81 - How to do some modest binary hacking

Rule #1 is make a backup
Rule #2 is make a backup

The hex editor is the right tool for the job, unless you insert or delete bytes the byte size of the file doesn't change. The hex editor displays all content.

I compiled gqview and found out it wanted its help file from a subdirectory of my temporary build directory.

I edited the directory string in the file to point to the right place. It only took a minute and beat debugging the source code.

------------

More recently, as in today, I was using a really neat PIM (Personal Information Manager)

It has (had) 1 pane for a todo list, 1 pane for the calendar and one pane for the appointment list.

Problem is I don't have many appointments. But I do have goals and the way the PIM is organized goals work perfectly in place of appointments. So I hacked it replacing this string
Appointments
with this
Goal Planner

These characters are only for display purposes and the number of characters I replaced was identical, so the file size didn't change, which you really likely don't want to do.

I've attached a little picture of the changes.

The idea I wish to convey in this chapter is don't be afraid to change some human readable text. ( you followed rule number #1 and #2 )

Generally, when you are inside the file, you can intuit if the text you plan to change is okay to change.

~

Chapter 81 - How to do some modest binary hacking
hex-changes.png
 Description   
 Filesize   5.22 KB
 Viewed   2112 Time(s)

hex-changes.png


_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Tue 04 Aug 2009, 05:50    Post_subject:  

Chapter 82 - File extensions and file names

Sometimes we need to add and remove file name information. I'll show an example. Suppose we wanted to decode .mp3 to .wav files with lame.

Lame's syntax is like this lame -decode <infile> <outfile>

For 16 songs that would be a lot of typing. If we want to do a good job we want the outfile with a .wav extension and not a .mp3.wav extension.

Suppose our files are named like this Track_01.mp3, Track_02.mp3, . . .

We have an advantage from the start because we know the infile extension.

Puppy comes with an external utility called basename. Basename will strip the directory name from our file, if the directory name exists, but it won't strip the extension unless we tell it what it is.

Back to the old for loop.

Code:
for i in *mp3 ; do
    fn=`basename .mp3`
    lame -decode ${fn}.mp3  ${fn}.wav
done


When the loop is done, we have 16 .mp3 and 16 .wav files and it didn't take typing. Note this would be a reusable script.

It wouldn't handle song names with spaces, but as the administrator of your Linux system, I think you are better off not introducing file or directory names with spaces.

The idea in this chapter is showing the utility basename and how to remove and change extensions. If you 'got' that much you got it. There are other ways to capture extensions and remove them. I'll save that for later.

~

Chapter 82 - File extensions and file names

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Tue 04 Aug 2009, 06:11    Post_subject:  

Chapter 83 - A little more about variables

Global Variables - These variables are set for system wide use. Some of the variables we set and exported in profile.local are global variables.

You want to try and avoid giving your script the same names as the global variables unless that's what you want.

PATH is a particularly important global variable. One time on the forum the coder used PATH=with:his:values and the rest of the script didn't run. The script has precedence.

Most of the variables I've set, in this series, I've used quotes. Actually, you don't need to quote your variables if there aren't spaces.

EDITOR=mp (doesn't need quotes)
EDITOR="mp" (doesn't hurt or change the end result)
EDITOR='mp' (also doesn't hurt or change the end result)

However sometimes quotes are the last thing you should use in a variable. As you have learned, many characters have special or double meanings in bash and utilities.

If you want your variable interpreted literally, use ' ' and not " "

In order to demonstrate the concept, try this exercise:

echo $PATH
echo "$PATH"
echo '$PATH'

echo Puppy Linux
echo " Puppy Linux "
echo ' "Puppy Linux" '

Between these two examples, you will get an idea of what I mean by a literal interpretation when you use ' ' instead of " "

~

Chapter 83 - A little more about variables

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Tue 04 Aug 2009, 19:41    Post_subject:  

Chapter 84 isolating file types

It is very common convention in Unix that our binary files and our shell scripts are put together in the /bin and /sbin directories.

Suppose we want to have a directory with just scripts, maybe for the purpose of studying the scripts on the system. To manually go through the directories, prune the scripts from binaries, and copy out the scripts would be a lot of work.

We could find out if the file is a script file with the file command:

file scriptname ; the output would be;
scriptname: Bourne shell script text executable

Another way would be standard out to grep
<scriptname grep '#!/bin/'; outputs;
#!/bin/bash

If grep returns with zero, I added the ' ' as reinforcement of making a literal interpretation. Try it with " " and you get bad results.

We don't want to take a lot of time making a script, which we don't plan to use a lot or distribute.

We make a directory called /root/scripts

Code:
#!/bin/bash
for i in * ; do
   if [ ! -d $i ] ; then
      file $i | grep "shell script" >/dev/null
      if [ x$? = x0 ] ; then
         cp $i -i /root/scripts
      fi
   fi
done


It's about as simple at that.

cd to your bin directories and run the command. When done, copies of most of the system's scripts will be in /root/scripts (except for those not in /bin directories)

Frankly, I'm not necessarily recommending this exercise, except for;

1) showing that sometimes very daunting tasks can be very simple with a few lines in bash

2) and simply by looking at scripts others have written, YOU WILL LEARN things. (should you actually make and run the script)

-------------------

Note: some time you might encounter someone claiming the use of #!/bin/sh is better than #!/bin/bash. Maybe, and they aren't particularly wrong if they say this.

I use #!/bin/bash exclusively because in Puppy 4.00 there is not sh. /bin/sh is a symlink to bash. So why not be direct?

Chapter 84 isolating file types

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Tue 04 Aug 2009, 19:51    Post_subject:  

Chapter 85 - string comparisons

We frequently see constructs like this:

[ "$myvar" = "words" ]
or as a shortcut
[ x$myvar = x$words ]

We are comparing string1 with string2 to see if they are equal

The quotes or the x don't actually exist in either string. We use them as place holders, to make sure there is something to compare with. We can't compare something to nothing and bash will give us an error.

By using these placeholders, there is always something to compare to.

" " is prettier
x is easier

Either work fine.

Pretty simple, but I don't think I mentioned the reasons why earlier.

Chapter 85 - string comparisons

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
cherrysteel

Joined: 05 Aug 2009
Posts: 1

PostPosted: Wed 05 Aug 2009, 08:26    Post_subject:  THANK YOU SO MUCH  

Very Happy after many hours of attempting to learn puppylinux ( my first linux distro)

I can finally get a foot hold of the command line.

I began to doubt my sanity as i followed other linux tutorials and got NOTHING but "command not found"

YOUR contributions are Priceless and your generosity inspiring!
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Thu 06 Aug 2009, 03:23    Post_subject:  

Chapter 86 LS_COLORS

The question:
    In mrxvt, when I use a ls command, the resulting list of directories are in different colours. I would like to know what each colour denotes." - Dave

The technical reason for the colors are probably, (depending on your Puppy), it;

1) sets alias ls='ls --color=auto' in /etc/profile
2) replaced busybox ls with the real ls

----------------


Below are some specifics from dircolors. (attached to this post)

We can control the colors and what is denoted by them.

----------------

# Configuration file for dircolors, a utility to help you set the
# LS_COLORS environment variable used by GNU ls with the --color option.
# Copyright (C) 1996, 1999-2008
# Free Software Foundation, Inc.
# Copying and distribution of this file, with or without modification,
# are permitted provided the copyright notice and this notice are preserved.
# The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
# slackware version of dircolors) are recognized but ignored.
# Below, there should be one TERM entry for each termtype that is colorizable
TERM Eterm
TERM ansi
TERM color-xterm
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM cons25
TERM console
TERM cygwin
TERM dtterm
TERM eterm-color
TERM gnome
TERM gnome-256color
TERM jfbterm
TERM konsole
TERM kterm
TERM linux
TERM linux-c
TERM mach-color
TERM mlterm
TERM putty
TERM rxvt
TERM rxvt-cygwin
TERM rxvt-cygwin-native
TERM rxvt-unicode
TERM screen
TERM screen-256color
TERM screen-bce
TERM screen-w
TERM screen.linux
TERM vt100
TERM xterm
TERM xterm-16color
TERM xterm-256color
TERM xterm-88color
TERM xterm-color
TERM xterm-debian
# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#NORMAL 00 # no color code at all
#FILE 00 # regular file: use no color at all
RESET 0 # reset to "normal" color
DIR 01;34 # directory
LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
# numerical value, the color is as for the file pointed to.)
HARDLINK 44;37 # regular file with more than one link
FIFO 40;33 # pipe
SOCK 01;35 # socket
DOOR 01;35 # door
BLK 40;33;01 # block device driver
CHR 40;33;01 # character device driver
ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file
SETUID 37;41 # file that is setuid (u+s)
SETGID 30;43 # file that is setgid (g+s)
CAPABILITY 30;41 # file with capability
STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
# This is for files with execute permission:
EXEC 01;32
# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')
# If you use DOS-style suffixes, you may want to uncomment the following:
#.cmd 01;32 # executables (bright green)
#.exe 01;32
#.com 01;32
#.btm 01;32
#.bat 01;32
# Or if you want to colorize scripts even if they do not have the
# executable bit actually set.
#.sh 01;32
#.csh 01;32
# archives or compressed (bright red)
.tar 01;31
.tgz 01;31
.arj 01;31
.taz 01;31
.lzh 01;31
.lzma 01;31
.zip 01;31
.z 01;31
.Z 01;31
.dz 01;31
.gz 01;31
.bz2 01;31
.bz 01;31
.tbz2 01;31
.tz 01;31
.deb 01;31
.rpm 01;31
.jar 01;31
.rar 01;31
.ace 01;31
.zoo 01;31
.cpio 01;31
.7z 01;31
.rz 01;31
# image formats
.jpg 01;35
.jpeg 01;35
.gif 01;35
.bmp 01;35
.pbm 01;35
.pgm 01;35
.ppm 01;35
.tga 01;35
.xbm 01;35
.xpm 01;35
.tif 01;35
.tiff 01;35
.png 01;35
.svg 01;35
.svgz 01;35
.mng 01;35
.pcx 01;35
.mov 01;35
.mpg 01;35
.mpeg 01;35
.m2v 01;35
.mkv 01;35
.ogm 01;35
.mp4 01;35
.m4v 01;35
.mp4v 01;35
.vob 01;35
.qt 01;35
.nuv 01;35
.wmv 01;35
.asf 01;35
.rm 01;35
.rmvb 01;35
.flc 01;35
.avi 01;35
.fli 01;35
.flv 01;35
.gl 01;35
.dl 01;35
.xcf 01;35
.xwd 01;35
.yuv 01;35
# http://wiki.xiph.org/index.php/MIME_ (cut)
.axv 01;35
.anx 01;35
.ogv 01;35
.ogx 01;35
# audio formats
.aac 00;36
.au 00;36
.flac 00;36
.mid 00;36
.midi 00;36
.mka 00;36
.mp3 00;36
.mpc 00;36
.ogg 00;36
.ra 00;36
.wav 00;36
# http://wiki.xiph.org/index.php/ (cut)
.axa 00;36
.oga 00;36
.spx 00;36
.xspf 00;36

~

Chapter 86 LS_COLORS

(continued in chapter 87)


PS thank you cherrysteel
dircolors.zip
Description 
zip

 Download 
Filename  dircolors.zip 
Filesize  17.73 KB 
Downloaded  1060 Time(s) 

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Thu 06 Aug 2009, 03:56    Post_subject:  

Chapter 87 using dircolors

So, now we've installed dircolors and dircolors.txt. What next?

Read the man page and/or type dircolors --help

I usually start off with the --help and if it is too cryptic or I need more, then the man page. Utilities and programs we use need to be learned. (at least the basics do)

dircolors --help gives us this;

Code:
Usage: dircolors [OPTION]... [FILE]
Output commands to set the LS_COLORS environment variable.

Determine format of output:
  -b, --sh, --bourne-shell    output Bourne shell code to set LS_COLORS
  -c, --csh, --c-shell        output C shell code to set LS_COLORS
  -p, --print-database        output defaults
      --help     display this help and exit
      --version  output version information and exit

If FILE is specified, read it to determine which colors to use for which
file types and extensions.  Otherwise, a precompiled database is used.
For details on the format of these files, run `dircolors --print-database'.

Report dircolors bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report dircolors translation bugs to <http://translationproject.org/team/>


Warning if we redirect like this: > we clobber the destination file. If we redirect like this >> we append it.

I recommend this command.

cp /etc/profile.local /etc/profile.local.bak

The idea being, it is not fun clobbering or losing our configuration files. It is less painful to backup your configuration files before editing in the event of mistakes.

dircolors - the defaults

dircolors -b to view what it does

dircolors -b >>/etc/profile.local - to add the LS_COLORS variable and export command to /etc/profile.local

LS_COLORS will be about 1186 characters long, do NOT split the long line.

dircolors customizing or studying

dircolors -p > dircolors.db
edit dircolors.db and change things as you want. when done;
dircolors dircolors.db >> /etc/profile.local

(name dircolors.db not arbitrary, use any name you wish)

Of course if you've put previous LS_COLORS in /etc/profile.local, you'll want to edit the file and remove earlier entries.

~

Chapter 87 using dircolors

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Sat 08 Aug 2009, 01:29    Post_subject:  

Chapter 88 - my pup_save file filled up

I had about 95 MB free and then it was 0 MB free. Thinking back, I couldn't remember when I downloaded something that big. So, it was time to troubleshoot and locate where the free space went. After discovering where the lost space was, I can back track and explain.

The behavior of mount points

In Linux we can mount filesystems on just about any mount point, (directory). The mount point does not need to be empty to use it as a mount point for another filesystem.

/mnt/hda1 is merely a directory inside my pup_save file. That's all it is - a directory. But I use it as a mount point for /dev/hda1.

If /mnt/hda1 is not mounted, I could view any files inside it. But if I mount it, the files would no longer be shown. The viewable files would be the files in the partition /dev/hda1

What would happen if I copied, moved or downloaded files to /mnt/hda1 ?

    If it is not mounted they would be placed inside /mnt/hda1, which is inside the pup_save file, thus increasing the used space in the pup_save file.

    But if /mnt/hda1 were mounted, the files would be placed inside /dev/hda1 and would not increase the pup_save used space.

I guess you can figure out what I did to fill up pup_save.

Introducing the utility du

du has many switches, modes of behavior. I made this script called disku (the u meaning usage)

Code:
#!/bin/bash
du --max-depth=1 --one-file-system | sort -n


The --one-file-system says don't operate on other file systems. --max-depth=1 means just show me the first level directories.

After running the script I noted /mnt was bigger than it should be.

The file sort also has many options, the -n switch arranges du output sizes in ascending order.

-----------

Summary: In this troubleshooting scenerio, I didn't even have a script to do the job. However, I knew the external tools existed and what they did.

How could I have made this simple script without knowing about the tools available? Not very easily. The 'secret to success' in this case is in knowing the utilities available to us.

In the course of these chapters, I'll try and make sure you've been introduced to virtually all the common utilities.

~

Chapter 88 - my pup_save file filled up

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Fri 21 Aug 2009, 21:21    Post_subject:  

Chapter 89 - How to make a RAM drive

First, I'd like to discuss reasons why you might want a RAM drive based mainly I suppose on reasons I've wanted RAM drives.

1) With MS-DOS, I used RAM drives for speeding up execution of batch files, holding some commonly used utilities and as a temp directory.

2) Later as RAM became cheaper, I learned how to load the entirety of Windows in RAM. This made Windows fairly invincible, because even if some kind of corruption happened, it would disappear after reboot.

3) With Linux, I like RAM drives as temporary work places for files which have no life expectancy, such as the files used in scripting or things like ripping a music disc and converting the wav files to mp3s. The RAM drive is fast and it's no wear and tear on the hard disk.

4) (Many of my scripts manipulate files and I have a wrkdir variable pointing to a RAM disk.)

----------------------------

I don't know that you need or want a RAM Drive, or this kind of RAM Drive. Or if you already have one. Nevertheless, I'll show how.

Pick a ram device and a mount point

In /etc/rc.d/rc.local

mke2fs -m0 /dev/ram3
mount -t ext2 /dev/ram3 /mnt/ramd


Puppy's default will usually give about a 14MB drive, this size can be increased on the kernel line, like this;

ramdisk_size=65536 (would give a 64MB RAM drive)

In earlier tests ( versions 2.xx ), I found Puppy's upper limits between 400 and 500 MB

In the next chapter I'll discuss a different kind of RAM filesystem.

~

Chapter 89 - How to make a RAM drive

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Fri 21 Aug 2009, 21:27    Post_subject:  

Chapter 90 - tmpfs on /dev/shm

This type of RAM filesystem is very common. I've seen it called an shmfs (in older days) and more currently, tmpfs. The mount point has always been /dev/shm. But should be able to use other mount points.

Some Puppys have this filesystem and some don't. I think I even saw one version were /tmp was a symlink to /dev/shm.

My Puppy didn't have the tmpfs, so I made one. First step is adding this line to /etc/fstab;

Code:
tmpfs   /dev/shm   tmpfs    noauto,rw,noatime,nodiratime 0 0


then in /etc/rc.d/rc.local run this command;

mount /dev/shm

You can also mount a tmpfs /dev/shm with a full set of mount instructions, but why bother? One fstab entry makes it much easier.

The default tmpfs size is 50% of RAM

You can change the size with this parameter, in fstab;
size=800M (if you wanted an 800MB tmpfs, I use 800 MB for CD copy)

Code:
tmpfs   /dev/shm   tmpfs    noauto,size=800M,rw,noatime,nodiratime 0 0


This type of filesystem doesn't actually deplete your RAM.

I conceptualize it this way. The first type of RAM disk I showed is static in size on not accessible for paging. Tmpfs is dynamic, and used as a part of available memory, sort of like a swap file in RAM. (A RAM disk that doesn't really use RAM?)

I don't want to say which is better, because the answer is likely dependent on what it's used for.

I use the /dev/shm for SeaMonkey's disk cache set at 100MB. Also as my $wrkdir. And for major work like copying a cd disc.

~

Chapter 90 - tmpfs on /dev/shm

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Bruce B


Joined: 18 May 2005
Posts: 11130
Location: The Peoples Republic of California

PostPosted: Sat 22 Aug 2009, 00:16    Post_subject:  

Chapter 91- A 100 more to go ?

Sorry for few weeks lost making new chapters. This is not a work completed. There is a story about the lost time. One I hope you find of some interest.

I've been doing this project on a highly modified Puppy version 4.00. I wanted for us to be able to convert man pages to HTML or text format. I thought Puppy had a file called man2html, but wanted to be sure. It appears it didn't.

I decided to build a new Puppy, one which would lend itself better to this project. With me doing things different, like keeping a log of changes, having fresh pup_saves for testing, keeping addon files in separate directories and etc.

So, I setup a new Puppy and added many applications, even put together a new Midnight Commander. Then, the fateful day. I ran a filesystem check and found it was full of errors.

I decided, no way. I'm starting over with a pup_save with a ext3 filesystem, not the default ext2. For about a year and a half now, I've been using ext3 with virtually no file system errors, and I might add, under very heavy usage.

Then my cable modem went bad. Then I decided to upgrade the firmware for my old Linksys router and the upgrade went bad. So buy a new router. While I'm at it how about a controller card for another drive? Why not extra DVD discs and, what would be wrong with a new Plextor burner?

Well you get the picture.

--------------

The part that bothers me from an 'us' perspective is the excessive ext2 file system errors.

What you can do is something along these lines, if you are using Frugal on an HD (probably a RAM stick also), for the purpose of checking.

1) boot using the puppy pfix=ram option
or
2) add a extra small pup_save file about 32 MB

Find your pup_save file, run e2fsck -f on your pup_save file and see if you are getting too many errors.

If so, you might want to plan to convert to an ext3 file system.

We'll deal with the 'how to' on that later.

Nuff

---------------

I have questions to test your learning, here is a function:

Code:
nd() {
   [ ! -d $1 ] && mkdir $1
   [ $1 ] && cd $1
}


Question: What does it do and where should it go?


~

Chapter 91- A 100 more to go ?

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 6 of 8 Posts_count   Goto page: Previous 1, 2, 3, 4, 5, 6, 7, 8 Next
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1565s ][ Queries: 13 (0.0045s) ][ GZIP on ]