Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-19 Thread Bob Proulx
Adam Funk wrote:
 On Tuesday 18 May 2004 10:40, Bob Proulx wrote:
 
  I would backup /var/backups.  That directory includes a copy of the
 
 I already back up /etc.  Where do the /var/backups/dpkg.status.* files
 come from?

The come from:

  /var/lib/dpkg/status

  dpkg status file and a few other tidbits from the system.  From that
  you can recreate your system.  I use my own script to parse the data.
  I can post that if there is interest.
 
 Yes, I'm interested.

It is a simple little ruby script from before I learned about
dpkg-ruby or any of the other parsing routines.  The copyright
statement is bigger than the entire code.  It is really a trivial
little script.  But in any case it should give you a hint of what is
possible.

Bob

#!/usr/bin/env ruby
#
# Process a Debian status file and print out installed package names.
#
# Examples:
#   dpkg.status.print-installed /var/lib/dpkg/status
#   dpkg.status.print-installed /var/backups/dpkg.status.0
#   zcat /var/backups/dpkg.status.1.gz | dpkg.status.print-installed
#   dpkg.status.print-installed (zcat /var/backups/dpkg.status.1.gz)
#
# The one-liner which is way too long but very useful.
#
# diff (dpkg.status.print-installed /var/lib/dpkg/status | sort) \
#   (dpkg.status.print-installed (zcat /var/backups/dpkg.status.1.gz) | sort)
#

#
# Copyright (C) 2003 Bob Proulx [EMAIL PROTECTED]
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#


# Lines look like this:
#   Package: telnet
#   Status: install ok installed
#   Package: wdiff
#   Status: purge ok not-installed

packagename = 

ARGF.each do |line|  # Walk each line of all input files.

  line.chomp!  # Remove the newline from the end of the line.

  if line =~ /^Package: +/
# Keep track of the current package name.
packagename = line.sub(/^Package: +/,'')
  end

  if line =~ /^Status: /

# Remove the header.  Split the line into the three fields.
desired, status, state = line.sub(/^Status: +/,'').split

if status == ok  state == installed
  # If the pkg was okay and installed then print the package name.
  puts packagename
end

  end

end


pgpp3ncSvlU03.pgp
Description: PGP signature


Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Adam Funk
(Sorry about the long lines but they illustrate the output I'm
 talking about.)

``dpkg -l'' on its own in a terminal produces wide output, e.g.:

$ dpkg -l perl*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ NameVersion Description
+++-===-===-==
ii  perl5.8.3-3 Larry 
Wall's Practical Extraction and Report Language.


but when I send its output to a pipe or a file, I get narrow 
output:

$ dpkg -l perl* |head
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name   VersionDescription
+++-==-==-
ii  perl   5.8.3-3Larry Wall's Practical Extraction and Report


I want to dump a complete list of installed packages to a file as 
part of my backup procedure.  man dpkg-query suggests using 
--showformat=format, in particular: Package information can be 
included by inserting variable references to package fields using 
the ${var[;width]} syntax.  But it doesn't say what the variable
names are.  Suggestions?

Thanks,
Adam


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Thomas Adam
 --- Adam Funk [EMAIL PROTECTED] wrote: 

 (Sorry about the long lines but they illustrate the output I'm
  talking about.)
 
 ``dpkg -l'' on its own in a terminal produces wide output, e.g.:

COLUMNS=200 dpkg -l | pipe | pipe | pipe | more | more | yay

Change the value of 200, if it is too small.

-- Thomas Adam

=
The Linux Weekend Mechanic -- http://linuxgazette.net
TAG Editor -- http://linuxgazette.net

shrug We'll just save up your sins, Thomas, and punish 
you for all of them at once when you get better. The 
experience will probably kill you. :)

 -- Benjamin A. Okopnik (Linux Gazette Technical Editor)





Chat instantly with your online friends?  Get the
FREE Yahoo! Messenger http://uk.messenger.yahoo.com/


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Bob Proulx
Adam Funk wrote:
 ``dpkg -l'' on its own in a terminal produces wide output, e.g.:
 [...]
 but when I send its output to a pipe or a file, I get narrow 
 output:

I thought dpkg -l used COLUMNS or the current tty columns to base its
output.  Which makes me think you have set 'COLUMNS=200 dpkg -l', which
is something I do.

 I want to dump a complete list of installed packages to a file as 
 part of my backup procedure.  man dpkg-query suggests using 
 --showformat=format, in particular: Package information can be 
 included by inserting variable references to package fields using 
 the ${var[;width]} syntax.  But it doesn't say what the variable
 names are.  Suggestions?

I would backup /var/backups.  That directory includes a copy of the
dpkg status file and a few other tidbits from the system.  From that
you can recreate your system.  I use my own script to parse the data.
I can post that if there is interest.  It is simple.  I would also
save /var/cache/debconf but it is not as critical.

Bob


pgpLe8umDZUSG.pgp
Description: PGP signature


Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Mal Beaton
Adam Funk wrote:
(Sorry about the long lines but they illustrate the output I'm
 talking about.)
``dpkg -l'' on its own in a terminal produces wide output, e.g.:
$ dpkg -l perl*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ NameVersion Description
+++-===-===-==
ii  perl5.8.3-3 Larry 
Wall's Practical Extraction and Report Language.

but when I send its output to a pipe or a file, I get narrow 
output:

$ dpkg -l perl* |head
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name   VersionDescription
+++-==-==-
ii  perl   5.8.3-3Larry Wall's Practical Extraction and Report

I want to dump a complete list of installed packages to a file as 
part of my backup procedure.  man dpkg-query suggests using 
--showformat=format, in particular: Package information can be 
included by inserting variable references to package fields using 
the ${var[;width]} syntax.  But it doesn't say what the variable
names are.  Suggestions?

Thanks,
Adam

How about dpkg --get-selections
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Adam Funk
On Tuesday 18 May 2004 10:20, Thomas Adam wrote:

  --- Adam Funk [EMAIL PROTECTED] wrote:
 
 (Sorry about the long lines but they illustrate the output I'm
  talking about.)
 
 ``dpkg -l'' on its own in a terminal produces wide output, e.g.:
 
 COLUMNS=200 dpkg -l | pipe | pipe | pipe | more | more | yay
 
 Change the value of 200, if it is too small.

Excellent.  I had tried these:

(COLUMNS=200 ; dpkg -l) |head
(COLUMNS=200  dpkg -l) |head

but got the narrow output.  Why do these two fail?


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Adam Funk
On Tuesday 18 May 2004 10:40, Bob Proulx wrote:

 I would backup /var/backups.  That directory includes a copy of the

I already back up /etc.  Where do the /var/backups/dpkg.status.* files
come from?

 dpkg status file and a few other tidbits from the system.  From that
 you can recreate your system.  I use my own script to parse the data.
 I can post that if there is interest.

Yes, I'm interested.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Thomas Adam
 --- Adam Funk [EMAIL PROTECTED] wrote: 

 On Tuesday 18 May 2004 10:20, Thomas Adam wrote:
 
   --- Adam Funk [EMAIL PROTECTED] wrote:
  
  (Sorry about the long lines but they illustrate the output I'm
   talking about.)
  
  ``dpkg -l'' on its own in a terminal produces wide output, e.g.:
  
  COLUMNS=200 dpkg -l | pipe | pipe | pipe | more | more | yay
  
  Change the value of 200, if it is too small.
 
 Excellent.  I had tried these:
 
 (COLUMNS=200 ; dpkg -l) |head
 (COLUMNS=200  dpkg -l) |head
 
 but got the narrow output.  Why do these two fail?

Because COLUMNS=200 is being set in a subshell. Thus, the resultant output
when it is piped through to head is lost, since bash does not work in this
way. Either you need to use process substitution or NOT run it in a
subshell, as per my example in a previous e-mail.

-- Thomas Adam

=
The Linux Weekend Mechanic -- http://linuxgazette.net
TAG Editor -- http://linuxgazette.net

shrug We'll just save up your sins, Thomas, and punish 
you for all of them at once when you get better. The 
experience will probably kill you. :)

 -- Benjamin A. Okopnik (Linux Gazette Technical Editor)





Chat instantly with your online friends?  Get the
FREE Yahoo! Messenger http://uk.messenger.yahoo.com/


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Colin Watson
On Tue, May 18, 2004 at 11:40:53AM +, Adam Funk wrote:
 On Tuesday 18 May 2004 10:20, Thomas Adam wrote:
   --- Adam Funk [EMAIL PROTECTED] wrote:
  (Sorry about the long lines but they illustrate the output I'm
   talking about.)
  
  ``dpkg -l'' on its own in a terminal produces wide output, e.g.:
  
  COLUMNS=200 dpkg -l | pipe | pipe | pipe | more | more | yay
  
  Change the value of 200, if it is too small.
 
 Excellent.  I had tried these:
 
 (COLUMNS=200 ; dpkg -l) |head
 (COLUMNS=200  dpkg -l) |head
 
 but got the narrow output.  Why do these two fail?

Those both set the COLUMNS shell variable but fail to export it to the
dpkg subprocess (you need an explicit 'export' to do that). 'COLUMNS=200
dpkg -l' is a special syntax that adds the variable to the environment
of the dpkg subprocess without affecting the shell in which it is
executed.

-- 
Colin Watson  [EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Colin Watson
On Tue, May 18, 2004 at 01:18:50PM +0100, Thomas Adam wrote:
  --- Adam Funk [EMAIL PROTECTED] wrote: 
  Excellent.  I had tried these:
  
  (COLUMNS=200 ; dpkg -l) |head
  (COLUMNS=200  dpkg -l) |head
  
  but got the narrow output.  Why do these two fail?
 
 Because COLUMNS=200 is being set in a subshell. Thus, the resultant output
 when it is piped through to head is lost, since bash does not work in this
 way.

No; it doesn't matter whether head can see COLUMNS or not, and the
output is not lost. You can tell this because both of these work fine:

  (export COLUMNS=200; dpkg -l) | head
  (COLUMNS=200 dpkg -l) | head

... as well as the more natural:

  COLUMNS=200 dpkg -l | head

Cheers,

-- 
Colin Watson  [EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread George Cristian Birzan
On Tue, May 18, 2004 at 08:34:53AM +, Adam Funk wrote:
 I want to dump a complete list of installed packages to a file as part 
 of my backup procedure.  man dpkg-query suggests using 
 --showformat=format, in particular: Package information can be 
 included by inserting variable references to package fields using the 
 ${var[;width]} syntax.  But it doesn't say what the variable
 names are.  Suggestions?

It can be anything from the /var/lib/dpkg/status file, case insensitive.

-- 
George Cristian Birzan  gcbirzan (at) wolfheart (dot) ro
Welcome thy neighbor into thy fallout shelter. He'll come in handy if
you run out of food.
-- Dean McLaughlin.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread Adam Funk
On Tuesday 18 May 2004 14:50, Colin Watson wrote:

 Those both set the COLUMNS shell variable but fail to export it to the
 dpkg subprocess (you need an explicit 'export' to do that).
 'COLUMNS=200 dpkg -l' is a special syntax that adds the variable to
 the environment of the dpkg subprocess without affecting the shell in
 which it is executed.

I wasn't aware of that special syntax so it had not occurred to me to
try it -- it looked like a run-on of two commands that ought to have
something between them.

Very useful in general -- thanks!

-- Adam


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Getting wide ``dpkg -l'' output in scripts and pipes.

2004-05-18 Thread csj
On 18. May 2004 at 2:03PM GMT,
Adam Funk [EMAIL PROTECTED] wrote:

 On Tuesday 18 May 2004 14:50, Colin Watson wrote:
 
  Those both set the COLUMNS shell variable but fail to export it to the
  dpkg subprocess (you need an explicit 'export' to do that).
  'COLUMNS=200 dpkg -l' is a special syntax that adds the variable to
  the environment of the dpkg subprocess without affecting the shell in
  which it is executed.

This doesn't work in all shells packaged for Debian.  I use use
env (coreutils):

env COLUMNS=200 dpkg -l

 I wasn't aware of that special syntax so it had not occurred to me to
 try it -- it looked like a run-on of two commands that ought to have
 something between them.

[...]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]