Log in to pe15
- Run the ssh client
Use the values in the table below to connect to pe15.
ssh configuration parameter value protocol ssh ssh version 2 ssh port 22 host pe15.cs.umb.edu user name your Unix username Authentication method password
- Enter your password
A dialog box will appear on the screen into which you must type the password for your Unix account.
Directory for this Exercise
(When you are ready for me to check this exercise, please scroll back up to where you entered these commands!)
- Go to your ex directory
cd ~/it244/ex- Create an ex15 directory
mkdir ex15- Go to your ex15 directory
cd ex15Start Up a script Session
Execute the script command, using the --flush option
script --flushRunning a Command in the Background
- Copy bother.sh to your ex15 directory
cp ~ckelly/course_files/it244_files/bother.sh .- Run bother.sh and watch it work
./bother.sh- Stop this program
Control C- Run this program again, but this time in the background
./bother.sh &The number in brackets is the job number. The second number is the process number of the first process in the job.
- Run jobs (You'll need to type this quickly during the 5-second pause between lines being printed!)
jobsjobs shows you the job number of all running jobs, their status, and the command line that created the job.
- Run ps (You'll need to type this quickly during the 5-second pause between lines being printed!)
psbother.sh is a simple script containing a loop that never ends. Inside the loop, it sleeps for 5 seconds and then prints something. When bother.sh calls sleep, it initiates a subprocess, which you see beneath bother.sh in the listing.
Bringing a Background Job to the Foreground
- Bring bother.sh to the foreground (You'll need to type this quickly during the 5-second pause between lines being printed!)
fgYou don't have to supply a job number because there is only background job.
- Suspend this job
Control Z- Run jobs
jobsThe job still exists, but it is suspended.
- Run ps
psBoth bother.sh and it's sleep subprocess are still there.
- Send the job to the background
bgAgain, since there is no other job, you do not have to supply a job number as an argument.
- Run jobs again (Quickly!)
jobsThe job is now in the background and has resumed running.Killing a Background Job
- Run jobs to see the job number (Quickly!)
jobs- Use the job number to kill the job (Quickly!)
kill %JOB_NUMBER- Run jobs to see what happened
jobsThe job has been terminated.
- Run bother.sh in the background one more time
./bother.sh &- Run ps to get the process number for bother.sh
ps- Use this process number to kill the job
kill PROCESS_NUMBER- Run jobs to see what happened
jobsThe job has been terminated.
- Run ps to see your running processes
psbother.sh and its subprocess are gone.
The ? Metacharacter
- Create foo files 1 through 5
touch foo1.txt foo2.txt foo3.txt foo4.txt foo5.txt- Create foo files 6 through 10
touch foo6.txt foo7.txt foo8.txt foo9.txt foo10.txt- Create one last file, this one simply named foo.txt
touch foo.txt- Obtain a long listing of the contents of your ex15 directory
ls -l- Run a long listing using the ? metacharacter
ls -l foo?.txtNotice that foo.txt and foo10.txt do not appear in the listing.
Notice also that the foo files are in alphabetical order.The * Metacharacter
- Run a long listing using the * metacharacter
ls -l foo*.txtNotice that all the foo files appear, even foo.txt.
* means any additional characters, however many, even none.
- Run a long listing on using a single character and *
ls -l f*You only have to enter as many characters as are needed to distinguish the files you want from the files you don't want.
- Run a long listing using more than one *
ls -l f*o*You can use multiple instances of metacharactersThe [ and ] Metacharacters
- Use the bracket metacharacters to select foo files 1 through 3
ls -l foo[123].txt- Use a range to list foo files 1 through 5
ls -l foo[1-5].txt- List all numbered foo files except 5 and 10
ls -l foo[1-46-9].txt- List the same files as above using a shorter search string
ls -l foo[!5].txtExit Your script Session
Use the exit command
exitYou should see a confirmation message confirming that the script is finished, resulting in a file called typescriptBash Script for this Exercise
- Make sure you are in your ex15 directory
cd ~/it244/ex/ex15- Create the script ex15.sh
nano ex15.sh- Write into this file the commands you used above starting with the ? meta-charaacter
DO NOT RUN bother.sh IN THIS SCRIPT
- Save this file
Save and quit.
- Make this file executable
chmod 755 ex15.sh- Test the script
./ex15.shFix any errors you find.
If you have trouble, see me.