Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #7956 > unrolled thread

Extract "Last checked" from extX filesystem

Started byVilmos Soti <vilmos@soti.ca>
First post2013-04-22 13:53 -0700
Last post2013-04-25 16:33 +0200
Articles 16 — 8 participants

Back to article view | Back to comp.os.linux.misc


Contents

  Extract "Last checked" from extX filesystem Vilmos Soti <vilmos@soti.ca> - 2013-04-22 13:53 -0700
    Re: Extract "Last checked" from extX filesystem Bit Twister <BitTwister@mouse-potato.com> - 2013-04-22 21:53 +0000
      Re: Extract "Last checked" from extX filesystem "Chris F.A. Johnson" <cfajohnson@gmail.com> - 2013-04-22 18:11 -0400
        Re: Extract "Last checked" from extX filesystem Bit Twister <BitTwister@mouse-potato.com> - 2013-04-22 22:35 +0000
          Re: Extract "Last checked" from extX filesystem "Chris F.A. Johnson" <cfajohnson@gmail.com> - 2013-04-23 03:31 -0400
            Re: Extract "Last checked" from extX filesystem gazelle@shell.xmission.com (Kenny McCormack) - 2013-04-23 08:29 +0000
              Re: Extract "Last checked" from extX filesystem Bit Twister <BitTwister@mouse-potato.com> - 2013-04-23 12:19 +0000
            Re: Extract "Last checked" from extX filesystem Bit Twister <BitTwister@mouse-potato.com> - 2013-04-23 12:01 +0000
    Re: Extract "Last checked" from extX filesystem J G Miller <miller@yoyo.ORG> - 2013-04-22 21:55 +0000
      Re: Extract "Last checked" from extX filesystem Richard Kettlewell <rjk@greenend.org.uk> - 2013-04-23 18:55 +0100
        Re: Extract "Last checked" from extX filesystem J G Miller <miller@yoyo.ORG> - 2013-04-23 19:23 +0000
          Re: Extract "Last checked" from extX filesystem Robert Riches <spamtrap42@jacob21819.net> - 2013-04-24 04:18 +0000
          Re: Extract "Last checked" from extX filesystem Richard Kettlewell <rjk@greenend.org.uk> - 2013-04-24 08:53 +0100
    Re: Extract "Last checked" from extX filesystem Vilmos Soti <vilmos@soti.ca> - 2013-04-23 13:21 -0700
      Re: Extract "Last checked" from extX filesystem Bit Twister <BitTwister@mouse-potato.com> - 2013-04-23 21:25 +0000
    Re: Extract "Last checked" from extX filesystem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-25 16:33 +0200

#7956 — Extract "Last checked" from extX filesystem

FromVilmos Soti <vilmos@soti.ca>
Date2013-04-22 13:53 -0700
SubjectExtract "Last checked" from extX filesystem
Message-ID<lqli8a8eyh.fsf@pia.msmri.medicine.ubc.ca>
Hello,

I would like to extract the "Last checked" field from
extX filesystems.

The trick is that I need it in a form something like
"seconds since epoch" so I can easily test it
programmatically for any length of time.

Unfortunately, dumpe2fs returns the field in a human
readable form, and I would like to avoid to convert
it to seconds.

Is there a way to accomplish it?

Thanks, Vilmos

[toc] | [next] | [standalone]


#7957

FromBit Twister <BitTwister@mouse-potato.com>
Date2013-04-22 21:53 +0000
Message-ID<slrnknbcg7.f7u.BitTwister@wb.home.test>
In reply to#7956
On 22 Apr 2013 13:53:26 -0700, Vilmos Soti wrote:
> Hello,
>
> I would like to extract the "Last checked" field from
> extX filesystems.
>
> The trick is that I need it in a form something like
> "seconds since epoch" so I can easily test it
> programmatically for any length of time.
>
> Unfortunately, dumpe2fs returns the field in a human
> readable form, and I would like to avoid to convert
> it to seconds.
>
> Is there a way to accomplish it?

You could try something like
  set $(dumpe2fs -h /dev/sdb5 | grep 'Last checked')
  shift 3
  _date="$@"
  _epoch=$(date --date="$date"  +%s)

  echo "$_date is $_epoch"

[toc] | [prev] | [next] | [standalone]


#7959

From"Chris F.A. Johnson" <cfajohnson@gmail.com>
Date2013-04-22 18:11 -0400
Message-ID<r4pg4a-t83.ln1@cfa.johnson>
In reply to#7957
On 2013-04-22, Bit Twister wrote:
> On 22 Apr 2013 13:53:26 -0700, Vilmos Soti wrote:
>> Hello,
>>
>> I would like to extract the "Last checked" field from
>> extX filesystems.
>>
>> The trick is that I need it in a form something like
>> "seconds since epoch" so I can easily test it
>> programmatically for any length of time.
>>
>> Unfortunately, dumpe2fs returns the field in a human
>> readable form, and I would like to avoid to convert
>> it to seconds.
>>
>> Is there a way to accomplish it?
>
> You could try something like
>   set $(dumpe2fs -h /dev/sdb5 | grep 'Last checked')
>   shift 3
>   _date="$@"
>   _epoch=$(date --date="$date"  +%s)
>
>   echo "$_date is $_epoch"

 Or:

read -a x < <(sudo dumpe2fs -h /dev/sdb6 2>/dev/null | grep 'Last checked:')
echo "${x[@]:3}"

-- 
   Chris F.A. Johnson, <http://cfajohnson.com>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

[toc] | [prev] | [next] | [standalone]


#7960

FromBit Twister <BitTwister@mouse-potato.com>
Date2013-04-22 22:35 +0000
Message-ID<slrnknbeup.j1r.BitTwister@wb.home.test>
In reply to#7959
On Mon, 22 Apr 2013 18:11:07 -0400, Chris F.A. Johnson wrote:
> On 2013-04-22, Bit Twister wrote:

>> You could try something like
>>   set $(dumpe2fs -h /dev/sdb5 | grep 'Last checked')
>>   shift 3
>>   _date="$@"
>>   _epoch=$(date --date="$date"  +%s)

Oops, _epoch=$(date --date="$_date"  +%s)

>>
>>   echo "$_date is $_epoch"
>
>  Or:
>
> read -a x < <(sudo dumpe2fs -h /dev/sdb6 2>/dev/null | grep 'Last checked:')
> echo "${x[@]:3}"

Op wanted epoch seconds. Is there any way to insert the "${x[@]:3}"
in place of my $_date variable?

_epoch=$(date --date="$_date"  +%s)

[toc] | [prev] | [next] | [standalone]


#7961

From"Chris F.A. Johnson" <cfajohnson@gmail.com>
Date2013-04-23 03:31 -0400
Message-ID<8vph4a-vdb.ln1@cfa.johnson>
In reply to#7960
On 2013-04-22, Bit Twister wrote:
> On Mon, 22 Apr 2013 18:11:07 -0400, Chris F.A. Johnson wrote:
>> On 2013-04-22, Bit Twister wrote:
>
>>> You could try something like
>>>   set $(dumpe2fs -h /dev/sdb5 | grep 'Last checked')
>>>   shift 3
>>>   _date="$@"
>>>   _epoch=$(date --date="$date"  +%s)
>
> Oops, _epoch=$(date --date="$_date"  +%s)
>
>>>
>>>   echo "$_date is $_epoch"
>>
>>  Or:
>>
>> read -a x < <(sudo dumpe2fs -h /dev/sdb6 2>/dev/null | grep 'Last checked:')
>> echo "${x[@]:3}"
>
> Op wanted epoch seconds. Is there any way to insert the "${x[@]:3}"
> in place of my $_date variable?
>
> _epoch=$(date --date="$_date"  +%s)

read last checked dow m d t y < <(sudo dumpe2fs -h /dev/sdb6 2>/dev/null | grep 'Last checked:')
epoch_seconds=$( date -d "$d $m $y $t" +%s )


-- 
   Chris F.A. Johnson, <http://cfajohnson.com>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

[toc] | [prev] | [next] | [standalone]


#7962

Fromgazelle@shell.xmission.com (Kenny McCormack)
Date2013-04-23 08:29 +0000
Message-ID<kl5gpg$aq1$1@news.xmission.com>
In reply to#7961
In article <8vph4a-vdb.ln1@cfa.johnson>,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
...
>>> read -a x < <(sudo dumpe2fs -h /dev/sdb6 2>/dev/null | grep 'Last checked:')
>>> echo "${x[@]:3}"
>>
>> Op wanted epoch seconds. Is there any way to insert the "${x[@]:3}"
>> in place of my $_date variable?
>>
>> _epoch=$(date --date="$_date"  +%s)
>
>read last checked dow m d t y < <(sudo dumpe2fs -h /dev/sdb6 2>/dev/null
>| grep 'Last checked:')
>epoch_seconds=$( date -d "$d $m $y $t" +%s )

I hate to be the bearer of bad news, but I think all these proposed
"solutions" are missing the point.  The OP was pretty clear that he was
trying to avoid using shell tricks and such to "convert" what he has (i.e.,
can get) into what he wants.

Instead, the whole point of this thread was how to get it directly - from
the file system - without having to convert it oneself.

Yes, I know this is kinda "anti-the-Unix-philosophy", which is all about
using existing tools and then hacking their output to get what you want.
But so it goes...

-- 
"They shall be attended by boys graced with eternal youth, who to the
beholder?s eyes will seem like sprinkled pearls.  When you gaze  upon that
scene, you will behold a kingdom blissful and glorious."

--- Qur'an 76:19 ---

[toc] | [prev] | [next] | [standalone]


#7964

FromBit Twister <BitTwister@mouse-potato.com>
Date2013-04-23 12:19 +0000
Message-ID<slrnkncv8j.11u.BitTwister@wb.home.test>
In reply to#7962
On Tue, 23 Apr 2013 08:29:36 +0000 (UTC), Kenny McCormack wrote:
>
> I hate to be the bearer of bad news, but I think all these proposed
> "solutions" are missing the point.

Maybe.

>  The OP was pretty clear that he was trying to avoid using shell tricks 

It was not that clear at all, in my opinion.

> and such to "convert" what he has (i.e., can get) into what he wants.

Ah, see, there is where we seem to differ. OP indicated retrieved was
in human form and did not want to have to convert it into seconds.
At that point, you could be right, or I am right in that the OP did
not want to do a bunch of calendar math to generate the seconds since epoch.

>
> Instead, the whole point of this thread was how to get it directly - from
> the file system - without having to convert it oneself.

That still remains to be seen.

> Yes, I know this is kinda "anti-the-Unix-philosophy", which is all about
> using existing tools and then hacking their output to get what you want.

I do not think so. Information supplied by the poster tends to steer
the direction of the solution.

> But so it goes...

Had the OP asked for the include .h files needed for accessing the
partition's last checked field, the thread would have a whole lot less
shell commands.  :-D

[toc] | [prev] | [next] | [standalone]


#7963

FromBit Twister <BitTwister@mouse-potato.com>
Date2013-04-23 12:01 +0000
Message-ID<slrnkncu5l.11u.BitTwister@wb.home.test>
In reply to#7961
On Tue, 23 Apr 2013 03:31:20 -0400, Chris F.A. Johnson wrote:
>>>
>>> read -a x < <(sudo dumpe2fs -h /dev/sdb6 2>/dev/null | grep 'Last checked:')
>>> echo "${x[@]:3}"
>>
>> Op wanted epoch seconds. Is there any way to insert the "${x[@]:3}"
>> in place of my $_date variable?
>>
>> _epoch=$(date --date="$_date"  +%s)
>
> read last checked dow m d t y < <(sudo dumpe2fs -h /dev/sdb6 2>/dev/null | grep 'Last checked:')
> epoch_seconds=$( date -d "$d $m $y $t" +%s )

I was afraid that would have been the solution when it failed when I
tried plugging in my "$@". 

Thank you for your time and all the help you have provided on Usenet.

[toc] | [prev] | [next] | [standalone]


#7958

FromJ G Miller <miller@yoyo.ORG>
Date2013-04-22 21:55 +0000
Message-ID<kl4bkj$t9c$1@dont-email.me>
In reply to#7956
On Monday, April 22nd, 2013, at 13:53:26h -0700, Vilmos Soti asked:

> Is there a way to accomplish it?

Grab the source code for tune2fs and change the output of

Last checked:             Fri Apr 12 14:59:34 2013

date format to seconds elapsed.

[toc] | [prev] | [next] | [standalone]


#7965

FromRichard Kettlewell <rjk@greenend.org.uk>
Date2013-04-23 18:55 +0100
Message-ID<874nexf7ye.fsf@araminta.anjou.terraraq.org.uk>
In reply to#7958
J G Miller <miller@yoyo.ORG> writes:
> Vilmos Soti asked:

>> Is there a way to accomplish it?
>
> Grab the source code for tune2fs and change the output of
>
> Last checked:             Fri Apr 12 14:59:34 2013
>
> date format to seconds elapsed.

That’s a good answer.  Alternatively one could use the e2fsprogs API,
e.g.

$ cat e2lc.c
// gcc -O2 -Wall -Wextra -Werror -o e2lc e2lc.c -lext2fs
#include <ext2fs/ext2fs.h>
#include <inttypes.h>
#include <stdio.h>

int main(int argc, char **argv) {
  errcode_t rc;
  ext2_filsys fs;
  if(argc != 2) {
    fprintf(stderr, "USAGE: e2lc DEVICE\n");
    exit(1);
  }
  if((rc = ext2fs_open2(argv[1], 0, 0, 0, 0, unix_io_manager, &fs))) {
    com_err(argv[0], rc, "%s", argv[1]);
    exit(1);
  }
  if(printf("%jd\n", (intmax_t)fs->super->s_lastcheck) < 0
     || fclose(stdout) < 0) {
    perror("stdout");
    exit(1);
  }
  return 0;
}
$ gcc -O2 -Wall -Wextra -Werror -o e2lc e2lc.c -lext2fs
$ really ./e2lc /dev/amfast/root
1344099918
$ really tune2fs -l /dev/amfast/root | grep checked
Last checked:             Sat Aug  4 18:05:18 2012
$ perl -le 'print scalar localtime 1344099918'
Sat Aug  4 18:05:18 2012

-- 
http://www.greenend.org.uk/rjk/

[toc] | [prev] | [next] | [standalone]


#7967

FromJ G Miller <miller@yoyo.ORG>
Date2013-04-23 19:23 +0000
Message-ID<kl6n3s$cs8$1@dont-email.me>
In reply to#7965
On Tuesday, April 23rd, 2013, at 18:55:05h +0100, Richard Kettlewell observed:

> That’s a good answer.

Well the probability was that one day I would eventually post
a good answer to something  ;)

> Alternatively one could use the e2fsprogs API,

Now that is an even better answer.

And the API can either be obtained from an e2fslibs-dev
package or at

   <http://e2fsprogs.sourceforge.NET>

I did previously have a look on CPAN to see if anybody had done
anything in Perl (did I type it properly this time? ;+])
but the cupboard was bare.

> Last checked:             Sat Aug  4 18:05:18 2012
> $ perl -le 'print scalar localtime 1344099918'
> Sat Aug  4 18:05:18 2012

Is it not advisable to fsck a file system at least
every 3-6 months, or is that just an urban legend?

[toc] | [prev] | [next] | [standalone]


#7971

FromRobert Riches <spamtrap42@jacob21819.net>
Date2013-04-24 04:18 +0000
Message-ID<slrnknen8m.p9p.spamtrap42@one.localnet>
In reply to#7967
On 2013-04-23, J G Miller <miller@yoyo.ORG> wrote:
> On Tuesday, April 23rd, 2013, at 18:55:05h +0100, Richard Kettlewell observed:
>
>> That???s a good answer.
>
> Well the probability was that one day I would eventually post
> a good answer to something  ;)
>
>> Alternatively one could use the e2fsprogs API,
>
> Now that is an even better answer.
>
> And the API can either be obtained from an e2fslibs-dev
> package or at
>
>    <http://e2fsprogs.sourceforge.NET>
>
> I did previously have a look on CPAN to see if anybody had done
> anything in Perl (did I type it properly this time? ;+])
> but the cupboard was bare.
>
>> Last checked:             Sat Aug  4 18:05:18 2012
>> $ perl -le 'print scalar localtime 1344099918'
>> Sat Aug  4 18:05:18 2012
>
> Is it not advisable to fsck a file system at least
> every 3-6 months, or is that just an urban legend?

If the physical disk that contains the filesystem is powered on
for about 15 minutes every three weeks, and one file is written
and then read back out, it could probably go a little longer than
that.

-- 
Robert Riches
spamtrap42@jacob21819.net
(Yes, that is one of my email addresses.)

[toc] | [prev] | [next] | [standalone]


#7972

FromRichard Kettlewell <rjk@greenend.org.uk>
Date2013-04-24 08:53 +0100
Message-ID<874newe54x.fsf@araminta.anjou.terraraq.org.uk>
In reply to#7967
J G Miller <miller@yoyo.ORG> writes:
> Richard Kettlewell observed:

>> Last checked:             Sat Aug  4 18:05:18 2012
>> $ perl -le 'print scalar localtime 1344099918'
>> Sat Aug  4 18:05:18 2012
>
> Is it not advisable to fsck a file system at least
> every 3-6 months, or is that just an urban legend?

I can’t remember the regular boot-time checks brought about by the
default settings ever having found anything worrying; rather they just
make the boot process take unreasonably long from time to time.  Others
might have different experiences.

-- 
http://www.greenend.org.uk/rjk/

[toc] | [prev] | [next] | [standalone]


#7968

FromVilmos Soti <vilmos@soti.ca>
Date2013-04-23 13:21 -0700
Message-ID<lqfvyhq9q9.fsf@pia.msmri.medicine.ubc.ca>
In reply to#7956
Vilmos Soti <vilmos@soti.ca> writes:

I am the original poster.

> I would like to extract the "Last checked" field from
> extX filesystems.

Thanks for the replies.

We have a lot of date partitions on our network, and
I just wanted to get a warning when a filesystem hasn't
been fsck'd for a couple of months.

Looks like there is no easy way to grab from an extX
filesystem the "Last checked" field in its raw form.

This is one of my beefs with Linux that I have to
parse out the useful info from anything and sometimes
write some fairly ugly code. It is one thing that I
need to parse text files or different pseudofs entries.
The problem is when the format changes from one
system to another or from one kernel to another.

Oh well.

Thanks for all who read the original post and helped me.

Vilmos

[toc] | [prev] | [next] | [standalone]


#7969

FromBit Twister <BitTwister@mouse-potato.com>
Date2013-04-23 21:25 +0000
Message-ID<slrnkndv7d.9nl.BitTwister@wb.home.test>
In reply to#7968
On 23 Apr 2013 13:21:18 -0700, Vilmos Soti wrote:
>
> The problem is when the format changes from one
> system to another or from one kernel to another.

But that is what "if" and "case" statements are for.  :-D



[toc] | [prev] | [next] | [standalone]


#7978

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-04-25 16:33 +0200
Message-ID<2022922.2QjsCcLD0n@PointedEars.de>
In reply to#7956
Vilmos Soti wrote:

> I would like to extract the "Last checked" field from
> extX filesystems.
> 
> The trick is that I need it in a form something like
> "seconds since epoch" so I can easily test it
> programmatically for any length of time.
> 
> Unfortunately, dumpe2fs returns the field in a human
> readable form, and I would like to avoid to convert
> it to seconds.
>  
> Is there a way to accomplish it?

RTFM.

man tune2fs
man locale
man awk
man date

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.os.linux.misc


csiph-web