Programming Question

Anonymous
timer Asked: Nov 6th, 2016

Question description

you have completed the code for the automation of the required tasks; the final step is to submit the script to the team for use. After you have incorporated any appropriate feedback into your project, one last requirement needs to be addressed.

Add to your Perl script the ability to kill a user’s processes (from shell script 3). The requirements for this task include the following:

  • Add this option to the menu.
  • Add the code/process into a subroutine.
  • Use an array to store the list of processes that need to be reviewed and killed.
  • Process the kill using the array.

Next, you have been asked by different users to explain how to compile a program in a UNIX environment.

Finally, take the following C program (save it as "power2.c"), and create it as a file in your UNIX environment:

/* power2.c -- Print out powers of 2: 1, 2, 4, 8, .. up to 2^N */
#include <stdio.h>
#define N 16
int main(void) {
int n; /* The current exponent */
int val = 1; /* The current power of 2 */
printf("/t n /t 2^n/n");
printf("/t================/n");
for (n=0; n<=N; n++) {
printf("/t%3d /t %6d/n", n, val);
val = 2*val;
}
return 0;
}
/* It prints out :
n 2^n
===============
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024
11 2048
12 4096
13 8196
14 16384
15 32768
16 65536
*/

(College of Science and Technology, n.d.)

Describe the behavior when you compile the program, with no options. What is the command that you would use to compile the code and create the executable "power2"?

Finally, compare and contrast the usage of a compiled and interpreted program.

  • Add the final Perl program along with the discussions about compiling a program and compiled versus interpreted to the section in your template "UNIX Tools."
  • Update the TOC to reflect the new section.
  • Name the document yourname_CS345__Final.doc.
  • Submit the document for grading.
  • Submit your database file to the Submission area.

Reference

College of Science and Technology. (n.d.). Retrieved from http://www.cis.temple.edu/~ingargio/cis71/code/pow...

Unix Systems Programming Project CS345-1604A-01 Professor Lawrence Todd Meadors Jivan Washington October 31, 2016 1|Page Table of Contents Section 1: Unix Programming ........................................................................................................ 3 Section 2: Unix Processes ............................................................................................................... 6 Section 3: Introduction To Perl ..................................................................................................... 14 A menu-driven Perl Program for various Unix Commands ......................................................... 16 A discussion about Perl variables………………………………………………………………..17 Section 4: Writing Perl Programs ................................................................................................. 18 A perl program that can be used to create and drop users and groups.......................................... 20 A discussion about perl's usage or regular expression…………………………………………...21 Section 5: Unix Tools ................................................................................................................... 23 TBD............................................................................................................................................... 23 Section 6: References .................................................................................................................... 24 2|Page Section 1: Unix Programming Introduction You can shut down a system in various ways, using different Unix commands. Shutting down the operating system in an orderly manner is crucial. When system boots, many processes are begun, and they need to be shut down before powering off the system. In addition to this, cached data gets misplaced if it is not cleaned from memory and saved to a disk. A successful shutdown process involves shutting down operations; cleaning information from the memory to a disk, in addition to unmounting file systems. The initial commands launch shutdown procedures, killing all on going processes. While preparing a system shutdown, one needs to determine the most appropriate controls for the system and the task at hand. A point of caution when stopping the operating system with the Stop+A sequence; This instantly breaks execution of the operating system and hence should be used as the last resort when restarting the system. The original three commands; launch shutdown procedures, killing all on going processes. These commands then write information to the disk, stopping the system processes to an acceptable run level. The script command performs all these tasks too, and it also boots the system back to the initdefault in /etc/inittab state. The /usr/sbin/poweroff command is the same as init state 5. Prompt the system administrator for all valid input parameters Command line arguments, $1...$n, are positional parameters, $0 pointing towards the actual command, shell script, function or program and $1...$n are the specific arguments to the command. The following script utilizes some special variables related to the command line. Shut down/poweroff shutdown -h now 3|Page Halt Power off Init 0 All these parameters do the same thing, that is, turn the computer off. When rebooting, use shutdown command but replace with the parameter -r (reboot) shutdown -r now Ask if a wall requires getting sent, and if yes, send the message and then ask if this is a shutdown or a reboot and process appropriately. #!bin/bash/ Input=" " echo "Does a wall need to be sent?" read input if ( "$input" = "yes" ); then echo "Sending a message to all users about the system reboot or shutdown" !wall fi echo "Is this reboot or shutdown?' read input if ( "$input" = "reboot" ); then echo "System is rebooting" read input 4|Page if ( "$input" = "rboot" ); then echo "System is rebooting" shutdown -r + 1 elif ( "$input" = "shutdown" ); then echo "System is about to shutdown" shutdown -h + 1 fi Unix Run Levels Run level is a condition of a unit in addition to the entire system that defines which system services are running. They get identified by numbers while other system administrators utilize run levels to decipher the functioning subsystems, for example, whether 1 is running, and whether the network is functioning. It is easier to follow the way Linux distribution works. The Linux distributions define the various run levels as follows; Run levels 2-5 are editable. 0 - Halting the system 1 - Single-User mode 2- Local Multi user like NFS 3 - Local multi user (networking) 4 - Not in Use 5 - Full multiuser (GUI) 6 - Reboot In every run level, the user will find a succession of links pointing towards start-up scripts found 5|Page in /etc/init.d. The identities of these links all begin as either K or S, succeeded by a numeral. If the link name starts with S, it indicates that service will start when you move into the next run level. If the link name starts with K, then the service will be killed. Section 2: Unix Processes Script No. 1: Add/Delete User and Group Operation No. 1: Add Group 6|Page Operation No. 2: Delete Group 7|Page Operation No. 3: Add User 8|Page 9|Page Operation No. 4: Delete User 10 | P a g e Script No. 2: User Process Viewer and killer Output Discussion Questions 11 | P a g e What are daemons, and what are they used for? A daemon is a type of program on multitasking OS that runs unobstructively as a background process and is not under the direct control of the user. They are usually used to perform certain actions at some predefined times or by the occurrence of a specific event. Typical examples will include the print spoolers, email handlers or other programs that perform administrative tasks for the OS. Parent process of daemon is often, but not always, the init process. Daemons are generally not interactive and have no controlling terminal. Process names of daemons usually end with letter d in *NIX type systems to indicate that the process is a daemon and to differentiate between a daemon and a normal computer program e.g. - sshd is a daemon that services the incoming ssh connections. Difference between user processes and daemons User processes are run interactively by the user from the command line terminal. Daemons on the other hand are recognised as processes which are nor bound to any terminal, nor they interact with user via command line or GUI. Daemon processes usually starts up via init process as and when a system is powered up and they remain started up after that. Init process is always the first process that is started when the system is booted up, and it remains on the system until computer is turned off; which is why a daemon is not connected to a terminal. So, even if the terminal is closed, it will not kill the daemon; signals can still be sent to our daemon processes. 12 | P a g e What are the consequences of killing a daemon using a script? Daemons are usually invoked by init which is the first process to run when the system is booted up. So, if we kill a daemon which is started by init, the system might misbehave. Say if we kill sshd, we will not be able to login to the system using ssh. However, rebooting the system will relaunch the init process, which will restart sshd and hence, ssh service will be restored. 13 | P a g e Section 3: Introduction To Perl To become familiar with Perl programs and to see how to interact with the operating system, write a Perl program that performs the following tasks: Generate a menu to ask the user for the task that he or she would like to see performed. The available tasks are as follows: Show current date and time. Show users currently logged in. Show the name of the working directory. Show the contents of the working directory. Prompt the user for the choice, and perform the system command. Also, describe how variables in Perl are handled, specifically with respect to the need for declaration and type casting. Perl Script The following is the content of my Perl script, test.pl. #! usr/bin/perl print "Enter 1 to show current date and time\n"; print "Enter 2 to show users currently logged in\n"; print "Enter 3 to show the name of current working directory\n"; print "Enter 4 to show the contents of current working directory\n"; chomp ($r = <>); if ($r==1) { 14 | P a g e system("cmd /c date /t"); system("cmd /c time /t"); } elsif ($r==2) { system("echo %username%"); } elsif ($r==3) { system("cmd /c pwd"); } elsif ($r==4) { system("cmd /c dir") } Script Results The script can be run by typing “test.pl” at the command prompt. The following screen shows what happened when the different menu options were selected by the user. 15 | P a g e 16 | P a g e Perl Variables Perl variables can be initialized without declaration (Perl Tutorial 2016). There are a total of three variable types – scalars, lists and hashes. In my Perl script, variable “$r” is self-declared when it is assigned a value from the user's input. Pearl variables do not require explicit type casting. This is known as dynamic casting (EECSUT 2016). Type casting is done automatically if an operand requires it with the operator used. In my Perl script, variable $r is casted into a scalar when it is compared with integers 1, 2, 3, or 4. 17 | P a g e Section 4: Writing Perl Programs #!/usr/bin/perl -w use strict; use feature qw(switch say); no warnings 'experimental::smartmatch'; my @pids =( 20501, 18222 ); my $choice = 0; do{ print "Admin Menu \n"; print "To add a user, press 1 \n"; print "To delete a user, press 2 \n"; print "To Add a group, press 3 \n"; print "To delete a group, press 4 \n"; print "To kill process from array, press 5 \n"; print "to exit this menu, press 6 \n"; print "Please chose an option:"; $choice =<>; chomp $choice; print "You chose option: "; print $choice; print "\n"; } while $choice < 1 || $choice > 6; given($choice) { when (1) { add_user(); } when (2) { del_user(); } when (3) { add_group(); } when (4) { del_group(); } when (5) { kill_processes();} default { print "Invalid input" } } sub kill_processes { while ( my $pid = shift(@pids)) { print "Kill process $pid? ([y]es, [n]o, [q]uit)?\n"; my $ans = <>; last if $ans =~ /^Q/i; next unless $ans =~ /^Y/i; kill 9,$pid; print "Process $pid killed\n"; 18 | P a g e } } sub add_user { my $nUsername; do { print "what is new users name?"; $nUsername = <>; #get new user name chomp $nUsername; print "Enter home dir:"; my $home = <>; chomp $home; #check that new user name is a string if ($nUsername =~ /[[:alpha:]]/) { #check to see if user exists if(getpwnam('$nUsername')){ print "User exists\n"; } else { my $nPassword; my $nPasstest; #get new user password do { print "Please add password: \n"; $nPassword = <>; print "Please re-enter password: \n"; $nPasstest = <>; } while($nPassword ne $nPasstest || length($nPassword) == 0); my $adduser = '/usr/sbin/adduser'; my $cmd = qq($adduser --home $home --gecos GECOS --disabled-login $nUsername); print $cmd; system($cmd); system("echo $nUsername:$nPassword | chpasswd"); } } else { print "Username must be alphanumeric.\n"; $nUsername = ""; } 19 | P a g e } while $nUsername eq ""; } sub del_user { my $nUsername; do { print "Enter username to delete:"; $nUsername = <>; #get new user name chomp $nUsername; #check that user name is a string if ($nUsername =~ /[[:alpha:]]/) { #check to see if user exists if(getpwnam('$nUsername')){ print "User exists. Deleting $nUsername\n"; my $deluser = '/usr/sbin/deluser'; my $cmd = qq($deluser -r $nUsername); print $cmd; system($cmd); } else { print "Username not present\n"; $nUsername = ""; } } else { print "Username must be alphanumeric.\n"; $nUsername = ""; } } while $nUsername eq ""; } sub add_group{ print "Please enter group for user: \n"; my $nGroup= <>; #add user to group if (getgrnam($nGroup)) { #check to see is group exists print $group; print "$nGroup already exists \n"; } else {#if group does not exist create group groupadd $nGroup; print $nGroup; print " has been added.\n"; my $groupadd = '/usr/sbin/groupadd'; 20 | P a g e my $cmd = qq($groupadd $nGroup); print $cmd; system($cmd); } } sub del_group{ print "Please enter group for user: \n"; my $nGroup= <>; #add user to group if (getgrnam($nGroup)) { #check to see is group exists print $group; print "Group exists. Deleting $nGroup \n"; my $delgroup = '/usr/sbin/delgroup'; my $cmd = qq($delgroup -r $nGroup); print $cmd; system($cmd); } else {#if group does not exist create group groupadd $nGroup; print $nGroup; print " does not exist.\n"; } } Discussion A regular expression(regexp) is a string of characters that represent the patterns you are viewing. The Perl's regexp syntax is very similar to other regular expressions. Mainly, there are 3 regular expression in Perl Match Regular Expression m// It is used to match a string or statement to a regular expression. E.g , $true = ($foo =~ m/foo/); This statement will set $true to 1 if $foo matches the regex, or 0 if the match fails. Substitute Regular Expression - s/// It is an extension of the match operator that allows you to replace the text matched with some new text. Syntax: s/PATTERN/REPLACEMENT/; For example, $string =~ s/dog/cat/; This statement replaces all occurrences of dog with cat. Transliterate Regular Expression - tr/// It does not use regular expressions for its search on replacement values. Syntax: tr/SEARCHLIST/REPLACEMENTLIST/cds It replaces all occurrences of the characters in SEARCHLIST with the corresponding characters in REPLACEMENTLIST. For example, #/user/bin/perl $string = 'The cat sat on the mat'; 21 | P a g e $string =~ tr/a/o/; print "$string\n"; The above script will gives the following output: The cot sot on the mot. 22 | P a g e Section 5: Unix Tools TBD 23 | P a g e Section 6: References Vivek Gite, April 20, 2012. "How to Shut down Linux Systems". Updated on July 16, 2013. Linux systems Administrators Guide, Chapter 9. http://www.tldp.org/LDP/sag/html/run-levelsintro.html Forrest, S., Hofmeyr, S. A., Somayaji, A., & Longstaff, T. A. (1996, May). A sense of self for unix processes. In Security and Privacy, 1996. Proceedings., 1996 IEEE Symposium on (pp. 120-128). IEEE. Norman Matloff. UNIX Processes. Retrieved from Department of Computer Science University of California at Davis: http://heather.cs.ucdavis.edu/~matloff/UnixAndC/Unix/Processes.pdf The Linux Information Project. (2005). Daemon Definition. Retrieved from The Linux Information Project: http://www.linfo.org/daemon.html “Introduction & Data Types” Department of Electrical Engineering and Computer Science The University of Tennessee (EECSUT) web.eecs.utk.edu/~bvz/cs460/notes/perl/perl1.html retrieved Oct 24, 2016 “Perl Variable” Perl Tutorial www.perltutorial.org/perl-variables retrieved Oct 24, 2016 24 | P a g e
Unix Systems Programming Project CS345-1604A-01 Professor Lawrence Todd Meadors Jivan Washington October 31, 2016 1|Page Table of Contents Section 1: Unix Programming ........................................................................................................ 3 Section 2: Unix Processes ............................................................................................................... 6 Section 3: Introduction To Perl ..................................................................................................... 14 A menu-driven Perl Program for various Unix Commands ......................................................... 16 A discussion about Perl variables………………………………………………………………..17 Section 4: Writing Perl Programs ................................................................................................. 18 A perl program that can be used to create and drop users and groups.......................................... 20 A discussion about perl's usage or regular expression…………………………………………...21 Section 5: Unix Tools ................................................................................................................... 23 TBD............................................................................................................................................... 23 Section 6: References .................................................................................................................... 24 2|Page Section 1: Unix Programming Introduction You can shut down a system in various ways, using different Unix commands. Shutting down the operating system in an orderly manner is crucial. When system boots, many processes are begun, and they need to be shut down before powering off the system. In addition to this, cached data gets misplaced if it is not cleaned from memory and saved to a disk. A successful shutdown process involves shutting down operations; cleaning information from the memory to a disk, in addition to unmounting file systems. The initial commands launch shutdown procedures, killing all on going processes. While preparing a system shutdown, one needs to determine the most appropriate controls for the system and the task at hand. A point of caution when stopping the operating system with the Stop+A sequence; This instantly breaks execution of the operating system and hence should be used as the last resort when restarting the system. The original three commands; launch shutdown procedures, killing all on going processes. These commands then write information to the disk, stopping the system processes to an acceptable run level. The script command performs all these tasks too, and it also boots the system back to the initdefault in /etc/inittab state. The /usr/sbin/poweroff command is the same as init state 5. Prompt the system administrator for all valid input parameters Command line arguments, $1...$n, are positional parameters, $0 pointing towards the actual command, shell script, function or program and $1...$n are the specific arguments to the command. The following script utilizes some special variables related to the command line. Shut down/poweroff shutdown -h now 3|Page Halt Power off Init 0 All these parameters do the same thing, that is, turn the computer off. When rebooting, use shutdown command but replace with the parameter -r (reboot) shutdown -r now Ask if a wall requires getting sent, and if yes, send the message and then ask if this is a shutdown or a reboot and process appropriately. #!bin/bash/ Input=" " echo "Does a wall need to be sent?" read input if ( "$input" = "yes" ); then echo "Sending a message to all users about the system reboot or shutdown" !wall fi echo "Is this reboot or shutdown?' read input if ( "$input" = "reboot" ); then echo "System is rebooting" read input 4|Page if ( "$input" = "rboot" ); then echo "System is rebooting" shutdown -r + 1 elif ( "$input" = "shutdown" ); then echo "System is about to shutdown" shutdown -h + 1 fi Unix Run Levels Run level is a condition of a unit in addition to the entire system that defines which system services are running. They get identified by numbers while other system administrators utilize run levels to decipher the functioning subsystems, for example, whether 1 is running, and whether the network is functioning. It is easier to follow the way Linux distribution works. The Linux distributions define the various run levels as follows; Run levels 2-5 are editable. 0 - Halting the system 1 - Single-User mode 2- Local Multi user like NFS 3 - Local multi user (networking) 4 - Not in Use 5 - Full multiuser (GUI) 6 - Reboot In every run level, the user will find a succession of links pointing towards start-up scripts found 5|Page in /etc/init.d. The identities of these links all begin as either K or S, succeeded by a numeral. If the link name starts with S, it indicates that service will start when you move into the next run level. If the link name starts with K, then the service will be killed. Section 2: Unix Processes Script No. 1: Add/Delete User and Group Operation No. 1: Add Group 6|Page Operation No. 2: Delete Group 7|Page Operation No. 3: Add User 8|Page 9|Page Operation No. 4: Delete User 10 | P a g e Script No. 2: User Process Viewer and killer Output Discussion Questions 11 | P a g e What are daemons, and what are they used for? A daemon is a type of program on multitasking OS that runs unobstructively as a background process and is not under the direct control of the user. They are usually used to perform certain actions at some predefined times or by the occurrence of a specific event. Typical examples will include the print spoolers, email handlers or other programs that perform administrative tasks for the OS. Parent process of daemon is often, but not always, the init process. Daemons are generally not interactive and have no controlling terminal. Process names of daemons usually end with letter d in *NIX type systems to indicate that the process is a daemon and to differentiate between a daemon and a normal computer program e.g. - sshd is a daemon that services the incoming ssh connections. Difference between user processes and daemons User processes are run interactively by the user from the command line terminal. Daemons on the other hand are recognised as processes which are nor bound to any terminal, nor they interact with user via command line or GUI. Daemon processes usually starts up via init process as and when a system is powered up and they remain started up after that. Init process is always the first process that is started when the system is booted up, and it remains on the system until computer is turned off; which is why a daemon is not connected to a terminal. So, even if the terminal is closed, it will not kill the daemon; signals can still be sent to our daemon processes. 12 | P a g e What are the consequences of killing a daemon using a script? Daemons are usually invoked by init which is the first process to run when the system is booted up. So, if we kill a daemon which is started by init, the system might misbehave. Say if we kill sshd, we will not be able to login to the system using ssh. However, rebooting the system will relaunch the init process, which will restart sshd and hence, ssh service will be restored. 13 | P a g e Section 3: Introduction To Perl To become familiar with Perl programs and to see how to interact with the operating system, write a Perl program that performs the following tasks: Generate a menu to ask the user for the task that he or she would like to see performed. The available tasks are as follows: Show current date and time. Show users currently logged in. Show the name of the working directory. Show the contents of the working directory. Prompt the user for the choice, and perform the system command. Also, describe how variables in Perl are handled, specifically with respect to the need for declaration and type casting. Perl Script The following is the content of my Perl script, test.pl. #! usr/bin/perl print "Enter 1 to show current date and time\n"; print "Enter 2 to show users currently logged in\n"; print "Enter 3 to show the name of current working directory\n"; print "Enter 4 to show the contents of current working directory\n"; chomp ($r = <>); if ($r==1) { 14 | P a g e system("cmd /c date /t"); system("cmd /c time /t"); } elsif ($r==2) { system("echo %username%"); } elsif ($r==3) { system("cmd /c pwd"); } elsif ($r==4) { system("cmd /c dir") } Script Results The script can be run by typing “test.pl” at the command prompt. The following screen shows what happened when the different menu options were selected by the user. 15 | P a g e 16 | P a g e Perl Variables Perl variables can be initialized without declaration (Perl Tutorial 2016). There are a total of three variable types – scalars, lists and hashes. In my Perl script, variable “$r” is self-declared when it is assigned a value from the user's input. Pearl variables do not require explicit type casting. This is known as dynamic casting (EECSUT 2016). Type casting is done automatically if an operand requires it with the operator used. In my Perl script, variable $r is casted into a scalar when it is compared with integers 1, 2, 3, or 4. 17 | P a g e Section 4: Writing Perl Programs #!/usr/bin/perl -w use strict; use feature qw(switch say); no warnings 'experimental::smartmatch'; my @pids =( 20501, 18222 ); my $choice = 0; do{ print "Admin Menu \n"; print "To add a user, press 1 \n"; print "To delete a user, press 2 \n"; print "To Add a group, press 3 \n"; print "To delete a group, press 4 \n"; print "To kill process from array, press 5 \n"; print "to exit this menu, press 6 \n"; print "Please chose an option:"; $choice =<>; chomp $choice; print "You chose option: "; print $choice; print "\n"; } while $choice < 1 || $choice > 6; given($choice) { when (1) { add_user(); } when (2) { del_user(); } when (3) { add_group(); } when (4) { del_group(); } when (5) { kill_processes();} default { print "Invalid input" } } sub kill_processes { while ( my $pid = shift(@pids)) { print "Kill process $pid? ([y]es, [n]o, [q]uit)?\n"; my $ans = <>; last if $ans =~ /^Q/i; next unless $ans =~ /^Y/i; kill 9,$pid; print "Process $pid killed\n"; 18 | P a g e } } sub add_user { my $nUsername; do { print "what is new users name?"; $nUsername = <>; #get new user name chomp $nUsername; print "Enter home dir:"; my $home = <>; chomp $home; #check that new user name is a string if ($nUsername =~ /[[:alpha:]]/) { #check to see if user exists if(getpwnam('$nUsername')){ print "User exists\n"; } else { my $nPassword; my $nPasstest; #get new user password do { print "Please add password: \n"; $nPassword = <>; print "Please re-enter password: \n"; $nPasstest = <>; } while($nPassword ne $nPasstest || length($nPassword) == 0); my $adduser = '/usr/sbin/adduser'; my $cmd = qq($adduser --home $home --gecos GECOS --disabled-login $nUsername); print $cmd; system($cmd); system("echo $nUsername:$nPassword | chpasswd"); } } else { print "Username must be alphanumeric.\n"; $nUsername = ""; } 19 | P a g e } while $nUsername eq ""; } sub del_user { my $nUsername; do { print "Enter username to delete:"; $nUsername = <>; #get new user name chomp $nUsername; #check that user name is a string if ($nUsername =~ /[[:alpha:]]/) { #check to see if user exists if(getpwnam('$nUsername')){ print "User exists. Deleting $nUsername\n"; my $deluser = '/usr/sbin/deluser'; my $cmd = qq($deluser -r $nUsername); print $cmd; system($cmd); } else { print "Username not present\n"; $nUsername = ""; } } else { print "Username must be alphanumeric.\n"; $nUsername = ""; } } while $nUsername eq ""; } sub add_group{ print "Please enter group for user: \n"; my $nGroup= <>; #add user to group if (getgrnam($nGroup)) { #check to see is group exists print $group; print "$nGroup already exists \n"; } else {#if group does not exist create group groupadd $nGroup; print $nGroup; print " has been added.\n"; my $groupadd = '/usr/sbin/groupadd'; 20 | P a g e my $cmd = qq($groupadd $nGroup); print $cmd; system($cmd); } } sub del_group{ print "Please enter group for user: \n"; my $nGroup= <>; #add user to group if (getgrnam($nGroup)) { #check to see is group exists print $group; print "Group exists. Deleting $nGroup \n"; my $delgroup = '/usr/sbin/delgroup'; my $cmd = qq($delgroup -r $nGroup); print $cmd; system($cmd); } else {#if group does not exist create group groupadd $nGroup; print $nGroup; print " does not exist.\n"; } } Discussion A regular expression(regexp) is a string of characters that represent the patterns you are viewing. The Perl's regexp syntax is very similar to other regular expressions. Mainly, there are 3 regular expression in Perl Match Regular Expression m// It is used to match a string or statement to a regular expression. E.g , $true = ($foo =~ m/foo/); This statement will set $true to 1 if $foo matches the regex, or 0 if the match fails. Substitute Regular Expression - s/// It is an extension of the match operator that allows you to replace the text matched with some new text. Syntax: s/PATTERN/REPLACEMENT/; For example, $string =~ s/dog/cat/; This statement replaces all occurrences of dog with cat. Transliterate Regular Expression - tr/// It does not use regular expressions for its search on replacement values. Syntax: tr/SEARCHLIST/REPLACEMENTLIST/cds It replaces all occurrences of the characters in SEARCHLIST with the corresponding characters in REPLACEMENTLIST. For example, #/user/bin/perl $string = 'The cat sat on the mat'; 21 | P a g e $string =~ tr/a/o/; print "$string\n"; The above script will gives the following output: The cot sot on the mot. 22 | P a g e Section 5: Unix Tools TBD 23 | P a g e Section 6: References Vivek Gite, April 20, 2012. "How to Shut down Linux Systems". Updated on July 16, 2013. Linux systems Administrators Guide, Chapter 9. http://www.tldp.org/LDP/sag/html/run-levelsintro.html Forrest, S., Hofmeyr, S. A., Somayaji, A., & Longstaff, T. A. (1996, May). A sense of self for unix processes. In Security and Privacy, 1996. Proceedings., 1996 IEEE Symposium on (pp. 120-128). IEEE. Norman Matloff. UNIX Processes. Retrieved from Department of Computer Science University of California at Davis: http://heather.cs.ucdavis.edu/~matloff/UnixAndC/Unix/Processes.pdf The Linux Information Project. (2005). Daemon Definition. Retrieved from The Linux Information Project: http://www.linfo.org/daemon.html “Introduction & Data Types” Department of Electrical Engineering and Computer Science The University of Tennessee (EECSUT) web.eecs.utk.edu/~bvz/cs460/notes/perl/perl1.html retrieved Oct 24, 2016 “Perl Variable” Perl Tutorial www.perltutorial.org/perl-variables retrieved Oct 24, 2016 24 | P a g e

Tutor Answer

(Top Tutor) Studypool Tutor
School: Purdue University
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors