Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1076
  • Last Modified:

Get timestamp using perl script

I am new to perl scripting,  i need a a perl script to copy a directory from remote machine to my local machine and print the filenames and its timestamp in the directory and its subdirectories which is been copied to local machine.  this perl script  should work both in unix and windows.
0
frnxx
Asked:
frnxx
3 Solutions
 
fsouzabrasilCommented:
This perl print timestamp, use this code to you.
#!/usr/bin/perl -w
#
@Month_name = ( "January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December" );
( $sec, $min, $hour, $day, $month, $year ) = ( localtime ) [ 0, 1, 2, 3, 4, 5 ];
printf  "%02d:%02d:%02d %02d %s %04d\n",
  $hour, $min, $sec, $day, @Month_name->[$month], $year+1900 ;
exit;
0
 
FishMongerCommented:
Do you want the current timestamp or the mtime or ctime of the file?

If you need the file's timestamp, then look at the stat function.
http://perldoc.perl.org/functions/stat.html


Here's a clean way to output a formatted timestamp.

#!/usr/bin/perl

use strict;
use warnings
use POSIX;

print strftime('%H:%M:%S %d %B %Y', localtime);

Open in new window

0
 
vikaskhoriaCommented:
To get the timestamp of a file in $file use the following code:



use File::stat;
use Time::localtime;

$date_string = ctime(stat($file)->mtime);
print "Timestamp of file $file: $date_string\n";

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now