Re: [gentoo-user] [OT] One line script for md5sum

2008-12-17 Thread Mick
On Sunday 14 December 2008, Neil Bothwick wrote:
 On Sun, 14 Dec 2008 11:47:51 +0200, Alan McKinnon wrote:
  That's why I suggested them :-) I use them a lot, especially when I
  have to run the same set of commands on 15 different hosts, then I do
  something like:
 
  for I in $(seq 1 15) ; do

 If you're using bash or zsh,you can speed this up with

 for I in {1..15}; do

Hmm, I tried this with a sequence of files that look like name0001stat.txt to 
name0198stat.txt, but when I run {0001..0198} it fails because it seems to 
ignore the zeros in 0001 and start counting from 1.  Do I need to use some 
escape character for this?
-- 
Regards,
Mick


signature.asc
Description: This is a digitally signed message part.


Re: [gentoo-user] [OT] One line script for md5sum

2008-12-17 Thread Willie Wong
On Wed, Dec 17, 2008 at 08:48:52AM +, Mick wrote:
 On Sunday 14 December 2008, Neil Bothwick wrote:
  On Sun, 14 Dec 2008 11:47:51 +0200, Alan McKinnon wrote:
   That's why I suggested them :-) I use them a lot, especially when I
   have to run the same set of commands on 15 different hosts, then I do
   something like:
  
   for I in $(seq 1 15) ; do
 
  If you're using bash or zsh,you can speed this up with
 
  for I in {1..15}; do
 
 Hmm, I tried this with a sequence of files that look like name0001stat.txt to 
 name0198stat.txt, but when I run {0001..0198} it fails because it seems to 
 ignore the zeros in 0001 and start counting from 1.  Do I need to use some 
 escape character for this?

This is one place bash's brace expansion is sorely lacking compared to
zsh. In this case you need to use the seq command from coreutils. See
man seq for more info.

In your particular case, you can do 

for I in $(seq -w 198); do ... 0$I ; done

seq is more flexible in that it allows arbitrary formatting of the
sequence using printf floating-point format. 

W

-- 
Willie W. Wong  ww...@math.princeton.edu
408 Fine Hall,  Department of Mathematics,  Princeton University,  Princeton
A mathematician's reputation rests on the number of bad proofs he has given.



Re: [gentoo-user] [OT] One line script for md5sum

2008-12-17 Thread Robert Bridge
On Wed, 17 Dec 2008 15:33:35 -0500
Willie Wong ww...@princeton.edu wrote:

 On Wed, Dec 17, 2008 at 08:48:52AM +, Mick wrote:
  On Sunday 14 December 2008, Neil Bothwick wrote:
   On Sun, 14 Dec 2008 11:47:51 +0200, Alan McKinnon wrote:
That's why I suggested them :-) I use them a lot, especially
when I have to run the same set of commands on 15 different
hosts, then I do something like:
   
for I in $(seq 1 15) ; do
  
   If you're using bash or zsh,you can speed this up with
  
   for I in {1..15}; do
  
  Hmm, I tried this with a sequence of files that look like
  name0001stat.txt to name0198stat.txt, but when I run {0001..0198}
  it fails because it seems to ignore the zeros in 0001 and start
  counting from 1.  Do I need to use some escape character for this?
 
 This is one place bash's brace expansion is sorely lacking compared to
 zsh. In this case you need to use the seq command from coreutils. See
 man seq for more info.
 
 In your particular case, you can do 
 
 for I in $(seq -w 198); do ... 0$I ; done
 
 seq is more flexible in that it allows arbitrary formatting of the
 sequence using printf floating-point format. 

Or use a wildcard based match.

namestat.text works, as would name*stat.text

Both are slightly less specific, but if you have other matches which
the seq excludes, you really should look at your nameing patterns.

RobbieAB


signature.asc
Description: PGP signature


Re: [gentoo-user] [OT] One line script for md5sum

2008-12-17 Thread Neil Bothwick
On Wed, 17 Dec 2008 08:48:52 +, Mick wrote:

 Hmm, I tried this with a sequence of files that look like
 name0001stat.txt to name0198stat.txt, but when I run {0001..0198} it
 fails because it seems to ignore the zeros in 0001 and start counting
 from 1.  Do I need to use some escape character for this?

No,you just need to use a better shell than bash :P


-- 
Neil Bothwick

Bother, said Pooh, as he started up DiskSalv


signature.asc
Description: PGP signature


Re: [gentoo-user] [OT] One line script for md5sum

2008-12-17 Thread Etaoin Shrdlu
On Wednesday 17 December 2008, 23:01, Neil Bothwick wrote:

 On Wed, 17 Dec 2008 08:48:52 +, Mick wrote:
  Hmm, I tried this with a sequence of files that look like
  name0001stat.txt to name0198stat.txt, but when I run {0001..0198} it
  fails because it seems to ignore the zeros in 0001 and start
  counting from 1.  Do I need to use some escape character for this?

 No,you just need to use a better shell than bash :P

Or just use one of:

seq -f '%04g' 1 198

printf '%04d\n' {1..198}

namestat.txt (although this might match more files than wanted)



Re: [gentoo-user] [OT] One line script for md5sum

2008-12-17 Thread Alan McKinnon
On Wednesday 17 December 2008 22:42:34 Robert Bridge wrote:
 On Wed, 17 Dec 2008 15:33:35 -0500

 Willie Wong ww...@princeton.edu wrote:
  On Wed, Dec 17, 2008 at 08:48:52AM +, Mick wrote:
   On Sunday 14 December 2008, Neil Bothwick wrote:
On Sun, 14 Dec 2008 11:47:51 +0200, Alan McKinnon wrote:
 That's why I suggested them :-) I use them a lot, especially
 when I have to run the same set of commands on 15 different
 hosts, then I do something like:

 for I in $(seq 1 15) ; do
   
If you're using bash or zsh,you can speed this up with
   
for I in {1..15}; do
  
   Hmm, I tried this with a sequence of files that look like
   name0001stat.txt to name0198stat.txt, but when I run {0001..0198}
   it fails because it seems to ignore the zeros in 0001 and start
   counting from 1.  Do I need to use some escape character for this?
 
  This is one place bash's brace expansion is sorely lacking compared to
  zsh. In this case you need to use the seq command from coreutils. See
  man seq for more info.
 
  In your particular case, you can do
 
  for I in $(seq -w 198); do ... 0$I ; done
 
  seq is more flexible in that it allows arbitrary formatting of the
  sequence using printf floating-point format.

 Or use a wildcard based match.

 namestat.text works, as would name*stat.text

pedantic
name0[01][0-9]{2}stat.text
/pedantic

would be better still

-- 
alan dot mckinnon at gmail dot com



Re: [gentoo-user] [OT] One line script for md5sum

2008-12-17 Thread Robert Bridge
On Thu, 18 Dec 2008 00:17:18 +0200
Alan McKinnon alan.mckin...@gmail.com wrote:

 On Wednesday 17 December 2008 22:42:34 Robert Bridge wrote:

  Or use a wildcard based match.
 
  namestat.text works, as would name*stat.text
 
 pedantic
 name0[01][0-9]{2}stat.text
 /pedantic
 
 would be better still
 

nitpick
more typing...
/nitpick

Depends on the measure, most times I have seen this kind of thing, the
shorter pattern I had would have been good enough. YMMV though, and I
won't try to argue that yours is more precise.

RobbieAB


signature.asc
Description: PGP signature


Re: [gentoo-user] [OT] One line script for md5sum

2008-12-17 Thread Alan McKinnon
On Thursday 18 December 2008 00:31:56 Robert Bridge wrote:
 On Thu, 18 Dec 2008 00:17:18 +0200

 Alan McKinnon alan.mckin...@gmail.com wrote:
  On Wednesday 17 December 2008 22:42:34 Robert Bridge wrote:
   Or use a wildcard based match.
  
   namestat.text works, as would name*stat.text
 
  pedantic
  name0[01][0-9]{2}stat.text
  /pedantic
 
  would be better still

 nitpick
 more typing...
 /nitpick

 Depends on the measure, most times I have seen this kind of thing, the
 shorter pattern I had would have been good enough. YMMV though, and I
 won't try to argue that yours is more precise.

Agreed :-)

A pattern like that in real life is likely to be something structured and 
*highly* unlikely to have odd file names thrown in.

But like all good sysadmin, I can't resist an opportunity to show off a little 
bit :-)



-- 
alan dot mckinnon at gmail dot com



Re: [gentoo-user] [OT] One line script for md5sum

2008-12-14 Thread Neil Bothwick
On Sat, 13 Dec 2008 19:59:44 -0500, Willie Wong wrote:

 Why not just a simple bash one-liner
 
 for i in token{a..z}; do md5sum -c $i; done

What wrong with

md5sum -c token{a..z}


-- 
Neil Bothwick

All Scottish food is based on a dare.


signature.asc
Description: PGP signature


Re: [gentoo-user] [OT] One line script for md5sum

2008-12-14 Thread Mick
On Sunday 14 December 2008, Neil Bothwick wrote:
 On Sat, 13 Dec 2008 19:59:44 -0500, Willie Wong wrote:
  Why not just a simple bash one-liner
 
  for i in token{a..z}; do md5sum -c $i; done

 What wrong with

 md5sum -c token{a..z}

Thank you all for your suggestions.  I think think that:

 md5sum -c token{a..z}.md5sum  and

 md5sum -c token*.md5sum are the easiest on this occasion, although Alan's 
last two commands are indeed insanely useful!  ha!  They will be saving me 
hours of typing in the future.  :)
-- 
Regards,
Mick


signature.asc
Description: This is a digitally signed message part.


Re: [gentoo-user] [OT] One line script for md5sum

2008-12-14 Thread Neil Bothwick
On Sun, 14 Dec 2008 11:47:51 +0200, Alan McKinnon wrote:

 That's why I suggested them :-) I use them a lot, especially when I
 have to run the same set of commands on 15 different hosts, then I do
 something like:
 
 for I in $(seq 1 15) ; do

If you're using bash or zsh,you can speed this up with

for I in {1..15}; do


-- 
Neil Bothwick

Rugged: Too heavy to lift.


signature.asc
Description: PGP signature


Re: [gentoo-user] [OT] One line script for md5sum

2008-12-14 Thread Alex Schuster
Neil Bothwick writes:

 On Sun, 14 Dec 2008 11:47:51 +0200, Alan McKinnon wrote:
  for I in $(seq 1 15) ; do

 If you're using bash or zsh,you can speed this up with

 for I in {1..15}; do

You can even use C style: for (( i=1; i = 15; i++ )); do

Wonko



[gentoo-user] [OT] One line script for md5sum

2008-12-13 Thread Mick
Hi All,

Is there a clever way to enter a string (rather than write a script file) so 
that md5sum will check a whole series of files in one go and report success 
or error;  I was thinking along the lines of if $value is ... then 
md5sum -c ..., but my non-existent scripting knowledge won't take me any 
further.  I want it to check a series of files named tokena, tokenb, 
tokenc, ... , etc.
-- 
Regards,
Mick


signature.asc
Description: This is a digitally signed message part.


Re: [gentoo-user] [OT] One line script for md5sum

2008-12-13 Thread Alan McKinnon
On Sunday 14 December 2008 01:49:50 Mick wrote:
 Hi All,

 Is there a clever way to enter a string (rather than write a script file)
 so that md5sum will check a whole series of files in one go and report
 success or error;  I was thinking along the lines of if $value is ... then
 md5sum -c ..., but my non-existent scripting knowledge won't take me any
 further.  I want it to check a series of files named tokena, tokenb,
 tokenc, ... , etc.

You are not being very clear about what you want. When you say check, what 
does that mean? Do you want to test if the files are OK? Then you would 
already have the md5sums so you should use md5sum -c

To generate the sums, just run md5sum filename

In any event, I think you need a fancy for loop. To run the same command on 
every file in a directory:

for I in * ; do your command here ; done

for a list of named files:

for I in file1, file2 ; do command ; done

for a list of files with a clear name structure:

for I in a b c d ; do command token${I} ; done 
or
for I in $(seq 1 10) ; do command token${I} ;  done

The last two are insanely useful. Replace command with whatever you need to 
be run over and over

-- 
alan dot mckinnon at gmail dot com



Re: [gentoo-user] [OT] One line script for md5sum

2008-12-13 Thread Willie Wong
On Sat, Dec 13, 2008 at 11:49:50PM +, Penguin Lover Mick squawked:
 Is there a clever way to enter a string (rather than write a script file) so 
 that md5sum will check a whole series of files in one go and report success 
 or error;  I was thinking along the lines of if $value is ... then 
 md5sum -c ..., but my non-existent scripting knowledge won't take me any 
 further.  I want it to check a series of files named tokena, tokenb, 
 tokenc, ... , etc.
 -- 

Why not just a simple bash one-liner

for i in token{a..z}; do md5sum -c $i; done

AFAIK the md5sum will report success or failure for each of the
checksum lines in tokena, tokenb, etc. 

If this doesn't suit your needs, can you describe in more detail your
desired behaviour?

W

-- 
(04:01:59) W: yep
(04:02:02) W: I love linux
(04:02:15) NJYWT: I love penguins
Sortir en Pantoufles: up 736 days, 23:38



Re: [gentoo-user] [OT] One line script for md5sum

2008-12-13 Thread Robert Bridge
On Sat, 13 Dec 2008 23:49:50 +
Mick michaelkintz...@gmail.com wrote:

 Hi All,
 
 Is there a clever way to enter a string (rather than write a script
 file) so that md5sum will check a whole series of files in one go and
 report success or error;  I was thinking along the lines of if $value
 is ... then md5sum -c ..., but my non-existent scripting knowledge
 won't take me any further.  I want it to check a series of files
 named tokena, tokenb, tokenc, ... , etc.

purely in the spirit of coming up with the simplest one...

md5sum -c token*

RobbieAB


signature.asc
Description: PGP signature


Re: [gentoo-user] [OT] One line script for md5sum

2008-12-13 Thread smallnow
token* is the best. I also have this useful script in my bashrc.

its just an extended version of this.
[[ $(md5sum  file1) == $(md5sum  file2) ]]

so you can just give it two files as its argument and it returns 0 if they are
the same. -v for verbose

md5() {
local v x y;
[[ $1 == -v ]]  [[ $# == 3 ]]  { v=true; shift; }
if [[ $# != 2 ]]; then
[[ $v ]]  echo Error: need 2 arguments.
return 2
fi
if [[ $v ]]; then
x=$(md5sum  $1 ) || return 2
y=$(md5sum  $2 ) || return 2
else
{ x=$(md5sum  $1 ) ;}  /dev/null || return 2
{ y=$(md5sum  $2 ) ;}  /dev/null || return 2
fi
if [[  $x == $y ]]; then
[[ $v ]]  echo Same.
return 0
else
[[ $v ]]  echo Different.
return 1
fi
}

- Ian