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 ex17 directory
mkdir ex17- Go to your ex17 directory
cd ex17Start Up a script Session
Execute the script command, using the --flush option
script --flushRedirecting Standard Error
- Copy 2 text files from ~ckelly/course_files/it244_files to your ex17 directory
cp ~ckelly/course_files/it244_files/foo[12].txt .- Run ls to make sure the copy operation worked
ls- Run cat on foo1.txt and foo2.txt
cat foo?.txtWhen you give cat two files as arguments, it prints the first, followed by the second.
- Run cat on a file that does not exist
cat xxx.txtcat sends an error message to standard error, which is the terminal by default.
- Run cat on two files, one nonexistent, sending standard output to a file
cat foo1.txt xxx.txt > foo_xxx.txtThe error message went to the terminal, not the file.
- Print the contents of foo_xxx.txt
cat foo_xxx.txtNotice that the error message was not inserted into the file.
- Run cat on two files, one nonexistent, sending standard error to a file
cat foo1.txt xxx.txt 2> errors.txtNotice that the contents of the first file is displayed on the terminal, but not the error message.
- Print errors.txt
cat errors.txterrors.txt contains the error message that would have gone to the screen if you had not redirected standard error.
- Run cat on two files, one nonexistent, sending all output to a file
cat foo1.txt xxx.txt &> everything.txtNoting appears on the screen.
- Print everything.txt
cat everything.txtBoth the output and error message were redirected to the same fileExit Your script Session
Use the exit command
exitYou should see a confirmation message confirming that the script is finished, resulting in a file called typescriptShell Scripts
- Create a script to keep track of the contents of your current directory
nano dir_snap.sh- Enter the hashbang line
#!/bin/bash- Enter a comment describing what the script does
# # This script takes periodic snapshots of the current directory and # sends them to a file "snapshot.log"- Enter a blank line
This makes the script more readable.
- Enter a line which will record the date
date >> snapshot.logTo be useful, the log file needs a date stamp.
Notice that we are appending to a file, even though it doesn't exist at first.
If you use the append symbol >> on a file that doesn't exist, that file will be created and the output sent to it.
- Enter a line which will record the current directory
pwd >> snapshot.log- Enter a separator line
echo ------------------------ >> snapshot.logThis makes the file more readable.
- Enter a line to send a long listing for all files to the log file
ls -al >> snapshot.log- Enter a line to send a blank line to the log file
echo >> snapshot.logThis will make the log more readable.
- Enter a line to show the script is finished
echo sent directory listing to snapshot.log- Save the file and exit nano
- Re-Start Your script Session Execute the script command, using both the --flush option AND the --append option
script --flush --append- Make the file executable
chmod 755 dir_snap.sh- Look at the permissions on the script
ls -l dir_snap.sh- Run the script
./dir_snap.sh- Look at the contents of snapshot.log
cat snapshot.log- Run the script again
./dir_snap.shNotice that additional information is added to the end of the file.
- Look at the contents of snapshot.log
cat snapshot.logExit Your script Session
Use the exit command
exitYou should see a confirmation message confirming that the script session is finished, resulting in a file called typescript. I will look at the typescript file, along with the other files in your directory.