IT 441: Network Services Administration
Class #07 Exercise

Complete by: 3/4/2018


Log in to users.cs.umb.edu

Writing to a another terminal, instead of a file

Open a second ssh session for yourself on users.cs.umb.edu.

(No need to use script or perlsession here!)
Execute the tty command to get your terminal's path, which will be of this form: /dev/pts/23 Below, replace /dev/pts/23 with the path that the tty command gave you

perl>  open ( OUT4 , '>' , '/dev/pts/23' ) or die $!;

perl>  print OUT4 "first\n";

perl>  print OUT4 "second\n";

perl>  print OUT4 "third\n";

perl>  print OUT4 "fourth\n";

perl>  close (OUT4);
(Look at your other terminal? What happened, and why?)

Piping into your script code -- from another process

Here, we will use a Linux command to choose all the usernames that contain "ll" and read them into our script code. This is to avoid the longer output we would get from printing every username!

perl>  open ( IN5 , '-|' , 'ls /home | grep ll' ) or die $!;

perl>  while (<IN5>) { chomp ; print $_ ; print ", " ; } print "\n" ;

perl>  close (IN5);

Piping from your script code -- into another process

perl>  open ( OUT6 , '|-' , 'sort -r' ) or die $!; 

perl>  while (<STDIN>) { $_ = uc $_ ; print OUT6 $_ ; } 
At this point, it will appear to stall, but what's actually happening is this: It is waiting for you to enter lines of text. Just type something and press Enter. Then, do this again, at least four more times. When you are done entering lines of text, press Ctrl+D. This signals the end of input so that the while loop stops executing.
perl>  close (OUT6);
(What happens after you enter the line close (OUT6); ?)

Piping in both directions

perl>  open ( IN7 , '-|' , 'ls /home | grep ll' ) or die $!;

perl>  open ( OUT7 , '|-' , 'sort -r' ) or die $!; 

perl>  while (<IN7>) { $_ = uc $_ ; print OUT7 ; } 

perl>  close (IN7); 

perl>  close (OUT7);

End the Perl Session

perl>  exit

End the script session

Use the exit command. You should then have a file called typescript in your current working directory.