CENTOS - istat

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat CENTOS - istat
# 1  
Old 11-16-2014
CENTOS - istat

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.


Code:
#!/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


Last edited by bartus11; 11-16-2014 at 07:01 PM.. Reason: Please use [code][/code] tags.
# 2  
Old 11-16-2014
Many scripting languages can give you the information that istat provides, but I am not sure why you need to save the information to two new files ... but it is your script. For a perl replacement:
Code:
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;

Which give you:
Code:
$ perl istatinfo istatinfo mtime owner
$ cat mtime
201411161938
$ cat owner
1002(derek)

for the file:
Code:
$ ls -l istatinfo
-rw-r--r--. 1 derek ludwig 588 Nov 16 19:38 istatinfo

Please format the mtime and owner to your liking.

Last edited by derekludwig; 11-16-2014 at 08:45 PM.. Reason: typo
# 3  
Old 11-16-2014
Good job derekludwig. Smilie

Not trying to one up you, but, since I already went to the trouble...

Here's the OPs script modified to work with bash (Centos standard I think).
Code:
#!/bin/bash

HOUR=0
MONTHN=0
[ -f $2 ] || touch $2
[ -f $3 ] || touch $3

if [ -f $1 ]
then
    :
else
    echo 99999999 > $2
    exit
fi

# LINE=`istat $1  | grep modified`

# LINE2=`istat $1 | grep Owner` 
 LINE=`ls -l --time-style='+%Y %m %d %H:%M' | grep $1`

# MONTH=`echo  $LINE | awk '{ print $4 }'`
YEAR=`echo  $LINE | awk '{ print $6 }'`
MONTHN=`echo  $LINE | awk '{ print $7 }'`
DAY=`echo  $LINE | awk '{ print $8 }'`
HOUR=`echo $LINE | awk '{ print $9 }'`
P1=`echo $LINE | awk '{print $1}'`

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 $LINE | awk '{ print $3 }'`
echo $USER > $3

# eof #

output
Code:
$ ls -l --time-style='+%Y %m %d %H:%M' | grep istat.sh
-rwxr-xr-x. 1 owner group  833 2014 11 16 17:58 istat.sh*
$ istat.sh targetfile mtimefile ownerfile
201411151034 > mtimefile
owner > ownerfile

I'm wondering about the usefulness of this meager output though???

Last edited by ongoto; 11-16-2014 at 11:52 PM.. Reason: fat thumb fixes & added output
# 4  
Old 11-17-2014
No worries, ongoto, I didn't think of the time-style option of ls. But if that is an available option, this could be simplified as:
Code:
ls -l --time-style=%Y%m%d%H%M $1 | awk '{ print $6; print $3; }'

# 5  
Old 11-17-2014
Do you have access to the "stat" command? IIRC that provides pretty much the same data.
# 6  
Old 11-17-2014
Quote:
Originally Posted by derekludwig
No worries, ongoto, I didn't think of the time-style option of ls. But if that is an available option, this could be simplified as:
Code:
ls -l --time-style=%Y%m%d%H%M $1 | awk '{ print $6; print $3; }'

Yeah.
That beats the sox off the script that was provided.

Cheers
# 7  
Old 11-22-2014
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.

tks.
Code:
#!/bin/bash

HOUR=0
MONTHN=0

[ -f $2 ] || touch $2
[ -f $3 ] || touch $3

if [ -f $1 ]
   then
   :
else
   echo 99999999 > $2
   exit
fi

LINE=`ls -l --time-style='+%Y %m %d $H:$M' | grep $1`

DAY=`echo  $LINE | awk '{ print $8 }'`
YEAR=`echo  $LINE | awk '{ print $6 }'`
MONTHN=`echo  $LINE | awk '{ print $7 }'`
HOUR=`echo $LINE | awk '{ print $9 }'`
P1=`echo $LINE | awk '{print $1}'`

HOUR=`echo $HOUR | sed "s/://g"`

echo  $YEAR$MONTHN$DAY$HOUR > $2

USER=`echo $LINE | awk '{ print $3 }'`
echo $USER > $3


Last edited by Scott; 11-22-2014 at 08:50 PM.. Reason: Please use code tags...
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Red Hat

RH V Centos

Hi, I have built out a new virtual production environment (VMWare, HA enabled, VMotion... all the bells & whistles) using RHEL5 VM's. I have got another ESX host that I plan to use as a pre-prod environment. To save some costs on RH subs I was thinking about installing this environment... (5 Replies)
Discussion started by: Duffs22
5 Replies

2. Red Hat

How to Upgrade Centos 5.7 using Centos 5.8 ISO image on Vmware workstation

Dear Linux Experts, On my windows 7 desktop with the help of Vmware workstation (Version 7.1), created virtual machine and installed Centos 5.7 successfully using ISO image. Query : Is this possible to upgrade the Centos 5.7 using Centos 5.8 ISO image to Centos version 5.8?.. if yes kindly... (2 Replies)
Discussion started by: Ananthcn
2 Replies

3. Shell Programming and Scripting

reformat date from istat

I would like to determine if a file is older than a particular date. I found that istat will let me see the date and time of a file older than a year, but I need to change the format. Could anyone help me reformat the following date to a variable (a one liner would be great). Output from istat -... (1 Reply)
Discussion started by: oldman2
1 Replies

4. UNIX for Advanced & Expert Users

istat ??

I got the command : istat filename shows all the file details like owner and group name. But i want to know, who has accessed the file last time. As istat shows the name of owner of that file and name of the group. istat does lots of my work but i want to know who has accessed my file... (2 Replies)
Discussion started by: varungupta
2 Replies

5. UNIX for Advanced & Expert Users

istat ??

I got the command : istat filename shows all the file details like owner and group name. But i want to know, who has accessed the file last time. As istat shows the name of owner of that file and name of the group. istat does lots of my work but i want to know who has accessed my file... (0 Replies)
Discussion started by: varungupta
0 Replies

6. UNIX for Advanced & Expert Users

HP LC2000 has message: istat=0a: LSS_PAR on ha=1 sist0=41

I have a HP Netserver 2000 running SCO UNIX 5.0.6. I get the message: istat=0a: LSS_PAR on ha=1 sist0=41 sist1=00 !!!! dstat =81 on ha=1 has DS_OPC while WAIT DISCONNECT, rp=c014f8co dsp=FD on path=1, newdsp=FD064600 WARNING: Parity Error MSG OUT=00000006 Failed, 1code=80000002 on ha=1 id... (0 Replies)
Discussion started by: dmksh
0 Replies
Login or Register to Ask a Question