1

How can i send a message to a log file (not the apt log) after the installation of a package. I simple want to log which package (package name) was installed. ie. "links installed successfully"

  • does /var/log/dpkg.log not have the info you need? – cas Nov 18 '15 at 2:24
  • How is the log kept for dpkg.log? Thats what i have a hard time understanding – et moi Nov 18 '15 at 2:30
  • too long for a comment, i'll have to make it an answer. – cas Nov 18 '15 at 2:35
  • What exactly do you not understand about /var/log/dkpg.log? The format of the file or what? – fpmurphy Nov 18 '15 at 2:43
  • BTW, apt-get doesn't actually install/remove the packages itself. It calls dpkg to do that. so dpkg is able to log every install, upgrade, remove, etc. The same is true for aptitude, synaptic, and other front-ends. – cas Nov 18 '15 at 2:52
0

/var/log/dpkg.log should contain the information you want:

From man dpkg:

--log=filename

Log status change updates and actions to filename, instead of the default /var/log/dpkg.log.

If this option is given multiple times, the last filename is used.

Log messages are of the form:

YYYY-MM-DD HH:MM:SS startup type command for each dpkg invocation where type is archives (with a command of unpack or install) or packages (with a command of configure, triggers-only, remove or purge);

YYYY-MM-DD HH:MM:SS status state pkg installed-version for status change updates;

YYYY-MM-DD HH:MM:SS action pkg installed-version available-version for actions where action is one of install, upgrade, configure, trigproc, disappear, remove or purge;

and YYYY-MM-DD HH:MM:SS conffile filename decision for conffile changes where decision is either install or keep.

e.g. I installed ksh this morning to investigate a difference between mksh and ksh93.

# grep ksh /var/log/dpkg.log
2015-11-18 09:39:52 install ksh:amd64 <none> 93u+20120801-2
2015-11-18 09:39:52 status half-installed ksh:amd64 93u+20120801-2
2015-11-18 09:39:52 status half-installed ksh:amd64 93u+20120801-2
2015-11-18 09:39:52 status unpacked ksh:amd64 93u+20120801-2
2015-11-18 09:39:52 status unpacked ksh:amd64 93u+20120801-2
2015-11-18 09:39:57 configure ksh:amd64 93u+20120801-2 <none>
2015-11-18 09:39:57 status unpacked ksh:amd64 93u+20120801-2
2015-11-18 09:39:57 status unpacked ksh:amd64 93u+20120801-2
2015-11-18 09:39:57 status half-configured ksh:amd64 93u+20120801-2
2015-11-18 09:39:57 status installed ksh:amd64 93u+20120801-2

If you just want to know when packages have been installed or upgraded, try something like this:

# zgrep -E '(install|upgrade) bash[: ]' /var/log/dpkg.log*
/var/log/dpkg.log.12.gz:2014-11-25 12:19:59 upgrade bash:amd64 4.3-11 4.3-11+b1
/var/log/dpkg.log.2.gz:2015-09-12 18:52:44 upgrade bash:amd64 4.3-13 4.3-14
/var/log/dpkg.log.4.gz:2015-07-29 10:27:33 upgrade bash:amd64 4.3-12 4.3-13
/var/log/dpkg.log.9.gz:2015-02-09 11:54:56 upgrade bash:amd64 4.3-11+b1 4.3-12

The trailing [: ] in the regex is to exclude other packages such as bash-builtins, bash-completion, bash-doc etc from the listing.

2

logger can be used for this, like

logger package installed successfully
  • It’s worth noting that this sends a syslog message to a location that’s not necessarily under your control or ability to view, if it is logged at all. – Jeff Schaller Dec 30 '17 at 17:23
0

You can use:

sudo apt-get install somepackage && echo somepackage installed successfully >> mylogfile.log

It's a bit silly, but it answers the exact question you asked. It only puts the message into mylogfile.log if the install succeeded.

(If that doesn't help, add more detail to your question and I will try to help.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.