LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-15-2011, 05:35 AM   #16
k3lt01
Senior Member
 
Registered: Feb 2011
Location: Australia
Distribution: Debian Wheezy, Jessie, Sid/Experimental, playing with LFS.
Posts: 2,899

Original Poster
Rep: Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623

I put it in the terminal and it said no output matching. Should have tested that better than I did. Stupid thing is the script works through that ok for some reason. I'll take it out and see what happens.
 
Old 11-15-2011, 05:39 AM   #17
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
It will always work because you have said when this command fails, which it will every time, to then run what is inside the if statement.

Also, your system must be quite different to mine, here is what I get:
Code:
$ dpkg-query -l debdelta = i
dpkg-query: error: package name in specifier '=' is illegal: must start with an alphanumeric character
Which is nothing along the lines of 'no output matching'??
 
1 members found this post helpful.
Old 11-15-2011, 05:59 AM   #18
k3lt01
Senior Member
 
Registered: Feb 2011
Location: Australia
Distribution: Debian Wheezy, Jessie, Sid/Experimental, playing with LFS.
Posts: 2,899

Original Poster
Rep: Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623
Sorry if I'm slow in replying there's a huge storm outside and it is knocking my net access about a bit.

Here is the exact out from that query
Code:
root@michael-laptop:/home/michael# dpkg-query -l debdelta = i
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
un  debdelta       <none>         (no description available)
No packages found matching =.
No packages found matching i.
root@michael-laptop:/home/michael#
The man oage says
Quote:
COMMANDS
-l, --list [package-name-pattern...]
List packages matching given pattern. If no package-name-pattern
is given, list all packages in /var/lib/dpkg/status, excluding
the ones marked as not-installed (i.e. those which have been
previously purged). Normal shell wildchars are allowed in pack-
age-name-pattern. Please note you will probably have to quote
package-name-pattern to prevent the shell from performing file-
name expansion. For example this will list all package names
starting with “libc6”:

dpkg-query -l 'libc6*'

The first three columns of the output show the desired action,
the package status, and errors, in that order.

Desired action:
u = Unknown
i = Install
h = Hold
r = Remove
p = Purge

Package status:
n = Not-installed
c = Config-files
H = Half-installed
U = Unpacked
F = Half-configured
W = Triggers-awaiting
t = Triggers-pending
i = Installed
and that is where I got it from. I assumed if the response come back as i it would tell the script it was installed.

EDIT: This is the query without the -i
Code:
root@michael-laptop:/home/michael# dpkg-query -l debdelta
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
un  debdelta       <none>         (no description available)
root@michael-laptop:/home/michael#
Problem is I know from synaptic that it is installed and I've used it today already

Last edited by k3lt01; 11-15-2011 at 06:02 AM.
 
Old 11-15-2011, 06:09 AM   #19
trappa01
LQ Newbie
 
Registered: Dec 2009
Posts: 20

Rep: Reputation: 8
grail is right. You don't need the "= i" in the statement at all.

if ! dpkg-query -l debdelta > /dev/null 2>&1 will give you a true/false return code (0 or 1). If the return code is 1 (false) then the script will go into the "then" block (this is because of the ! after the if).

What is probably happening in your script is that you are getting an error due to the "= i" and therefore a return code of non-zero. This will always execute the "then" block.

As for your question about seeing the output, you can execute your script using "script > log.txt"
 
1 members found this post helpful.
Old 11-15-2011, 06:13 AM   #20
trappa01
LQ Newbie
 
Registered: Dec 2009
Posts: 20

Rep: Reputation: 8
Try using -s instead of -l
 
1 members found this post helpful.
Old 11-15-2011, 06:39 AM   #21
k3lt01
Senior Member
 
Registered: Feb 2011
Location: Australia
Distribution: Debian Wheezy, Jessie, Sid/Experimental, playing with LFS.
Posts: 2,899

Original Poster
Rep: Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623
I understand the mistake I made.

Quote:
Originally Posted by trappa01 View Post
As for your question about seeing the output, you can execute your script using "script > log.txt"
Gotta love computers, all the output is going to the txt file except for this snippet
Code:
root@michael-laptop:/home/michael/Desktop# ./update_upgrade > log.txt
y
Reading changelogs...
Extracting templates from packages: 100%
./update_upgrade: line 52: syntax error near unexpected token `fi'
./update_upgrade: line 52: `fi'
root@michael-laptop:/home/michael/Desktop#
Anyway the process all worked as it should just then, apart from not being able to see what was happening on the terminal. I don't know if that is normal behaviour but if it is how can I change it to post everything on the terminal so I can see what is happening and also keep a log for later reference so I can see how much download debdelta is saving.
 
Old 11-15-2011, 06:42 AM   #22
k3lt01
Senior Member
 
Registered: Feb 2011
Location: Australia
Distribution: Debian Wheezy, Jessie, Sid/Experimental, playing with LFS.
Posts: 2,899

Original Poster
Rep: Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623
Quote:
Originally Posted by trappa01 View Post
Try using -s instead of -l
I'll do that tomorrow it's nearly 11pm here now, good thing I don't have to go to work this week lol.

Thank you all again, I appreciate your assistance.
 
Old 11-15-2011, 07:40 AM   #23
trappa01
LQ Newbie
 
Registered: Dec 2009
Posts: 20

Rep: Reputation: 8
Quote:
Gotta love computers, all the output is going to the txt file except for this snippet
Sorry, I should have been more clear. "./update_upgrade > log.txt" will send the stdout to log.txt but not stderr.
Run with "./update_upgrade > log.txt 2>&1" so that you get both sent to your log file.

As for the error, its probably still a mismatch between the if statements and their corresponding fi's .
 
Old 11-15-2011, 08:47 PM   #24
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,591

Rep: Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244Reputation: 1244
Hi,

ok, I couldn't help myself, here is a version of the script (with very verbose comments). Note that I _did_not_ screw around with the sudo setup since I think doing such a thing is prone to causing errors.

Code:
#!/bin/bash

#
# Check if debdelta is installed
#
dpkg -s debdelta > /dev/null 2>&1
# The return value of the last command is stored in $?
# If the above commands return value is 0, then debdelta is installed
if [ "$?" != "0" ] ; then
    echo "It seems debdelta is not installed."
    read -p "This script needs debdelta. Can I install it? y/n >" 
    if [ "$REPLY" != "y" ] ; then
	echo "Can not run without debdelta. Exiting."
	exit 1
    fi
    # Install debdeta and exit the script if there is an error
    sudo apt-get install debdelta || exit 1
fi
echo "Ok, debdelta is installed."

#
# Check if the user really wants to do the upgrade
# 
read -p "Do you really want to do the upgrade? y/n >"
if [ "$REPLY" != "y" ] ; then
    echo "Ok, not upgrading."
    exit 0
fi

#
# Do it. Only run the next command if the previous command exited cleanly
#
echo "Starting upgrade..."
sudo aptitude update && sudo debdelta-upgrade && sudo aptitude safe-upgrade
Please note, that this script is not tested, and (although it is a
very simple) therefore it may contain undocumented features (AKA bugs).

Cheers,

Evo2.
 
Old 11-15-2011, 09:10 PM   #25
k3lt01
Senior Member
 
Registered: Feb 2011
Location: Australia
Distribution: Debian Wheezy, Jessie, Sid/Experimental, playing with LFS.
Posts: 2,899

Original Poster
Rep: Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623Reputation: 623
Hi Evo, thanks for this I appreciate your input. I'll take the script for a test drive and see how it goes.

The script I wrote has worked but only when I had it output to the log and when very little if anything showed in the terminal. This is something I don't understand but am looking at today. I also believe that logging the process to file would be a good feature so people can see how much download they are saving using debdelta, how would I achieve that with your script? It needs to be a part of the script itself not part of the command to run it.

Thanks again for your help and patience. I have only tried scripting once before (I have a small 1 line script that removes duplicate entries from a host file) a few years ago so it's a huge learning curve for me.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My very own Kernel build script for Debian/Ubuntu-based systems Kenny_Strawn Linux - Kernel 5 12-02-2010 10:57 AM
Shell script to compile a custom Linux kernel on Debian-based systems Kenny_Strawn Linux - Kernel 3 09-25-2010 02:29 PM
Bash script questions. ArthurHuang Programming 6 03-20-2007 11:59 PM
Couple of Shell Script Questions mathias1979 Programming 3 06-16-2005 04:22 PM
Couple Questions about Debian MikeeX Linux - Distributions 5 12-09-2002 09:26 PM


All times are GMT -5. The time now is 03:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration