User Tools

Site Tools


opus:spring2013:ddenunz2:start

Dan DeNunzios spring2013 Opus

Introduction

Hello my name is Dan DeNunzio, I have been working in the IT field for 15 years doing various jobs. I first gained my education and training while in the military as a network administrator for 7 years. After my time in the service I moved home to find a job and have been working at a local healthcare agency for almost 10 years as the IT Manager. My job has taken many forms and keeps me quite busy tending to the various gears of the IT machine there. I feel that I am well rounded in the technology field but lacking in the programming and alternative OS area. I am currently in my second semester at CCC and plan to transfer when finished.

unix Journals

Jan 28, 2013

  • Poking around in Lab46 trying to familiarize myself with the Unix command line.
  • What challenges are you facing with respect to the course? “How foreign Unix is…”

Feb 02, 2013

  • Just finished going over lab0x1 covering basic utilities and how to use the manual pages.
  • Learning to move around in the file system and manipulate files and folders.
  • Commands used in this lab; ls and arguments to view folder contents, cp to copy files to other directories, using mv to move files and or rename files, rm to remove files, ln to create a link to a file.
  • Linking one file to another using the -s (soft) argument created a link to the specified folder allowing the two linked directories to share the same file. Removing the file removed the file from either folders view. Removing the link removed the connection between the two directories.
  • Finally Manual pages were used to gather more information about individual commands and their arguments.

Feb 10, 2013

  • Familiarizing with the Unix file system, root directory and sub dirs. cd /, ls -l, cd home , cd myusername
  • Found /usr/games …fun, cannot open root or lost+found, also found games under /var/games/bsdgames
  • From root going home; cd home, cd username
  • Using pwd utility alot while exploring fs directories ex: pwd command issued while in /tmp directory displays: /tmp
  • Familiarization with absolute and relative path names. List directories to see attributes and note different ownership and group as well as other obvious attributes such as size and date as well as permissions. changing to any directory and using pwd will show that each folder although having the same name is in its own file path and different from another file similarly named.
  • Using the . and .. directory. . referring to your present directory and .. referring to the parent directory to which you are in.
  • Looked at miscellaneous files and folders to review permissions, owners and file types.
  • Reviewed file permissions and attributes, used chmod to change permissions on lab2 directory.
  • $ chmod 701 lab2
  • Similarly-named entities in the fs.
  • UNIX Directory Structure:
  • /
  • | +-var/
  • | | +-mail/
  • | | | +-ddenunz2/
  • | +-home/
  • | | +-ddenunz2/
  • | | | +-bin/
  • | | | +-lab2/
  • | | | +-public_html/
  • | | | +-src/
  • | | | | +-submit/
  • | | | | | +-Makefile

Feb 18, 2013

Somehow I missed doing the second part of this past week’s work regarding unconventional naming.

  • Reviewed special characters to accommodate spaces in file names. ( *, \, “”, or '' )
  • * wildcard - Working in the /badname/exercise directory using the * wildcard to open files worked fine for most files not already beginning with a special character. Using cat comp* to open compress “this” file.data indicated that the file has spaces and double quotes in its name, duh. $ cat just* was used to read just a simple file.txt where we now know it is a simple name but could be simpler without the spaces, thanks again spaces. Finally I decided to get a little daring and $ cat 'ls* which went really well, just kidding, I locked up my session and had to restart putty. Reconnected and back to daring; where $ cat ???* gave me a whole bunch of information. Fun… questionable, interesting yes. '!' symbol reference from ??? can you delete me ???.abc reminds me of vi editor, some of my Unix memory IS still there…wq!
  • \ escape – seems like a pain typing \ all the time, using the \ character to cat one,\ ‘two’,\ three,\ “four” = \torture, returned no such file … maybe I typed something wrong, not typing that again, this file is a good candidate for “ “ or the wild card. Not having any luck with the rest of the files using the \ character. Used cat just\ a\ simple\ file.txt just to be sure I was doing things correctly and again I am reassured by knowing that this would be simpler without the spaces.
  • “ “ shell quoting – made trying to read the remainder of the files a little easier. cat “#pico28903#” wants to be a pico temp file. cat “* watch out! *” reminds me again of cautiously using the ‘!’. So far I think I’ll be sticking to the wildcard and “ “.
  • The challenge directory – after several unsuccessful attempts I realized I needed to use rm./'- challenge round -'

“Using the redundant ./ directory information prevents the dash from occurring at the beginning of the file name, and being interpreted as an option of the rm command.” -kb.iu.edu/data/abao.html - web

Feb 27, 2013

LAB 0X3

  • Commands used: cat, head, tail, wc
  • cat - used to read files and output contents
  • wc - when used with the -l argument, displays only the line count, wc –help for more. The file passwd has 27 lines.
  • head - by default prints the first 10 lines of a file to STDOUT. Using the -n option along with specifying the number of lines prints the first X number lines of text. i.e. head -n16 passwd displays the first 16 lines of the passwd file.
  • tail - by default displays the last 10 lines of the file specified. Using tail witht eh -n option followed by an number displays the last X number of lines of a file. i.e. tail -n passwd prints the final 8 lines of text to STDOUT.
  • Using cat > myfile to create a file named myfile, entered some text.
  • tail - reads the last few lines of any given file. Using the -f option (follow) outputs any appended data as the file grows .
  • The -f option for tail could be useful when reading a log file that is constantly updated.

VIM Tutorial

  • The Basics
  • Cursor navigation - h ←, k ↑, l →, j ↓
  • ESC for command mode
  • Exit vim with out saving- :q!
  • Save and exit - :wq or SHIFT+zz
  • x - deletes selected character
  • i - inserts , or a in command mode to append
  • Operators and Motions
  • d operator
  • Delete words dw command - use dw at the beginning of the highlighted word to delete.
  • d$ - delete all characters to the end of the line.
  • dnw - delete multiple words
  • ndd - delete multiple lines
  • Undo - command u will undo previous changes.
  • Apprentice level
  • vim saves deleted characters to memory and can be pasted to the cursor with p
  • r can be used to replace a character rg would replace a selected character with g.
  • ce - changes the selected word, c$ changes everything to the end of the line.
  • Experienced level
  • Advanced nav - end of file G, beginning of file gg, nG to get to line n, CTRL+g displays file info.
  • Search Text - /, ? /edit searches for the word edit in the forward direction and ?edit would search backwards in the file for the word edit. Previous search N.
  • Substitute - first occurrence of this word with that word :s/this/that/
  • Substitute - all occurrences of this word with that word in line :s/this/that/g
  • Substitute - all occurrences of this word with that word in file :%s/this/that/g
  • Veteran level
  • external commands while editing a file can be executed by :!thecommand, i.e. :!ls or :!date
  • Saving to a file with out quitting - :w writes to file w/out quitting, :w bash.sh writes to the bash.sh file.
  • Selecting text and writing it to a different file with :w<filename>
  • Append / merge content of one file into your currently opened file. Use the r operator. :r myfile.txt will retrieve content of the myfile.txt and insert it to your currently opened file. The place where the text will be inserted depends on you cursor position.
  • Expert level
  • o operator - :o inserts a line below the cursor while O (SHIFT+o) inserts a new line above the cursor.
  • Copy with the y (yank) operator - yy copies the selected line, nyy copies n lines from cursor
  • : set number, shows line numbers
  • The .vimrc file - located in your home directory, can be used to setup the background, font color and other preferences. edit ~/.vimrc to customize vim environment.

The Puzzle Box

  • file utility performs test to determine the file type of a file. Three tests are performed in order (filesystem, magic number and language tests), the first to succeed prints the file type.

March 09, 2013

LAB 0X4

  • Commands operators and variables
  • echo - prints to terminal
  • apropos - uses words as arguments to print out all available commands related to the argument.
  • grep - grabs text
  • pipe | - used as a filter
  • redirection >, » - sends output to a file or appends to a file.
  • Wild cards (*) and (?)
  • File descriptors - STDIN(0), STDOUT(1), STDERR(2)
  • wc - word count
  • cal - calendar

Dot - Files

  • using -a argument with ls in home directory I can see the hidden files of the dir (.bash_history, .bash_logout, .bashrc, .* etc…)
  • edited .signature file to include requested information using vi, i, enter text, esc, shiftZZ, cat .sig file
  • cat of .bash_history looks a log of commands used, hmmm how embarrassing, not like I didn't know it was there, smile and move on.
  • Using “printenv” lists my environment variables
  • SHELL=/bin/bash
  • MAIL=/home/ddenunz2/Maildir
  • TERM=xterm
  • PATH=/home/ddenunz2/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin

echo utility

  • echo $PATH - /home/ddenunz2/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin
  • declaring variable; $ var1=“UNIX Shell”

Command Aliases

  • alias ls='ls –color=auto'
  • ls has a color=auto, after unalias ls the ls no longer shows file type colors. ls –color adds the file color indicator .
  • command arguments are additional words or characters that follow a command and give the command information about what to do.
  • Recreating the alias for ls was a bit problematic as I kept forgetting the quotes, but I got it using: lab46:~$ alias ls='ls –color=auto' , ls now displays beautifully in color again. This session anyway…

History

  • !history_number - run indicated command by history number
  • history displays that my “you got it” line is 559.
  • $ !559 returns “you got it”
  • Using the up arrow to cycle through prompt history shows echo “you got it”. The last command given to the shell. This is very useful for commonly used commands in history.

Tab completions

  • using tab to complete commands and path names
  • cd /u , tab completes the path with cd /usr/
  • /b, tab completes more of the path cd /usr/bin
  • current working dir is now /usr/bin
  • $ ls v, tab beeps, tab again
  • using part of name to tab complete, keep adding characters to tab i.e. $ls vim gave some files starting with vim, adding t narrowed tabs search to vimtutor
  • $ ls vimt ←tab

March 20, 2013

LAB 0X5

Creating files with the touch utility

  • Created the listed files: file1, file2, file3, file4, file1234, fileZZZ and file41 using touch utility.
  • /shell$ touch filex

Using wildcards

  • Listing my directory with $ ls file* returns files beginning only with “file”
  • Listing my directory with $ ls file? returns only files beginning with the word “file” and having only one additional character.
  • Listing my directory with $ ls file[24a]* returns only files beginning with the word “file” and having the characters 2 or 4or a in its name. The command returned (file2, file4 and file41)

I/O Redirection

  • lab46:~/shell$ cat /etc/motd > file1 directed the output of motd to file1
  • I thought lab46:~/shell$ echo “-this is text-” » file1, would append “-this is text-” to file1, however cat file1 displayed only “-this is text-”.
  • lab46:~/shell$ echo “more text…” > file1, over wrote file1 with “more text…” as I suspected this time as the redirection operator was used.
  • lab46:~/shell$ ls file* | grep “file1” > file2, filtered the list command for files with “file1” in the name and sent the output to file2.

Filtering unwanted information

  • lab46:~/shell$ ls file555

ls: cannot access file555: No such file or directory

  • lab46:~/shell$ ls file555 > /dev/null does not hide the error
  • lab46:~/shell$ ls file555 2> /dev/null, the use of the STDERR redir operator hid the error message.

Pagers

  • For a long listing of the /bin directory use $ ls -l /bin
  • In order to page through the output of the long listing pipe the command to less
  • lab46:~/shell$ ls -l /bin | less

Quotes

  • ` - back quote allows command expansion
  • ' - single quote is literal and does not allow expansion
  • “ - double quote allows variable expansion
  • echo “$PATH” - displayed the directories for PATH as the double quotes allow variable expansion
  • echo '$PATH' - literally returned $PATH as the single quotes defined a literal expression.

Mar 25, 2013

Web Pages Exercise

Apr 04, 2013

Simple script

  • Created script1.sh with ls, df and who commands listed.

Running Script1.sh

  • Permission denied - checking file permissions with ls -l shows me that the owner has rw and everyone else is read only.
  • Correcting permissions - Using $ chmod 711 script1.sh corrected file permissions to owner rwx and all others execute only. A quick ls -l to review changes and the script works.

Simple I/O

  • Reviewed use of echo and read commands. As I recall “echo” displays standard output and read is a way to receive standard input.

Arithmetic

  • Playing with the commands at the prompt certainly helped to clear things up before going back and forth with editing age.sh. I could not get the date command to display only the tear and store to a variable in my script. I ended up using:

read birth_year current_year=2013 let age=current_year-birth_year echo your age is $age

I was trying

read birth_year current_year='date +”%Y“' let age=current_year-birth_year echo your age is $age

HAHA!

read birth_year current_year=$(date +”%Y“) let age=current_year-birth_year echo your age is $age

WORKS! -

shabang

  • Due to the many shells available all having alternative syntax to which a user could be working from the 'shabang' facility can be used to launch a specific shell in which to run your scripts. The shabang format can be written as follows: #!/path/to/shell/ -options, i.e. for bash: #!/bin/bash

Selection Statements

  • The 'if' statement - was used to evaluate the difference between two variables, in this case num1 and num2.
  • elif - else if statement was used for a catch-all statement to address when the two if conditions are false.
  • Notable information from Lab 0x6 , Shell Scripting Concepts:
    • an if block can have multiple elif statements
    • can only have one if and one else statement within an if block
    • you only need one terminating fi
    • must have spaces surrounding the [ and ] commands from conditional logic
    • must have spaces between each element of the condition
    • double quotes aren't required, but good means of preventing more serious errors if either variable is NULL.
    • the semi-colon is a command separator, alternately you can just put the following command on the next line i.e. then

Selection

  • still working on the logic, I'm definitely not guessing the correct number every time. Plus I want the guessing game to end once I have selected the correct number. TBC

lab46:~$ vi guess1.sh

#!/bin/bash pick=$1)

echo “$pick” echo “Pick a number between 1 and 20:” read num1 if [ “$num1” -eq “$pick” ] ; then

echo "Congratualtions $num1 was the randomly selected number!"

else

echo "Sorry try again, pick another number between 1 and 20:"

read num2 fi

if [ “$num2” -eq “$pick” ] ; then

echo "Congratulations $num2 was the randomly selected number!"

else

echo "Sorry try again, pick another number between 1 and 20:"

read num3 fi

if [ “$num3” -eq “$pick” ] ; then

echo "Congratualtions $num3 was the randomly selected number!"

else

echo "Sorry try again, select another number between 1 and 20:"

read num4 fi

if [ “$num4” -eq “$pick” ] ; then

echo "Congratualtions $num4 was the randomly selected number!"

else

echo "Sorry $num4 was not the randomly selected number"

fi

Apr 09, 2013

Numeric Loop, finally got this to not cover my screen in the number 20!

#!/ in/bash

for 2) ; do echo -n “$i ” ; done

Apr 20, 2013

Job Control and Multitasking

UNIX by nature proves to be a multitasking OS just by the ability of providing multiple terminals and the use of daemons to perform routine tasks with in the system. Navigating these terminals and knowing how to take advantage of UNIX multitasking abilities will enable one to use the system more efficiently and effectively. Some of the basic commands used to take advantage of the systems multitasking abilities are ps, top, jobs, fg and kill.

ps - for “process” outputs a list of processes you are currently running, adding options can output additional information or more specific information on the processes running.

  • Options a, u, x - a, stands for all, listing all processes running including from other users. The addition of the x option outputs all activity including daemon processes.
  • Simply using ps shows my current running processes as seen below:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ddenunz2 24433 0.0 0.0 11000 1400 pts/38 TN 14:13 0:00 top ddenunz2 24508 0.0 0.0 8588 992 pts/38 RN+ 14:47 0:00 ps u ddenunz2 24569 0.0 0.1 13636 2012 pts/38 SNs Apr20 0:01 -bash ddenunz2 30390 0.0 0.0 13596 12 pts/41 SNs Jan26 0:00 /bin/bash ddenunz2 30394 0.0 0.1 42516 2396 pts/41 SN+ Jan26 14:51 irssi

  • ps -u lists all process in user oriented format.

lab46:~$ ps aux | grep inetd root 947 0.0 0.0 8328 120 ? Ss Jan14 0:00 /usr/sbin/inetd ddenunz2 24886 0.0 0.0 10092 876 pts/38 SN+ 15:00 0:00 grep inetd

Top - displays processes running in real time and in addition some system information such as CPU and memory usage, up time and connected users.

  • Using “O” oh - allows for selecting a sort field. The currently selected sort field is indicated by an “*”.
  • At current time the system does not appear to be all that busy. My “top” process along with some users irssi process are the only things altering back and forth between top CPU usage. Sorting the processes by memory usage shows that users running eggdrop, python, irssi and root's sshd are among the top memory users.

Running in the Background

  • From /var/public/unix/multitask I copied the count.c file to my home directory.
  • count.c is an ASCII C program text file, determined by using the file command.
  • lab46:~$ gcc -o count count.c
  • ./count
  • Returns “The number is 33554432.000000”
  • Timing the count output took 33.4 seconds. The output file contains “The number is 33554432.000000”.
  • Running count in the background seemed to complete quicker and was using 90 - 100% of the CPU during process.

Command Separator Task 1

  • Used the following command line to delay the output of the ls command to the .txt file, I enclosed the command in parenthesis to run the sequence as one command and to allow it to run in the background.
  • lab46:~$ (sleep 8 ; ls -l /var > multitask.lab.txt)&

Task2

  • After suspending “cat-” and links http://localhost&” and attempting to log out I am prompted with a message that states there are stopped jobs.
  • The purpose of the stopped jobs message when attempting to log out could be in place to allow the user to ensure they actually want to kill or terminate the jobs. Typing logout a second time will log the user out and kill the processes.
  • My links job is number 2 [26159]
  • foregrounding the links job brings up the requested page. ctrl+z re-suspended the process.
  • After ending cat - , jobs lists the links process as running. Bringing back the links process and exiting closes the process and no longer appears in the jobs list.

Killing Processes

  • Hangup signal [1] SIGHUP
  • Terminate signal [15] SIGTERM
  • Kill signal [9] SIGKILL
  • Interrupt signal [2] SIGINT

Who output with two login instances:

Last login: Sun Apr 21 16:25:49 2013 from dynamic-acs-64-22-55-242.zoominternet. net lab46:~$ who NAME LINE TIME IDLE PID COMMENT mgough + pts/7 2013-01-17 10:26 old 29872 (rrcs-50-75-106-214:S .0) synack + pts/9 2013-04-14 02:30 old 28070 (69.194.56.177) smalik2 + pts/18 2013-01-20 15:14 old 26721 (mobile-198-228-195-0 67:S.0) wedge - pts/24 2013-04-21 07:38 00:30 21527 (10.80.81.2) smeas + pts/33 2013-02-27 20:11 04:38 3474 (li583-226:S.0) mowens3 + pts/64 2013-04-21 16:52 00:33 26002 (cpe-69-205-136-233.s tny.res.rr.com) ddenunz2 + pts/71 2013-04-21 17:25 . 26274 (dynamic-acs-64-22-55 -242.zoominternet.net) wedge - pts/70 2013-04-21 17:03 . 26138 (10.80.81.2) ddenunz2 + pts/41 2013-01-26 11:06 old 30390 (dynamic-acs-64-22-55 -242:S.0) jcavalu3 + pts/54 2013-04-19 15:48 old 15136 (10.80.3.174) mowens3 + pts/62 2013-04-21 16:33 00:51 25583 (cpe-69-205-136-233.s tny.res.rr.com) thakes3 + pts/53 2013-04-12 12:02 old 10983 (caprisun.offbyone.la n) ddenunz2 + pts/38 2013-04-21 16:25 00:03 25559 (dynamic-acs-64-22-55 -242.zoominternet.net) mgough + pts/0 2013-03-09 00:09 15:54 2545 (rrcs-50-75-106-214:S .1) tedmist1 + pts/94 2013-03-20 11:51 22:24 20894 (lab46.offbyone.lan) lab46:~$

  • The terminal device for each session is 71 and 38 and found an old one 41.
  • I killed the two older sessions using the kill command followed by the process ID. The old session would not go away after checking who. kill -9 finally removed the old session.

Applying my Skills 11. a.) ps -u statd

  b.) lab46:~$ ps -A | grep 'init'

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 8356 92 ? Ss Jan14 1:40 init [2]

The PID for init is 1.

  c.) root owns the cron process. Cron is driven by a configuration file that schedules the processing of jobs for users and daemons.
1)
RANDOM % 20
2)
i=20; i>=2; i-=2
opus/spring2013/ddenunz2/start.txt · Last modified: 2013/08/25 12:16 by 127.0.0.1