Table of Contents

Part 2

Entries

October 4, 2011

Today we learned about regular expressions.

^ - match beginning of line
$ - match end of the line
. - match any single character
* - match 0 or more of the previous
[] - match any one of the  enclosed 
[^] - inverted character class ( do not include)
\< - match beginning of word
\> - match ending of word
() - grouping
| - or 
\(\) - grouping for substitution

This allows for more advanced searching or advanced functions with a bot. I'm having a hard time using the grouping for substitution part of regular expressions. Still having trouble with time management.

     <(^^,)>

October 6, 2011

Today we played with regular expressions and worked on my bot.

My bot is now able to say “Hi” back to a user directly. He can do math and tell how many users are on the system. Still having trouble using regular expressions but slowly getting a hand on them.

<(^^,)>

October 16, 2011

Once again we had to restart the irc chat. We began to talk about the “c” language. We also learned about Programming Paradigms. The C language is very useful for programming because it allows you to be more specific with the details of your program.

 && - and
 || - or

This helps with decisions in a script. As for the class, so far everything is going very well.

October 18, 2011

Today we learned about wildcards. Wildcards are for files while RegEx is for text.

 ? - match any single charecter
 * - match 0 or more of anything
 [] - anyone of enclosed
 [^ ] - not only one of enclosed

I am having trouble with the RegEx and Wildcards still.

unix Topics

Moving And Renaming Files

The command “mv” can be used in renaming and moving files.

lab46:~$ ls
Maildir                 archives.tar.bz2  data         shellscripting  tmp
archive1.tar.gz         archives.zip      irc          src             vitest
archive2.zip            bin               motd         src.orig
archivecompilationfile  cake              public_html  testdir
archives                closet            puzzlebox    testdir2
lab46:~$ touch testfile
lab46:~/testdir$

lab46:~/testdir$ mv testdir2 lol
lab46:~/testdir$ ls
file  lol  testfile
lab46:~/testdir$
lab46:~/testdir$ cd
lab46:~$ ls
Maildir                 archives.tar.bz2  data         shellscripting  testfile
archive1.tar.gz         archives.zip      irc          src             tmp
archive2.zip            bin               motd         src.orig        vitest
archivecompilationfile  cake              public_html  testdir
archives                closet            puzzlebox    testdir2
lab46:~$ mv vitest testdir
lab46:~$ ls
Maildir                 archives.tar.bz2  data         shellscripting  testfile
archive1.tar.gz         archives.zip      irc          src             tmp
archive2.zip            bin               motd         src.orig
archivecompilationfile  cake              public_html  testdir
archives                closet            puzzlebox    testdir2
lab46:~$ cd testdir
lab46:~/testdir$ ls
file  lol  testfile  vitest
lab46:~/testdir$

copying a file is useful because it leaves the file in its location but also moves it to another location.

Archiving Files

It's like taking a bunch of files and putting them all into one secured little box. Not that anyone can't just open the archived file but it allows for a much easier mode of transportation especially combined with compressing. In basic terms it allows for the easy transportation of a large amount of files. The most common archiving tool is “tar”. Tar has a lot of details so you can look them up to see all the variations but an example of one is provided bellow.

lab46:~$ ls
Maildir                 archives.zip  linktestfile    testdir
archive                 bin           motd            testdir2
archive1.tar.gz         cake          public_html     testfile
archive2.zip            closet        puzzlebox       tmp
archivecompilationfile  courses       shellscripting
archives                data          src
archives.tar.bz2        irc           src.orig
lab46:~$ tar -cvf testdir.tar testdir
testdir/
testdir/file
testdir/testfile
testdir/lol
testdir/vitest
testdir/hahaha/
lab46:~$ ls
Maildir                 archives.zip  linktestfile    testdir
archive                 bin           motd            testdir.tar
archive1.tar.gz         cake          public_html     testdir2
archive2.zip            closet        puzzlebox       testfile
archivecompilationfile  courses       shellscripting  tmp
archives                data          src
archives.tar.bz2        irc           src.orig
lab46:~$

Compressing and Decompressing

“gzip” is a command that can be used to compress a file and “gunzip” is the opposite command that can decompress the file. This is useful in combination with archiving because it makes large masses of files really small and easy for transportation. As an example the archive archives.zip will be gzipped and gunzipped.

lab46:~$ ls
Maildir                 archives          closet   public_html     testdir
archive                 archives.tar.bz2  courses  puzzlebox       testdir2
archive1.tar.gz         archives.zip      data     shellscripting  testfile
archive2.zip            bin               irc      src             tmp
archivecompilationfile  cake              motd     src.orig
lab46:~$ gzip archives.zip

lab46:~$ ls
Maildir                 archives          closet   public_html     testdir
archive                 archives.tar.bz2  courses  puzzlebox       testdir2
archive1.tar.gz         archives.zip.gz   data     shellscripting  testfile
archive2.zip            bin               irc      src             tmp
archivecompilationfile  cake              motd     src.orig
lab46:~$ gunzip archives.zip.gz
lab46:~$ ls
Maildir                 archives          closet   public_html     testdir
archive                 archives.tar.bz2  courses  puzzlebox       testdir2
archive1.tar.gz         archives.zip      data     shellscripting  testfile
archive2.zip            bin               irc      src             tmp
archivecompilationfile  cake              motd     src.orig
lab46:~$

It is a special file that points to another file. Like a shortcut on a normal desktop. One can be made by using the command “ln -s source_file myfile” Demonstration.

lab46:~$ ls
Maildir                 archives          closet   public_html     testdir
archive                 archives.tar.bz2  courses  puzzlebox       testdir2
archive1.tar.gz         archives.zip      data     shellscripting  testfile
archive2.zip            bin               irc      src             tmp
archivecompilationfile  cake              motd     src.orig

lab46:~$ ln -s testfile linktestfile
lab46:~$ ls
Maildir                 archives.zip  linktestfile    testdir
archive                 bin           motd            testdir2
archive1.tar.gz         cake          public_html     testfile
archive2.zip            closet        puzzlebox       tmp
archivecompilationfile  courses       shellscripting
archives                data          src
archives.tar.bz2        irc           src.orig
lab46:~$ cat linktestfile
hi
lab46:~$ cd linktestfile
-bash: cd: linktestfile: Not a directory
lab46:~$ ls -l
total 60
lrwxrwxrwx 1 cforman lab46    17 Aug 28 10:37 Maildir -> /var/mail/cforman
-rw-r--r-- 1 cforman lab46 10240 Oct 27 22:27 archive
-rw-r--r-- 1 cforman lab46   237 Oct 20 16:05 archive1.tar.gz
-rw-r--r-- 1 cforman lab46   584 Oct 20 16:06 archive2.zip
-rw-r--r-- 1 cforman lab46    62 Oct 20 16:31 archivecompilationfile
drwxr-x--x 3 cforman lab46    79 Oct 20 16:30 archives
-rw-r--r-- 1 cforman lab46   318 Oct 25 15:03 archives.tar.bz2
-rw-r--r-- 1 cforman lab46  1168 Oct 20 16:45 archives.zip
drwxr-xr-x 2 cforman lab46  4096 Oct 26 12:47 bin
-rw-r--r-- 1 cforman lab46     3 Sep  6 16:21 cake
drwxr-xr-x 2 cforman lab46    69 Sep 15 16:11 closet
-rw-r--r-- 1 cforman lab46 10240 Oct 27 14:48 courses
lrwxrwxrwx 1 cforman lab46    27 Oct  4 14:36 data -> /usr/local/etc/data/cforman
drwx------ 4 cforman lab46    39 Sep 29 14:55 irc
lrwxrwxrwx 1 cforman lab46     8 Oct 27 22:38 linktestfile -> testfile
-rw-r--r-- 1 cforman lab46  1310 Sep 15 15:13 motd
drwx-----x 2 cforman lab46     6 Aug 26  2009 public_html
drwxr-x--- 3 cforman lab46    62 Oct 25 16:21 puzzlebox
drwxr-xr-x 2 cforman lab46     6 Sep 22 15:21 shellscripting
drwx------ 2 cforman lab46     6 Sep  6 14:31 src
drwx------ 4 cforman lab46    45 Sep  4 21:29 src.orig
drwxr-xr-x 3 cforman lab46    68 Oct 27 13:16 testdir
drwxr-xr-x 2 cforman lab46     6 Oct 13 18:42 testdir2
-rw-r--r-- 1 cforman lab46     3 Oct 27 12:34 testfile
drwxr-xr-x 2 cforman lab46    97 Sep 30 23:06 tmp
lab46:~$

This shows that it just looks like any other file except a light blue color. when the command “ ls -l” is used it will show the user where the link points to and you can view the contents of the link by catting it.

Permissions of files

Permissions are exactly as they sound. They say who is allowed to access a file.

position        Meaning    
1	directory flag, 'd' if a directory, '-' if a normal file, something else occasionally may appear here for special devices.
2,3,4	read, write, execute permission for User (Owner) of file
5,6,7	read, write, execute permission for Group
8,9,10	read, write, execute permission for Other
value	Meaning
-	in any position means that flag is not set
r	file is readable by owner, group or other
w	file is writeable. On a directory, write access means you can add or delete files
x	file is executable (only for programs and shell scripts - not useful for data files). Execute permission on a directory means you can list the files in that directory
s	in the place where 'x' would normally go is called the set-UID or set-groupID flag.

cli was used to preserve format ( taken from http://www.dartmouth.edu/~rc/help/faq/permissions.html because there is no better way to explain it)

lab46:~$ ls -l
total 60
lrwxrwxrwx 1 cforman lab46    17 Aug 28 10:37 Maildir -> /var/mail/cforman
-rw-r--r-- 1 cforman lab46 10240 Oct 27 22:27 archive
-rw-r--r-- 1 cforman lab46   237 Oct 20 16:05 archive1.tar.gz
-rw-r--r-- 1 cforman lab46   584 Oct 20 16:06 archive2.zip
-rw-r--r-- 1 cforman lab46    62 Oct 20 16:31 archivecompilationfile
drwxr-x--x 3 cforman lab46    79 Oct 20 16:30 archives
-rw-r--r-- 1 cforman lab46   318 Oct 25 15:03 archives.tar.bz2
-rw-r--r-- 1 cforman lab46  1168 Oct 20 16:45 archives.zip
drwxr-xr-x 2 cforman lab46  4096 Oct 26 12:47 bin
-rw-r--r-- 1 cforman lab46     3 Sep  6 16:21 cake
drwxr-xr-x 2 cforman lab46    69 Sep 15 16:11 closet
-rw-r--r-- 1 cforman lab46 10240 Oct 27 14:48 courses
lrwxrwxrwx 1 cforman lab46    27 Oct  4 14:36 data -> /usr/local/etc/data/cforman
drwx------ 4 cforman lab46    39 Sep 29 14:55 irc
lrwxrwxrwx 1 cforman lab46     8 Oct 27 22:38 linktestfile -> testfile
-rw-r--r-- 1 cforman lab46  1310 Sep 15 15:13 motd
drwx-----x 2 cforman lab46     6 Aug 26  2009 public_html
drwxr-x--- 3 cforman lab46    62 Oct 25 16:21 puzzlebox
drwxr-xr-x 2 cforman lab46     6 Sep 22 15:21 shellscripting
drwx------ 2 cforman lab46     6 Sep  6 14:31 src
drwx------ 4 cforman lab46    45 Sep  4 21:29 src.orig
drwxr-xr-x 3 cforman lab46    68 Oct 27 13:16 testdir
drwxr-xr-x 2 cforman lab46     6 Oct 13 18:42 testdir2
-rw-r--r-- 1 cforman lab46     3 Oct 27 12:34 testfile
drwxr-xr-x 2 cforman lab46    97 Sep 30 23:06 tmp
lab46:~$

an example of changing permissions for the group.

lab46:~$ ls -l
total 60
lrwxrwxrwx 1 cforman lab46    17 Aug 28 10:37 Maildir -> /var/mail/cforman
-rw-r--r-- 1 cforman lab46 10240 Oct 27 22:27 archive
-rw-r--r-- 1 cforman lab46   237 Oct 20 16:05 archive1.tar.gz
-rw-r--r-- 1 cforman lab46   584 Oct 20 16:06 archive2.zip
-rw-r--r-- 1 cforman lab46    62 Oct 20 16:31 archivecompilationfile
drwxr-x--x 3 cforman lab46    79 Oct 20 16:30 archives
-rw-r--r-- 1 cforman lab46   318 Oct 25 15:03 archives.tar.bz2
-rw-r--r-- 1 cforman lab46  1168 Oct 20 16:45 archives.zip
drwxr-xr-x 2 cforman lab46  4096 Oct 26 12:47 bin
-rw-r--r-- 1 cforman lab46     3 Sep  6 16:21 cake
drwxr-xr-x 2 cforman lab46    69 Sep 15 16:11 closet
-rw-r--r-- 1 cforman lab46 10240 Oct 27 14:48 courses
lrwxrwxrwx 1 cforman lab46    27 Oct  4 14:36 data -> /usr/local/etc/data/cf orman
drwx------ 4 cforman lab46    39 Sep 29 14:55 irc
lrwxrwxrwx 1 cforman lab46     8 Oct 27 22:38 linktestfile -> testfile
-rw-r--r-- 1 cforman lab46  1310 Sep 15 15:13 motd
drwx-----x 2 cforman lab46     6 Aug 26  2009 public_html
drwxr-x--- 3 cforman lab46    62 Oct 25 16:21 puzzlebox
drwxr-xr-x 2 cforman lab46     6 Sep 22 15:21 shellscripting
drwx------ 2 cforman lab46     6 Sep  6 14:31 src
drwx------ 4 cforman lab46    45 Sep  4 21:29 src.orig
drwxr-xr-x 3 cforman lab46    68 Oct 27 13:16 testdir
drwxr-xr-x 2 cforman lab46     6 Oct 13 18:42 testdir2
-rw-r--r-- 1 cforman lab46     3 Oct 27 12:34 testfile
drwxr-xr-x 2 cforman lab46    97 Sep 30 23:06 tmp

lab46:~$ chmod g+rw testfile
lab46:~$ ls -l
total 60
lrwxrwxrwx 1 cforman lab46    17 Aug 28 10:37 Maildir -> /var/mail/cforman
-rw-r--r-- 1 cforman lab46 10240 Oct 27 22:27 archive
-rw-r--r-- 1 cforman lab46   237 Oct 20 16:05 archive1.tar.gz
-rw-r--r-- 1 cforman lab46   584 Oct 20 16:06 archive2.zip
-rw-r--r-- 1 cforman lab46    62 Oct 20 16:31 archivecompilationfile
drwxr-x--x 3 cforman lab46    79 Oct 20 16:30 archives
-rw-r--r-- 1 cforman lab46   318 Oct 25 15:03 archives.tar.bz2
-rw-r--r-- 1 cforman lab46  1168 Oct 20 16:45 archives.zip
drwxr-xr-x 2 cforman lab46  4096 Oct 26 12:47 bin
-rw-r--r-- 1 cforman lab46     3 Sep  6 16:21 cake
drwxr-xr-x 2 cforman lab46    69 Sep 15 16:11 closet
-rw-r--r-- 1 cforman lab46 10240 Oct 27 14:48 courses
lrwxrwxrwx 1 cforman lab46    27 Oct  4 14:36 data -> /usr/local/etc/data/cforman
drwx------ 4 cforman lab46    39 Sep 29 14:55 irc
lrwxrwxrwx 1 cforman lab46     8 Oct 27 22:38 linktestfile -> testfile
-rw-r--r-- 1 cforman lab46  1310 Sep 15 15:13 motd
drwx-----x 2 cforman lab46     6 Aug 26  2009 public_html
drwxr-x--- 3 cforman lab46    62 Oct 25 16:21 puzzlebox
drwxr-xr-x 2 cforman lab46     6 Sep 22 15:21 shellscripting
drwx------ 2 cforman lab46     6 Sep  6 14:31 src
drwx------ 4 cforman lab46    45 Sep  4 21:29 src.orig
drwxr-xr-x 3 cforman lab46    68 Oct 27 13:16 testdir
drwxr-xr-x 2 cforman lab46     6 Oct 13 18:42 testdir2
-rw-rw-r-- 1 cforman lab46     3 Oct 27 12:34 testfile
drwxr-xr-x 2 cforman lab46    97 Sep 30 23:06 tmp
lab46:~$

Viewing files

Viewing files can be done thought a couple of different ways. The “out of the way” way to view file contents is to open the file using “nano” or the “vi editor”. Both of these allow the appending of a file also rather then just viewing it. the easiest way to view a file is to use the “cat” command to pretty much echo the contents of the file onto the screen.

lab46:~$ ls
Maildir                 archives.zip  linktestfile    testdir
archive                 bin           motd            testdir.tar
archive1.tar.gz         cake          public_html     testdir2
archive2.zip            closet        puzzlebox       testfile
archivecompilationfile  courses       shellscripting  tmp
archives                data          src
archives.tar.bz2        irc           src.orig
lab46:~$ cat cake
16
lab46:~$ cat testfile
hi
lab46:~$ cat src
cat: src: Is a directory
lab46:~$ cat linktestfile
hi
lab46:~$

“cat” can view text files and links to text files but it cant view directories, because they are not basic files they are many files. “cat” can open programs but this is not recomended because it does not like it and will freak out on your screen.

lab46:~/bin$ ls
CliBash             OpusResults  datatypes    hello.s   script2
DOOMONUbot          boscript     datatypes.c  password  script3
DOOMONUbot2         cli.c        hello        script    script4
Multiplicationprog  commandline  hello.c      script1   script5
lab46:~/bin$ cat hello
ELF>@@à @@@@@@@À@@@@   `  ÈÈ`È` @@DDPåtdüü@ü@$$Qåt/lib64/ld-linux-x86-64.so.2GNUGNUÛ-6I!#ÄSÚ¬ü9j;}Xk __gmon_start__libc.so.6puts__libc_start_mainGLIBC_2.2.5ui 1`HèkèúèÕHÃÿ5¢ ÿ%¤ @ÿ%¢ héàÿÿÿÿ% héÐÿÿÿ1íIÑ^HâHäðPTIÇÀ@HÇÁ@HÇÇä@èÇÿÿÿôHH1 H
ÀtÿÐHÃUHåSH=H uK»¸`HB Hë°`HÁûHëH9Øs$fDHÀH ÿÅ°`H H9ØrâÆû H[ÉÃfff.
                                            %t Ll$èLt$ðL|$øH\$ÐHì8L)åAýIöHÁýI×ècþÿÿHÉÿàÉÃUHå¿ì@èîþÿÿ¸ÉÃóÃfffff.         -{ L
ít1Û@LúLöDïAÿÜHÃH9ërêH\Hl$Ld$Ll$ Lt$(L|$0HÄ8ÃUHåSHHð Høÿt» `DHÿÐHHøÿuñH[ÉÃHèoþÿÿHÃHello, World! èþÿÿ<ÿÿÿ\ÿÿÿtzRx
              ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
< þÿÿ$TþÿÿQ_@F
Ø@`@õþÿo@¨@
=
 `0@p@ þÿÿoP@ÿÿÿoðÿÿoF@È`æ@ö@GCC: (Debian 4.4.5-8) 4.4.5GCC: (Debian 4.4.5-10) 4.4.5.symtab.strtab.shstrtab.interp.note.ABI-tag.note.gnu.build-id.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rela.dyn.rela.plt.init.text.fini.rodata.eh_frame_hdr.eh_frame.ctors.dtors.jcr.dynamic.got.got.plt.data.bss.comment#@ 1<@<$H`@`DöÿÿoN
       ¨@¨=^ÿÿÿoF@kþÿÿoP@Pzp@p                                                 ¸@¸Ð@Ð0@ØØ@Ø è@è¨ü@ü$¶ @ À `Ç°`ÎÀÓÈ`õ09þ /       ¸ñ@@<@`@@¨F@    P@
p@
  @
Ð@@Ø@è@ü@ @ `°`À`È````ñÿ `*°`8À`EP@[`jxÀ@ñÿ
                                           ¨`@À`« @ÁñÿÉ`ß`ð`È`
`@'@. = QcØ@iè`¤`±¸`¾@Îñÿ`Úñÿ`ßñÿ`æä@ë
¸@call_gmon_startcrtstuff.c__CTOR_LIST____DTOR_LIST____JCR_LIST____do_global_dtors_auxcompleted.6341dtor_idx.6343frame_dummy__CTOR_END____FRAME_END____JCR_END____do_global_ctors_auxhello.c_GLOBAL_OFFSET_TABLE___init_array_end__init_array_start_DYNAMICdata_start__libc_csu_fini_start__gmon_start___Jv_RegisterClassesputs@@GLIBC_2.2.5_fini__libc_start_main@@GLIBC_2.2.5_IO_stdin_used__data_start__dso_handle__DTOR_END____libc_csu_init__bss_start_end_edatamain_initlab46:~/bin$ PuTTYTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTY
-bash: PuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTY: command not found
lab46:~/bin$

It sometimes works with bash language programs though.

Text Processing

It is a basic process of typing like you would do with any text editor. There is one catch. Unix does so much more with its text editing. There are two popular text editors and both are quite unique. The “nano” editor and the “VI” editor. Nano is a basic editor that allows for the compilation of data in the simplest way possible. All that is required is the user to type it in. There are tips at the bottom that give a few of the commands nano can perform to the text within it. VI is in some terms the “ultimate” text editor. VI has two modes: the command mode and the insert mode. The command mode allows for some pretty beast tricks. Once a document is completed you can use the command mode to copy lines in the text and then plunk them somewhere else in the document. You can also use a command to change a set of words into another word. ex, changing all the “hello”'s in the document to “babies must die”. its not a necessary change but it can be done and the VI editor can do so much more.

Insert Mode (VI)

Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.

If you want to demonstrate something on the command-line, you can do so as follows:

lab46:~$ vi

~
~
~
~
~                              VIM - Vi IMproved
~
~                               version 7.2.445
~                           by Bram Moolenaar et al.
~           Modified by pkg-vim-maintainers@lists.alioth.debian.org
~                 Vim is open source and freely distributable
~
~                           Sponsor Vim development!
~                type  :help sponsor<Enter>    for information
~
~                type  :q<Enter>               to exit
~                type  :help<Enter>  or  <F1>  for on-line help
~                type  :help version7<Enter>   for version info
~
~
~
~
~
                                                              0,0-1         All

This is the VI start up and you can get here by typing “vi” on the command line. To enter the the insert mode all that is needed is for the user to hit the “i” key. Simple right. to escape you hit the “esc” key and your back to the command mode. The word insert should appear in the bottom left corner of your screen. If its not there your in the command mode. Within the text editor you can use the arrow keys to navigate and the normal keys to type nothing tricky here. Text editing can also be used to create programs that can be executed if given the right properties.

Command Mode (VI)

This is where you can do all the fun stuff to a text document. Here a basic list of commands can be found.

http://www.eng.hawaii.edu/Tutor/vi.html

This list of commands allow the user to yank lines to place them somewhere else, copy lines, replace text and much much more.

If you don't know if you are in the command mode you can spam the ESC key to get there. Usually it take just one hit but the constant flow of beeping says you are where you need to be and you can now do some wicked editing.

Extended Command Line (VI)

The extended command mode allows for the searching of key words or letters within the text. It also allows for the replacing of such text. Usually within the command mode you can enter short commands but in the extended command mode you can enter in a whole string of commands that can be used to pinpoint a distinct piece of text or pieces of text through out the text by searching for them and then replacing them with whatever you with to replace them with.

Unix Shell

The Unix shell is a GUI command-line interpreter. Basically it is a visual representation of code. It is like Windows but mostly text oriented visuals rather then picture icons and such that is provided by Windows.

This is a view of the Unix shell I work in. It has text art or pictures made from keys on the keyboard.

 __         _     _ _   __   . . [ Type 'motd' to see the original motd ]. . .
|  |   __ _| |__ / | |_/ /   . Basic System Usage:  Type 'usage' at prompt   .
|  |__/ _` | '_ \\_  _/ _ \  . Events and News:     Type 'news' at prompt    .
|_____\__,_|_.__/  |_|\___/  . Broken E-mail?_      Type 'fixmail' at prompt .
---------------------------  . Check Lab46 Ma)\:    Type 'alpine' at prompt  .
c o r n i n g -_c c . e d u  . . . . . . ..'`--`'. . . . . . . . . . . . . . .
 Lab46 is the C)\_uter & Information Scie/  ^  ^  \ment's Student Development
 Server for .'`---`'.related coursework, \ \/\/\/ /and exp_J_ation.
  .. .  .  /  <> <>  \                 .  '------'     .'`---`'. .    .  . ..
 .  Lab46 W|    A    |    http://lab46.corning_/)_    /.'b   d  \            .
 .  Lab46 H\  <\_/>  /    http://lab46.corn.'`----`'. \:   0    |t           .
 .  Help E_?_._`"`_.'     haas@corning-cc./.'<\   /> ||' V===V  /ing-cc.edu  .
  .. . .'`---`'.``  _/(              /\.  |:,___A___,| '._____.' .    .  . ..
      /.'a . a  \.'`---`'.        __(_(__ \' \_____/ /  _?_
      |:  ___   /.'/\ /\  \    .-'._'-'_.'-:.______.'.'`"""`'.
      \'  \_/   |:   ^    |  .'.' (o\'/o) '.'.      /   ^.^   \
       '._____.'\' 'vvv'  / / :_/_:  A  :_\_: \     \  `===`  /
                 '.__.__.' | :   \'=...='/   : |     `-------`
                            \ :  :'.___.':  : /
                             '-:__:__:__:__:-'
You have new mail.
Last login: Sat Oct 29 20:52:58 2011 from cpe-67-241-236-8.stny.res.rr.com
lab46:~$ alpine
Alpine finished -- Closed folder "INBOX". Kept all 25 messages.
lab46:~$ alpine
Alpine finished -- Closed folder "INBOX". Kept all 25 messages.
lab46:~$

Environment Variable

These are variables that change the processing environment. The commands “env, set, and printenv” display all environment variables and their values.

lab46:~$ env
TERM=xterm
SHELL=/bin/bash
SSH_CLIENT=67.241.236.8 56619 22
SSH_TTY=/dev/pts/1
USER=cforman
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=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:*.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:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.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:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
MAIL=/home/cforman/Maildir
PATH=/home/cforman/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
LC_COLLATE=C
PWD=/home/cforman
LANG=en_US
HISTCONTROL=ignoreboth
SHLVL=1
HOME=/home/cforman
LOGNAME=cforman
SSH_CONNECTION=67.241.236.8 56619 10.80.2.38 22
_=/usr/bin/env
lab46:~$ printenv
TERM=xterm
SHELL=/bin/bash
SSH_CLIENT=67.241.236.8 56619 22
SSH_TTY=/dev/pts/1
USER=cforman
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=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:*.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:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.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:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
MAIL=/home/cforman/Maildir
PATH=/home/cforman/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
LC_COLLATE=C
PWD=/home/cforman
LANG=en_US
HISTCONTROL=ignoreboth
SHLVL=1
HOME=/home/cforman
LOGNAME=cforman
SSH_CONNECTION=67.241.236.8 56619 10.80.2.38 22
_=/usr/bin/printenv
lab46:~$

These Variables can be changed by assigning a new value to a environment variable. Here is an example grabbed off of http://en.wikipedia.org/wiki/Environment_variable#Unix_2

ENVIRONMENT_VARIABLE=VALUE <command> notation.

Examples of environment variables include:
PATH - lists directories the shell searches, for the commands the user may type without having to provide the full path.
HOME (Unix-like) and USERPROFILE (Microsoft Windows) - indicate where a user's home directory is located in the file system.
HOME/{.AppName} (Unix-like) and APPDATA\{DeveloperName\AppName} (Microsoft Windows) - for storing application settings. Many open source programs incorrectly use USERPROFILE for application settings in Windows - USERPROFILE should only be used in dialogs that allow user to choose between paths like Documents/Pictures/Downloads/Music, for programmatic purposes APPDATA (roaming), LOCALAPPDATA or PROGRAMDATA (shared between users) is used.
TERM (Unix-like) - specifies the type of computer terminal or terminal emulator being used (e.g., vt100 or dumb).
PS1 (Unix-like) - specifies how the prompt is displayed in the Bourne shell and variants.
MAIL (Unix-like) - used to indicate where a user's mail is to be found.
TEMP - location where processes can store temporary files

unix Objective

Objective Script Understanding

I wish to test my ability to look at a peice of code and determine what each part is doing to the best of my ability before having to look up information.

Method

I will use a previously made script and observe what I did explaining each line so anyone can understand it peice by piece. I will judge myself on the amount of data i have to look up.

Measurement

#!/bin/bash
#
#
a=0
echo -n "Please enter a number: "
   read number
   until [ $number -eq 0 ]; do
   n=0
   until [ `echo "$number-2^$n" |bc` -lt 0 ]; do
      let n=$n+1
   done
   let n=$n-1
   let number=$number-`echo "2^$n"|bc`
   places=""
   for((i=0;i<$n;i++)); do
      places="${places}0"
   done
   places="1${places}"
    a=`echo "$a+$places" |bc`
done
echo "The Binary value is: $a"
exit 0

I will be explaining this script line by line to test my ability to read script.

line one = that is the required start line for a bash script. Without this the program would cease to function in any other location besides a bash shell.

line 2 and 3 are just spaces and mean nothing. text can go after the # and the script will not think of it as script.

line 4 is a echo that promts the user for a digit to convert to bianary.

line 5 reads the inputed variable

line 6 begins a loop withthe boundries of until number is equal to 0 meaning the number the user inputed is equal to 0

line 7 asigns n with the value of 0

line 8 starts another loop in which the variable has 2 to n subtracted from it until it is less then 0

line 9 sets n so that each time the loop progresses it adds one to the value of n

line 10 ends the second loop

line 11 subtracts 1 from n because 2 to the n makes it less then 0 and you dont want to go that far.

line 12 sets number no as number - 2 to the n power.

line 13 creates the places variable

line 14 starts a for loop in which i is less then n

line 15 places is equal to places represented by 0

line 16 ends the for loop

line 17 puts a 1 infront of places representing the farthest binanary digit for that specific loop.

line 18 sets a equal to a + places which is a 1 and a bunch of 0s a is 0 at start

line 19 ends until loop 1 if bounds are met

line 20 echos the answer to the user … answer is the variable a

line 21 is end script call

Analysis

Experiments

Experiment 1

Question

Can I use Gzip to unzip the file courses.html?

Resources

http://en.wikipedia.org/wiki/Gzip I should just be able to use the command gunzip and unzip the file.

Hypothesis

I believe i can unzip the archive without any issues.

I can do this because after using the command “file” i was able to see that it was a gzip file.g

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

Data

lab46:~$ file courses.html
courses.html: gzip compressed data, was "courses.html", from Unix, last modified: Wed Oct 19 19:20:57 2011, max compression
lab46:~$ gunzip courses.html
gzip: courses.html: unknown suffix -- ignored
lab46:~$
lab46:~$ mv courses.html courses.gz
lab46:~$ ls
Maildir                 archives.zip  irc             src.orig
archive1.tar.gz         bin           motd            testdir
archive2.zip            cake          public_html     testdir2
archivecompilationfile  closet        puzzlebox       testfile
archives                courses.gz    shellscripting  tmp
archives.tar.bz2        data          src
lab46:~$ gunzip courses.gz
lab46:~$ ls
Maildir                 archives.zip  irc             src.orig
archive1.tar.gz         bin           motd            testdir
archive2.zip            cake          public_html     testdir2
archivecompilationfile  closet        puzzlebox       testfile
archives                courses       shellscripting  tmp
archives.tar.bz2        data          src

Analysis

Based on the data collected:

Conclusions

It can be concluded that Gzip is a very useful tool to compress and decompress as long as the file name is correct.

Experiment 2

Question

While using the x11 terminal, what would happen if I changed the variable of $DISPLAY?

Resources

$DISPLAY is the variable that controls where the terminal displays the results of your actions on it. The variable mimics this pattern but varies from comp to comp. “flake0?.offbyone.lan:?” the ? is to replaced by the correct number corresponding to the display you wish to access.

Hypothesis

I believe i can change my variable to display on some one's computer. State your rationale.

===Experiment=I M GOING TO change my DISPLAY variable and use xeyes and hopefully xeyes will appear on the other persons computer.

Data

DISPLAAY=flake03.offbyone.lan:1
xeyes

I was not able to exactly demonstrate the results of these two line but they worked. the program xeyes worked on the other computer and not mine.

Analysis

Based on the data collected:

Conclusions

It is very fun to change you DISPLAY variable and pop stuff up on other computers. This power though should no be abused because it can become very annoying.

Retest

If you're doing an experiment instead of a retest, delete this section.

If you've opted to test the experiment of someone else, delete the experiment section and steps above; perform the following steps:

State Experiment

Whose existing experiment are you going to retest? Prove the URL, note the author, and restate their question.

Resources

Evaluate their resources and commentary. Answer the following questions:

Hypothesis

State their experiment's hypothesis. Answer the following questions:

Experiment

Follow the steps given to recreate the original experiment. Answer the following questions:

Data

Publish the data you have gained from your performing of the experiment here.

Analysis

Answer the following:

Conclusions

Answer the following: