User Tools

Site Tools


opus:fall2011:lgottsha:part1

Part 1

Entries

August 29th 2011

Today we learned some basic commands in Unix and were given some time to “play” by using the commands to explore the system.

September 20th 2011

Today we learned about extended command mode for VI and the control key combinations that allow you to do shortcuts for things like cut and paste.These should be useful tools in speeding up things like Shell Scripting assuming i can remember them.

September 27th 2011

Today we wrote a shell script that converts numbers from base 10 (normal numbers) to base 2 (binary). This was useful because it helped understand the thinking process to develop the psuedocode for an assignment in another class where we were to make psuedocode for a binary converter. This was also useful in understand relations between commands for other Shell Scripts.

Septermber 29th

Today we learned how to write the shell script for a basic bot using II or IRC Improved. This was a useful demonstration of how multiple commands work together to form a script and how to look at coding and break it down in a manner that allows you to see what part of the script does what.

Topics

Listing Files

Listing used by typing the command ls. Listing does a variety of things. ls lists current files and directories in whatever directory you may be in while ls -l lists files running on the system, who ran them and the permissions for the files. ls -a is used to find hidden files or directories that are excluded from the standard ls command through use of a . before the name.

lab46:~$ ls
Downloads  Maildir  bin  closet  in  irc  link  longcat  motd  public_html  src  tmp
lab46:~$ ls -a
.              .config      .irssi           .ssh              closet       src
..             .dbus        .local           .viminfo          in           tmp
.117.swp       .fluxbox     .mozilla         .xinitrc          irc
.Xauthority    .gconf       .openoffice.org  .xsession-errors  link
.bash_history  .gconfd      .pine-passfile   Downloads         longcat
.bash_logout   .gvfs        .pinerc          Maildir           motd
.bashrc        .indent.pro  .profile         bin               public_html
lab46:~$ ls -l
total 16
drwxr-xr-x 2 lgottsha lab46    6 Sep 20 15:14 Downloads
lrwxrwxrwx 1 lgottsha lab46   18 Aug 28 10:37 Maildir -> /var/mail/lgottsha
drwxr-xr-x 2 lgottsha lab46 4096 Sep 29 16:46 bin
drwxr-xr-x 2 lgottsha lab46   32 Sep 15 16:17 closet
-rw-r--r-- 1 lgottsha lab46   15 Sep 29 14:59 in
drwx------ 4 lgottsha lab46   39 Sep 29 14:55 irc
lrwxrwxrwx 1 lgottsha lab46    4 Sep  1 14:45 link -> file
-rw-r--r-- 1 lgottsha lab46   58 Sep 13 15:57 longcat
-rw-r--r-- 1 lgottsha lab46 1310 Sep 15 15:15 motd
drwx-----x 2 lgottsha lab46    6 Aug 26  2009 public_html
drwx------ 3 lgottsha lab46   34 Jan 20  2011 src
drwxr-xr-x 2 lgottsha lab46   84 Sep 22 16:46 tmp

Ownership

Ownership is the display of the user who owns a file, owndership can be seen with the ls -l command which displays it in the third column of the results

lab46:~$ ls -l
total 16
drwxr-xr-x 2 //**lgottsha*//* lab46    6 Sep 20 15:14 Downloads
lrwxrwxrwx 1 lgottsha lab46   18 Aug 28 10:37 Maildir -> /var/mail/lgottsha
drwxr-xr-x 2 lgottsha lab46 4096 Sep 29 16:46 bin

Permissions

Permissions are a users consent to access a file, Viewed with the ls -l command there are permissions for editing, opening/ viewing and executable and are displayed as a W, R or X under the ls -l command. Where these are located determines who has which permissions be it the owner, another group or something else.

lrwxrwxrwx* 1 lgottsha lab46   18 Aug 28 10:37 Maildir -> /var/mail/lgottsha
drwxr-xr-x*2 lgottsha lab46 4096 Sep 29 16:46 bin
drwxr-xr-x* 2 lgottsha lab46   32 Sep 15 16:17 closet
-rw-r--r--* 1 lgottsha lab46   15 Sep 29 14:59 in

* indicates the permissions line

VI's Insert Mode

VI text editors insert mode. The mode that allows VI to actually edit text with in a file. Initially entered through the use of lower case “i” after initializing VI there are multiple other commands to enter insert mode.

#!/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}"
let a=$a+$places
done
echo "the binary value is $a"
exit 0


~
~
~
-- INSERT --                                                           1,1           All

A file in VI's insert mode.

VI's Command Mode

VI's command mode is the environment you are in when initially opening VI. In command mode you cannot edit text by typing but can use a variety of commands to perform different functions on the file instead. The simplest commands are :q to quit :w to save your file :wq to save then quit and :q! to quit without saving

#!/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}"
let a=$a+$places
done
echo "the binary value is $a"
exit 0
~
~
~
:q

A file in VI's Command Mode being given the command to quit.

Regular file

regular files are files that are not links or directories most regular files appears gray in color and can be read via the cat command.

lab46:~$ ls
Downloads  Maildir  bin  closet  in*  irc  link  longcat*  motd*  public_html  src  tmp

*indicates the regular files in my directory

Directories

Directories are places where files are stored. Much like folders for GUI users of operating systems like Windows. when shown via the ls command directories are blue and if you have permissions you may enter them via the cd command. The command for a knew directory is mkdir “Directory name”

lab46:~$ ls
Downloads* Maildir  bin*  closet*  in  irc*  link  longcat  motd  public_html*  src*  tmp*

* Indicates the directories within my home directory

Special Files

Files that are neither directories nor regular files. special files are yellow by default and usually device files thatrepresent the hardware components of the machin

lab46:/dev/input$ ls
by-path  event0  event1  mice*  mouse0*

*special files representing the Mouse

Killing a Process

killing a process sends a signal to it telling it to terminate. While there are a variety of kill commands for various situations Kill -9 will kill any process that you can kill. to kil something find the process you want via the ps command and type the kill command followed by the processes PID number.

lab46:~$ ps
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
lgottsha  2449  0.0  0.0   8580   896 pts/38   RN+  12:07   0:00 ps u
lgottsha  7752  0.0  0.1  13640  2008 pts/38   SNs  09:42   0:00 -bash
lgottsha 23924  0.0  0.1  13660  2004 pts/29   SNs  Sep20   0:00 /bin/bash
lgottsha 31149  0.0  0.6 157312  7272 pts/29   SNl+ Sep29   0:00 vi

The kill command for vi in this situation would be kill -9 31146

Shell Scripting

Shell scripting is where a script is written for the shell or command line that causes something to happen. Shell scripts for unix start with the #!/bin/bash line,the initial characters known as sh and bang and the rest of the line specifying that the script is intended to run on the bash shell. Scripts can be used for a variety of things and are considered one of the most basic programming languages.

#!/bin/bash
#B35T 5R1PT 3V4R
echo -n "please enter your name: "
read name #put user input into name
echo "Hi, $name, We've had a slight weapons malfunction here,but we're fine here now, everything fine. How're you?"
exit 0

~

The code of a simple script

Viewing Files

Viewing files is done via the cat command. When viewed the files text will be displayed on screen, however not all files are viewable. When nonviewable files are ran through car they will cause random code to appear on the screen and the user will need to crtl C to unlock their terminal. Only regular files will always be viewable.

lab46:/usr/games$ cat monop
ELF>@@@h@@@@@@À@@@@dqdq hqhq`hq`p qq`q` @@DDPåtdgg@g@Qåt/lib64/ld-linux-x86-64.so.2GNUGNU¬Pßù*Uê6Å
u½«[%+#"$&%' !)*(

3ªÏ ]-bÊ@÷qFjÃî}±2¿V
                    É(!:ÕvérO;  __gmon_start__libc.so.6fflushstrcpygetwexitsprintfsrandfopensetregidperrorsignalputsputchargetpidsbrkcallocstrlengetcharfseekctimestdoutstrcasecmpgetgid__ctype_b_locerrcreatfreadclose__ctype_tolower_locerrx_IO_getc__libc_start_mainwrit%uiee__x/0s`*Ps`Xs``s`hs`ps`xs`ss`_2.2.5s`
s`

The result of using car on a nonviewable file

lab46:~/bin$ cat Password
Ah-ah-ah. You didn't say the magic word.

The result of using cat on the file Password.

Removing files

The windows equivalent of deletion. to remove a file you'd use the rm command followed by the name of the file you want to remove and responding yes to the prompt “remove regular file 'filename'?” with yes. You can only remove files that you have permissions to.

lab46:~$ ls
Downloads  bin     in   link     motd         src  trashfile
Maildir    closet  irc  longcat  public_html  tmp
lab46:~$ rm trashfile
rm: remove regular empty file `trashfile'? yes
lab46:~$ ls
Downloads  Maildir  bin  closet  in  irc  link  longcat  motd  public_html  src  tmp

Objectives

Objective 1

State the course objective; define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?

Experiments

Experiment 1

Question

is it possible to create a “menu” to the games directory using shell scripts?

Resources

www.unix.com google

Hypothesis

That it will be possible to make a link to the games directory and show games available using the cd,echo and ls commands using the echo and cd commands will put the user in the directory and ls will display the avalible games while echo will ask the user to pick a game.

Experiment

With shell script

#!/usr/games
echo -n "would you like to play a game?:"
read word
if [ "$word" = "yes" ]
 then
        echo "`cd /usr/games`"
        echo "`ls`"
        echo "Pick a game, any game..."
else
        echo"THEN, YOU SHALL NOT PASS"
        exit 1
fi
exit 0

Data

Was unable to get directory to change to the games directory. The rest of the script worked well but was useless without the cd.

Analysis

Based on the data collected:

My hypothesis was incorrect, the script failed to execute as expected. Some variable must not be being taken into account.

Conclusions

Concept may be doable but needs something additional to support the CD command. CD will not execute because the script is taking place in a subshell.

Experiment 2

Question

What is the question you'd like to pose for experimentation? State it here.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Experiment

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

Data

Perform your experiment, and collect/document the results here.

Analysis

Based on the data collected:

  • was your hypothesis correct?
  • was your hypothesis not applicable?
  • is there more going on than you originally thought? (shortcomings in hypothesis)
  • what shortcomings might there be in your experiment?
  • what shortcomings might there be in your data?

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.

Experiment 3

Question

What is the question you'd like to pose for experimentation? State it here.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

Experiment

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

Data

Perform your experiment, and collect/document the results here.

Analysis

Based on the data collected:

  • was your hypothesis correct?
  • was your hypothesis not applicable?
  • is there more going on than you originally thought? (shortcomings in hypothesis)
  • what shortcomings might there be in your experiment?
  • what shortcomings might there be in your data?

Conclusions

What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.

opus/fall2011/lgottsha/part1.txt · Last modified: 2011/10/01 18:34 by wedge