954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Unix shell access from Perl script

Hello everyone. I am writing a Perl script that will be installed on a Linux host. I need the script to be able to access the current time / date environment variable somtimes. I've looked through a list of the standard CGI variables that can be accessed through $ENV but time / date isn't one of them. Is it possible to pass commands to the host's shell from within a Perl script and have the result piped back into the script? If so I could just pass:

date


Or maybe there is a simpler way to do this that I'm missing. Any advice would be appriciated.

Steven.

Mushy-pea
Posting Whiz in Training
275 posts since Jun 2006
Reputation Points: 47
Solved Threads: 1
 

There are a few ways to get the date/time with perl:

http://perldoc.perl.org/functions/gmtime.html

http://perldoc.perl.org/functions/localtime.html

http://perldoc.perl.org/functions/time.html

or you can use backtiks to get the date from the system date function, something like:

my $date = `/bin/date +"%a, %b %d, %Y"`;
KevinADC
Posting Shark
921 posts since Mar 2006
Reputation Points: 246
Solved Threads: 67
 

Thanks Kevin. I'm sure one of those methods will do the job.

Steven.

Mushy-pea
Posting Whiz in Training
275 posts since Jun 2006
Reputation Points: 47
Solved Threads: 1
 

you may use also:

print scalar localtime();


Svet

lordspace
Junior Poster in Training
90 posts since May 2006
Reputation Points: 18
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You