Hi, I am using CENTOS and for now, I am not able to install or to configure the istat command on Linux. So, is there a way to do the same that the shell is doing below, but not using istat command? I would appreciate any help on it.
#!/bin/sh
HOUR=0
MONTHN=0
if [ -f $1 ]
then
:
else
echo 99999999 > $2
exit
fi
LINE=`istat $1 | grep modified`
LINE2=`istat $1 | grep Owner`
DAY=`echo $LINE | awk '{ print $5 }'`
YEAR=`echo $LINE | awk '{ print $8 }'`
MONTH=`echo $LINE | awk '{ print $4 }'`
HOUR=`echo $LINE | awk '{ print $6 }'`
P1=`echo $LINE | awk '{print $8}'`
HOUR=`echo $HOUR | sed "s/://g"`
for i in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
do
MONTHN=`expr $MONTHN \+ 1`
if [ "$MONTH" = "$i" ]
then
break
fi
done
MONTHN=`expr $MONTHN \+ 100 | cut -c2-4`
echo $YEAR$MONTHN$DAY$HOUR > $2
USER=`echo $LINE2 | awk '{ print $2 }'`
echo $USER > $3
Many scripting languages can give you the information that man istat (All) provides, but I am not sure why you need to save the information to two new files ... but it is your script. For a man perl (All) replacement:
use strict;
use warnings;
use File::Basename;
use POSIX qw{ strftime };
$, = '';
$\ = "\n";
my $NAME = basename $0;
unless (0 < @ARGV) {
print STDERR 'Usage: ', $NAME, ' <file> <mtimefile> <ownerfile>';
exit 1;
}
my $file = shift @ARGV;
my @F = stat $file;
unless (0 < @F) {
print STDERR $file, ': no such file or directory';
exit 1;
}
$file = shift @ARGV;
open FH, '>', $file or die $file;
print FH strftime '%Y%m%d%H%M', localtime $F[9];
close FH;
$file = shift @ARGV;
open FH, '>', $file or die $file;
print FH $F[4], '(', scalar getpwuid($F[4]), ')';
close FH;
exit 0;
Hi ongoto, thank you for writing the script. I did what you wrote, however, the time is not returning correctly. It is returning: $H$M instead of the hour. See below the script without the comments.