Log in to users.cs.umb.edu
- Log in to a Windows machine
Enter your Unix username as the account name. Then enter your password.- Run the ssh client
Use the values in the table below to connect to users.
ssh configuration parameter value protocol ssh ssh version 2 ssh port 22 host users.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.- Make sure you are in your home directory
cd- Go to your it441 directory
cd it441- Go to your ex directory
cd ex- Create an ex14 directory
mkdir ex14- Go to your ex14 directory
cd ex14- Execute the script command
script- Copy over config files
for file in interfaces passwd hosts ; do cp /home/ckelly/course_files/it341_files/$file ./ ; done- Use your perlsession alias to start the re.pl script.
perlsession(NOTE: If the perlsession alias is not recognized, or if re.pl cannot run, then double-check your Perl configuration, as well as your login shell vs. subshell environments!)Regexes - Character ranges and counts
perl> $mac1 = "A0:5B:96:FC:FE:D2" ; perl> $mac2 = "5b:96:fc:fe:d2:34" ; perl> if ($mac1 =~ /([0-9A-F][0-9A-F]:)+[0-9A-F][0-9A-F]/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> if ($mac1 =~ /([\dA-F][\dA-F]:)+[\dA-F][\dA-F]/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> if ($mac1 =~ /([\dA-F]{2}:)+[\dA-F]{2}/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> if ($mac2 =~ /([\dA-F]{2}:)+[\dA-F]{2}/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> if ($mac2 =~ /([\da-f]{2}:)+[\da-f]{2}/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> if ($mac2 =~ /([\dA-F]{2}:)+[\dA-F]{2}/i) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> $not_a_mac1 = "A0:5B:96:FC:FE:D2:34:56" ; perl> if ($not_a_mac1 =~ /([\dA-F]{2}:)+[\dA-F]{2}/i) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> if ($not_a_mac1 =~ /([\dA-F]{2}:){5}[\dA-F]{2}/i) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> $not_a_mac2 = "A0:5B:D2:56" ; perl> if ($not_a_mac2 =~ /([\dA-F]{2}:){5}[\dA-F]{2}/i) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> if ($not_a_mac2 =~ /([\dA-F]{2}:){1,5}[\dA-F]{2}/i) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }Regexes - Groups, Arrays, and Positional Variables
perl> $ipStr = "Our IP address is 156.92.241.47. How nice!"; perl> if ($ipStr =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; } perl> @ipStrParts = ($ipStr =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/); perl> for $part (@ipStrParts) { print "$part\n"; } perl> @ipStrParts = ($ipStr =~ /((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))/); perl> for $part (@ipStrParts) { print "$part\n"; } perl> if ($ipStr =~ /((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))/) { print "The IP address is: $1\n\n" ; print "First Octet: $2\n" ; print "Second Octet: $3\n" ; print "Third Octet: $4\n" ; print "Fourth Octet: $5\n" ; } perl> $modifier = ""; perl> print $ipStrParts[0]; perl> for $part (@ipStrParts[1..4]) { if ($part > 255) { $modifier = "not "; last; } } perl> print "$ipStrParts[0] is " . $modifier . "a valid IP"; perl> $ipStr = "Our IP address is 156.92.341.47. How nice!"; perl> @ipStrParts = ($ipStr =~ /((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))/); perl> $modifier = ""; perl> for $part (@ipStrParts[1..4]) { if ($part > 255) { $modifier = "not "; last; } } perl> print "$ipStrParts[0] is " . $modifier . "a valid IP";Regexes - Groups, Arrays, and Positional Variables
perl> open ( INFILE , '<' , './passwd' ) or die $!; perl> @passwd_lines = <INFILE> ; perl> close (INFILE); perl> $passwd = join ("", @passwd_lines) ; perl> print $passwd ; perl> @users = ($passwd =~ /([a-z0-9]+):x/g) ; perl> print (join (", ", @users)) ; print "\n" ; perl> @data = ($passwd =~ /([a-z0-9]+):.+:(\/bin\/.*sh)/g) ; perl> %users_shells = @data; perl> foreach $k (keys(%users_shells)) { print "User: $k\nShell: $users_shells{$k}\n\n" ; }File Tests and Strings
perl> print "What file or directory should I test: "; perl> chomp($target = <STDIN>); perl> print ("Target file or directory is: ", $target, "\n"); perl> if (-e $target) { print "$target exists\n"; } else { print "$target does not exist\n"; } perl> if (-d $target) { print "$target is a directory\n"; } else { print "$target is not a directory\n"; } perl> open ( INFILE , '<' , '/home/ckelly/course_files/it441_files/filetesting.pl' ) or die $!; perl> print <INFILE> ; perl> close (INFILE); perl> $string = "foo bar blech" ; perl> print "The string \'$string\' is " . length($string) . " characters long." ; perl> print "The string \'bar\' begins at index #" . index($string, 'bar') ; perl> print "The string \'blech\' begins at index #" . index($string, 'blech') ; perl> print substr($string, 4, 3) . "\n" ; perl> print substr($string, 0, 7) . "\n" ; perl> print substr($string, 8) . "\n" ;End the Perl Session
perl> exitEnd the script session
Use the exit command. You should then have a file called typescript in your current working directory.