Experimenting with Perl

Experimenting with Perl

Well, this is my first actual experiment with Perl. All it does is chmod 750 some fetch utilities. In my next build I want to set it up so that if the file exists, and if it doesnt, it will prompt you that the file is not on the system and it is being skipped.

#!/usr/bin/perl
# Revision 1 - 09-03-09
# Initial Build
# Chmod 750 of rcp, wget, lynx, links, elinks, scp, nc, ftp, telnet, curl

print ("Permissions?\n");
system ('chmod 750 -v /usr/bin/rcp');
system ('chmod 750 -v /usr/bin/wget');
system ('chmod 750 -v /usr/bin/lynx');
system ('chmod 750 -v /usr/bin/links');
system ('chmod 750 -v /usr/bin/elinks');
system ('chmod 750 -v /usr/bin/scp');
system ('chmod 750 -v /usr/bin/nc');
system ('chmod 750 -v /usr/bin/ftp');
system ('chmod 750 -v /usr/bin/telnet');

Lets see how this turns out over the next few days.

Update before I go to bed:

#!/usr/bin/perl
# Revision 1 - 09-03-09 0055
# Initial Build
# Chmod 750 of rcp, wget, lynx, links, elinks, scp, nc, ftp, ssh, telnet, curl
#
# Revision 2 - 09-03-09 0113
# If else statements are in place, they can handle if the file does or does not exist

print ("Permissions lol...\n");
$filename = '/usr/bin/wget';
if (-e $filename) {
print "Found $filename\n";
system ("chmod 750 -v '/usr/bin/wget'");
}
else
{ print "File $filename, not found\n";
}
$filename = '/usr/bin/curl';
if (-e $filename) {
print "Found $filename\n";
system ("chmod 750 -v '/usr/bin/curl'");
}
else
{ print "File $filename, not found\n";
}
$filename = '/usr/bin/rcp';
if (-e $filename) {
print "Founds $filename\n";
system ('chmod 750 -v /usr/bin/rcp');
}
else
{ print "File $filename, not found\n";
}
$filename = '/usr/bin/lynx';
if (-e $filename) {
print "Found $filename\n";
system ('chmod 750 -v /usr/bin/lynx');
}
else
{ print "File $filename, not found\n";
}
$filename = '/usr/bin/elinks';
if (-e $filename) {
print "Found $filename\n";
system ('chmod 750 -v /usr/bin/elinks');
}
else
{ print "File $filename, not found\n";
}
$filename = '/usr/bin/scp';
if (-e $filename) {
print "Found $filename\n";
system ('chmod 750 -v /usr/bin/scp');
}
else
{ print "File $filename, not found\n";
}
$filename = '/usr/bin/nc';
if (-e $filename) {
print "Found $filename\n";
system ('chmod 750 -v /usr/bin/nc');
}
else
{ print "File $filename, not found\n";
}
$filename = '/usr/bin/ftp';
if (-e $filename) {
print "Found $filename\n";
system ('chmod 750 -v /usr/bin/ftp');
}
else
{ print "File $filename, not found\n";
}
$filename = '/usr/bin/telnet';
if (-e $filename) {
print "Found $filename\n";
system ('chmod 750 -v /usr/bin/telnet');
}
else
{ print "File $filename, not found\n";
}
print "Permissions set to 750 across the board.\n"

And now the last revision of the night, colors.

#!/usr/bin/perl
# Revision 1 - 09-03-09 0055
# Initial Build
# Chmod 750 of rcp, wget, lynx, links, elinks, scp, nc, ftp, ssh, telnet, curl
#
# Revision 2 - 09-03-09 0113
# If else statements are in place, they can handle if the file does or does not exist
#
# Revision 3 - 09-03-09 0124
# Colors?

use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1; #reset colors after each line, otherwise everything will be green and red

print ("Permissions lol...\n");
$filename = '/usr/bin/wget';
if (-e $filename) {
print GREEN "Found $filename\n";
system ("chmod 750 -v '/usr/bin/wget'");
}
else
{
print RED "File $filename, not found\n";
}
$filename = '/usr/bin/curl';
if (-e $filename) {
print GREEN "Found $filename\n";
system ("chmod 750 -v '/usr/bin/curl'");
}
else
{ print RED "File $filename, not found\n";
}
$filename = '/usr/bin/rcp';
if (-e $filename) {
print GREEN "Found $filename\n";
system ('chmod 750 -v /usr/bin/rcp');
}
else
{ print RED "File $filename, not found\n";
}
$filename = '/usr/bin/lynx';
if (-e $filename) {
print GREEN "Found $filename\n";
system ('chmod 750 -v /usr/bin/lynx');
}
else
{
print RED "File $filename, not found\n";
}
$filename = '/usr/bin/elinks';
if (-e $filename) {
print GREEN "Found $filename\n";
system ('chmod 750 -v /usr/bin/elinks');
}
else
{ print RED "File $filename, not found\n";
}
$filename = '/usr/bin/scp';
if (-e $filename) {
print GREEN "Found $filename\n";
system ('chmod 750 -v /usr/bin/scp');
}
else
{ print RED "File $filename, not found\n";
}
$filename = '/usr/bin/nc';
if (-e $filename) {
print GREEN "Found $filename\n";
system ('chmod 750 -v /usr/bin/nc');
}
else
{ print RED "File $filename, not found\n";
}
$filename = '/usr/bin/ftp';
if (-e $filename) {
print GREEN "Found $filename\n";
system ('chmod 750 -v /usr/bin/ftp');
}
else
{ print RED "File $filename, not found\n";
}
$filename = '/usr/bin/telnet';
if (-e $filename) {
print GREEN "Found $filename\n";
system ('chmod 750 -v /usr/bin/telnet');
}
else
{ print RED "File $filename, not found\n";
}
print "Permissions set to 750 across the board.\n"

Additional reading:
http://perl.about.com/od/programmingperl/qt/perlexists.htm
http://perl.active-venture.com/lib/Term/ANSIColor.html
http://www.linuxforums.org/forum/linux-programming-scripting/116383-how-can-i-use-wget-perl.html
http://wiht.link/perl-resources

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.