0

What message should be displayed on ubuntu command line to show that a successful upgrade has been completed (via command)?

1
  • Is no errors not enough? Mar 7, 2014 at 11:08

3 Answers 3

1

CLI programs normally use exit codes to specify if the command exited with success or something happened in the middle, apt-get is no exception.

That means that instead of

sudo apt-get install foo

(being foo some package that you want to upgrade manually of even install) you can use

apt-get install foo && echo "Great success!" || echo "OMG do something! Dooooooooomed!"

If the first command fails somewhere with an error, the first one will be executed, else the second one.

Of course you can replace the commands I used in the example with something more practical, such as, eg: mail someone or send a warning to everyone logged in to the computer. Get creative.

0
1

Try the below command to check whether the previous command succeeded or not,

echo $?

If the output of the above command displays 0, means your previous command was succeeded.If it displays any number other than 0, your previous command was not succeeded.

[ $(echo $?) == 0 ] && echo "Your previous command was succeeded" || echo "Your previous command was not succeeded"

OR

((! $?)) && echo "Your previous command was succeeded" || echo "Your previous command was not succeeded"
2
  • [ $(echo $?) == 0 ] could be also written as ((! $?)).
    – devnull
    Mar 7, 2014 at 12:46
  • Moreover, you probably want either = or bash conditional command [[ if you want to use ==.
    – devnull
    Mar 7, 2014 at 12:49
0

After running

apt-get upgrade

run this:

if [ $? -eq 0 ]; then
    echo OK
else
    echo FAIL
fi

The exit status is stored in “$?” internal variable.

the exit status value varies from 0 to 255.

0 Successful execution of command

0 > command fails because of an error during expansion or redirection, the exit status is greater than zero.

2 Incorrect command usage

126 Command found but not executable

127 Command not found

1
  • 1
    When i answer your answer was just echo $?. I provide another syntax and some explanation. It's better to teach how to fish to just give a fish
    – Maythux
    Mar 7, 2014 at 12:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .