4

I'd like to run a script (let's say myScript.sh) every time a yum update or yum install command is executed.

So if I run yum update someprogram then myScript.sh should be executed right after that. Is this possible?

Currently I could run a script if I put it in the ".spec" file when I build the rpm to install, but we have a lot of packages and I'd like to have this script run everytime any package gets updated. I thought about maybe using a cron job to run it every hour but that doesn't seem like a good idea.

Mikel
  • 56,387
  • 13
  • 130
  • 149
Katie
  • 1,552
  • 1
  • 12
  • 13
  • This might be relevant: http://yum.baseurl.org/wiki/WritingYumPlugins – Tom Hunt Nov 20 '15 at 00:30
  • See this answer on [Yum post actions](https://unix.stackexchange.com/a/585786/161288). You basically write a small actions file that matches specific packages, general actions, or both, and you point it to your script. – Walf Oct 28 '21 at 02:27

1 Answers1

2

You can create bash function in .bashrc :

myyumfunction() {
    yum update $1
    myScript.sh
}

Bash functions that you define in your .bashrc are available within your shell. You can call your function like this:

$ myyumfunction someprogram
lgeorget
  • 13,656
  • 2
  • 41
  • 63
shcherbak
  • 493
  • 2
  • 10
  • 1
    This covers the manual call to yum but not things like automatique updates or calls to yum via GUIs for example. +1 anyway because it's a simple and good solution. – lgeorget Nov 20 '15 at 17:12
  • Thanks @shcherbak! It would be difficult for me to try to get other people to use my custom function, but this isn't a bad idea! I might end up having to do this. – Katie Nov 21 '15 at 00:52