pico shell1.pl
#!/usr/bin/perl
#comman ways to interact with shell
#exec - older form of the newer version system. Executes commands from an shell enviroment and does not return an exit command
exec "ls -Al" || die "unable to run the process";#does not return an exit status and is deprecated
$DIR="/etc/init.d"
system "ls $DIR";#return an exit status
print "$?\n";
system "$DIR/httpd stop";
$SERVICE = "httpd";
@array1 = ("$DIR/$SERVICE","stop");
system (@array1);
print "$?\n";
if ($? == 0)
{
print "$SERVICE has been stoped\n";
}
else
{
print $SERVICE has ALREADY been stopped\n";
}
#end
/etc/init.d/httpd start
#!/usr/bin/perl
$DIR="/etc/init.d" # prints one file
$DIR="/etc/init.d/" # prints all the file
$filelist = `ls -Al $DIR | wc -l`;
@filelist = `ls -Al $DIR`;
foreach (@filelist)
{
print "$_";
}
#end
No comments:
Post a Comment