=====unix Keywords===== ■ $PATH....X ■ Job control.......x ■ wildcards......x ■ tab completion.....x ■ Cron/Crontab.......x ■ Pattern Matching.........x ■ Regular Expressions.......x ■ Shell Scripting.....x ====unix Keyword 9==== shell scripting ===Definition=== shell scripting is a small program essentialy that contains commands such as command line task such as grep, ls, mv, and cp. when you run the script it it excute these for you instead of typing all theses things. ===Demonstration=== ls ~ df who is in script.sh lab46:~$ ./script.sh Desktop archive2.zip count.c mail Documents archives data motd Downloads archivescombined.tar date multitask.lab.txt Maildir at dateyears output Music badname devel phenny Pictures badname.tgz file phenny.tar.bz2 Public bin forloop.sh script.sh Templates botscript.sh guess1.sh src Videos class_notes lab1 src.bak age.sh classlog.c lab2 the answer.txt archive1.tar.gz count loop.sh Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvda1 4128448 2522072 1396664 65% / tmpfs 784300 0 784300 0% /lib/init/rw udev 755640 36 755604 1% /dev tmpfs 784300 4 784296 1% /dev/shm /dev/xvda2 253871 12859 227905 6% /tmp nfs:/home 2930056576 1434124544 1495932032 49% /home nfs:/lib/mail 2930056576 1434124544 1495932032 49% /var/mail skinney1 pts/8 2012-03-17 11:36 (cpe-24-94-52-91.stny.res.rr.com) rmatsch pts/16 2012-03-17 11:46 (user-10bj433.cable.mindspring.com) jjohns43 pts/24 2012-01-23 12:18 (cpe-74-65-82-173:S.0) smalik2 pts/29 2012-03-17 10:49 (cpe-69-205-204-88.stny.res.rr.com) skinney1 pts/35 2012-03-16 10:15 (65-124-85-125.dia.static.qwest.net) mfaucet2 pts/65 2012-03-09 17:09 (55:S.0) smalik2 pts/27 2012-01-25 14:53 (cpe-69-205-204-88:S.0) wedge pts/28 2012-03-17 10:02 (telstar.lair.lan) jdavis34 pts/22 2012-03-06 12:57 (cpe-69-205-141-69:S.0) jjohns43 pts/82 2012-02-27 11:03 (cpe-74-65-82-173:S.0) lab46:~$ ===PATH(unix)=== ===Definition=== PATH is an environmental variable that specifies a set of directories where executable programs are located. ===Demonstration=== lab46:~$export PATH=$PATH:/home/rmatsch/src/unix ====Job control (unix)==== ===Definition=== Job control allow you to have the system work on a job in the background while you do something else . If you are simply trying to get logged out, but have encountered the "There are stopped jobs" message **Useful Commands** control-z Stop (don't kill) the foreground job, and then return to the shell Check the status of jobs in the current session ps -u username Check the status of processes, including those from other sessions. On BSD systems, use 'ps -gx'. kill -9 %1 Kill a job, by specifying its job number after the percent sign kill -9 123 Kill a process, by specifying its process id (PID) number bg Run the most recently stopped job in the background fg Bring most recently background job to the foreground fg %1 Bring a job to foreground by specifying its job number after the percent sign A daemon is a computer program that runs in the background as a process, instead of running in the foreground. below is an example of a deamon running in back ground and a command to look at the root processes. ===Demonstration=== inetd or init lab46:~$ ps -u root USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 8356 720 ? Ss Jan17 0:41 init [2] root 2 0.0 0.0 0 0 ? S Jan17 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Jan17 0:05 [migration/0] root 4 0.0 0.0 0 0 ? S Jan17 0:08 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S Jan17 0:00 [watchdog/0] root 6 0.0 0.0 0 0 ? S Jan17 0:04 [migration/1] root 7 0.0 0.0 0 0 ? S Jan17 0:03 [ksoftirqd/1] root 8 0.0 0.0 0 0 ? S Jan17 0:00 [watchdog/1] root 9 0.0 0.0 0 0 ? S Jan17 5:40 [events/0] root 10 0.0 0.0 0 0 ? S Jan17 3:53 [events/1] root 11 0.0 0.0 0 0 ? S Jan17 0:00 [cpuset] root 12 0.0 0.0 0 0 ? S Jan17 0:00 [khelper] root 13 0.0 0.0 0 0 ? S Jan17 0:00 [netns] root 14 0.0 0.0 0 0 ? S Jan17 0:00 [async/mgr] root 15 0.0 0.0 0 0 ? S Jan17 0:00 [pm] root 16 0.0 0.0 0 0 ? S Jan17 0:00 [xenwatch] root 17 0.0 0.0 0 0 ? S Jan17 0:00 [xenbus] root 18 0.0 0.0 0 0 ? S Jan17 0:06 [sync_supers] root 19 0.0 0.0 0 0 ? S Jan17 0:07 [bdi-default] root 20 0.0 0.0 0 0 ? S Jan17 0:00 [kintegrityd/0] root 21 0.0 0.0 0 0 ? S Jan17 0:00 [kintegrityd/1] root 22 0.0 0.0 0 0 ? S Jan17 0:00 [kblockd/0] root 23 0.0 0.0 0 0 ? S Jan17 0:00 [kblockd/1] root 24 0.0 0.0 0 0 ? S Jan17 0:00 [kseriod] root 27 0.0 0.0 0 0 ? S Jan17 0:00 [kondemand/0] root 28 0.0 0.0 0 0 ? S Jan17 0:00 [kondemand/1] root 29 0.0 0.0 0 0 ? S Jan17 0:02 [khungtaskd] root 30 0.0 0.0 0 0 ? S Jan17 0:20 [kswapd0] root 31 0.0 0.0 0 0 ? SN Jan17 0:00 [ksmd] root 32 0.0 0.0 0 0 ? S Jan17 0:00 [aio/0] root 33 0.0 0.0 0 0 ? S Jan17 0:00 [aio/1] root 34 0.0 0.0 0 0 ? S Jan17 0:00 [crypto/0] root 35 0.0 0.0 0 0 ? S Jan17 0:00 [crypto/1] root 38 0.0 0.0 0 0 ? S Jan17 0:00 [khvcd] root 123 0.0 0.0 0 0 ? S Jan17 0:14 [kjournald] root 170 0.0 0.0 10408 4 ? S ====unix Keyword 12==== cron/crontab ===Definition=== cron tab is a task scheduler.It is a time based which runs periodically at certain times or dates, used to automate system processes. ===Demonstration=== lab46:~$ crontab -e # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any').# # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command ====Wild Cards(Unix)==== ==Definition== characters that are very powerful and help a great deal when in UNIX. the special characters enable a user to control the output of commands without having to specify the exact name of a file. ==demonstration== * zero or more of “any” character ? used to represent one of “any” character \ will ignore such things as space if the variable name isn't one string. ” ” (or ' ') quote the enclosed characters [ ] character class - match any of the enclosed characters. [^ ] inverted character class - do not match any of the enclosed characters. ====pattern matching(unix)==== ===Definition=== Pattern matching a way to search in unix which enables the user to look for files. ===Demonstration=== Using ls(1), list files that match the following patterns: a. Only files that begin with a lowercase vowel. b. All files that end with a .s c. All files that do not start with a vowel, yet end with a .s d. Only 3 character filenames that don't end with a consonant. e. Explain your strategy and reasoning for constructing an effective pattern for each part of this question a. Using ls in the given directory, show me how you'd list only files that begin with a lowercase vowel: ls a* e* i* o* u* b. Using ls in the given directory, show me how you'd list only files that end with a .s: ls *.s c. Using ls in the given directory, show me how you'd list only files that do not start with a vowel, yet end with a .s: ls [b-d,f-h,j-n,p-t,v-z]**.s d. Using ls in the given directory, show me how you'd list only the files consisting of just 3 character filenames that don't end with a consonant: lab46:/var/public/unix/patterns$ ls a* e* i* o* u* a.b.c.d.e.f.s abd i3 a39487y abe i4 a6.c abf i5.s a7.d ac.s i6.s a8.e aca i7.s a9.f ad.s ive_got_a_beautiful_feeling aaa alab5.s o_what_a_beautiful_day aab alab6.s o_what_a_beautiful_morning.s aac e11 u_2 aad e8933 uey aae e9038 uey2 aaf e904385 ueya ab.s ee.s ueyai aba everythings_going_my_way.s ueyed abb i1 uint abc i2 lab46:/var/public/unix/patterns$ ====Tab completion (unix)==== tab completion ===Definition=== tab completion is a command line feature that allows you to type some of a command and have the command line finish it when you hit the tab key. kinda like a auto complete ===Demonstration=== Demonstration of the chosen keyword. lab46:/var/public/unix/patterns$ l (tab) last less lispmtopgm lrrdNode lastb lessecho listres ls lastlog lessfile ln lsattr latin2ascii.py lesskey lnstat lscpu lcf lesspipe loadkeys lsinitramfs ld let loadunimap lsmod ld.bfd lex local lsof ld.gold lexgrog locale lspci ldapadd lft localedef lspgpot ldapcompare lft.db lockfile lsusb ldapdelete lftp lockfile-check luit ldapexop lftpget lockfile-create lwp-download ldapmodify libnetcfg lockfile-remove lwp-dump ldapmodrdn libpng-config lockfile-touch lwp-mirror ldappasswd libpng12-config loggen lwp-request ldapsearch line logger lwp-rget ldapurl link login lxterm ldapwhoami links logname lynx ldd links2 logout lynx.cur ldrdf linux32 look lzmainfo leaftoppm linux64 lorder ====unix Keyword 16==== **regular expressions** Regular Expression Symbol . Match any character * Match 0 or more of the preceding ^ Beginning of line or string $ End of line or string [ ] Character class - match any of the enclosed characters [^ ] Negated character class - do not match any of the enclosed characters \< Beginning of word \> End of word ===Demonstration=== grep '^[b-d][aeiou]' /etc/passwd =====unix Objective===== ====unix Objective==== be able to write a simple shell scipt that contains file manipulation, and irc bot configuration. ===Definition=== the objective entails making a script to do multiple task incoporatiing things which have already learned allong with new task. ===Method=== have students given many task and allow students to write all of these task in a script to be performed in a single script. ===Measurement=== tell students to creat a script to do thing they know how to do via command line and also do task they dont know. ===Analysis=== Reflect upon your results of the measurement to ascertain my achievement i did alright but there is always room for inprovmemt.