pgrep-based script only doesn't work for PVE

JustaGuy

Renowned Member
Jan 1, 2010
324
2
83
Hi,

I use a series of scripts to generate system tray icons to indicate when otherwise invisible background tasks are running, such as Timeshift, so that I don't reboot & corrupt something. I've been using the same bunch of scripts for everything with success for years now, but since installing PVE onto my Debian, I'm unable to get them to work for VMs. This is the only time I've ever had a problem, & I haven't found a solution on my own so I'm here for help.

Below I will explain how the process I use works, & where it's failing, so hopefully someone will see where I'm going wrong.

Austerity & Pericles are the VMs pgrep is looking for. I've also tried making pgrep look for kvm, but it didn't make a difference.

This is the icon the below scripts manage:
Code:
#!/usr/bin/python
import os
from gi.repository import Gtk as gtk, AppIndicator3 as appindicator


def main():
  indicator = appindicator.Indicator.new("PVE", "/home/cdb/Applications/Icons/Proxmox.png", appindicator.IndicatorCategory.APPLICATION_STATUS)
  indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
  indicator.set_menu(menu())
  gtk.main()


def menu():
  menu = gtk.Menu()


#  command_one = gtk.MenuItem('Open Main Window')
#  command_one.connect('activate', open)
#  menu.append(command_one)


#  exittray = gtk.MenuItem('Exit Tray')
#  exittray.connect('activate', quit)
#  menu.append(exittray)


  menu.show_all()
  return menu


def open(_):
  os.system("sudo timeshift-gtk")


def quit(_):
  gtk.main_quit()


if __name__ == "__main__":
  main()


I start 2 watch processes in screen to see when the VM process starts & stops:
Code:
screen -d -m watch -n8 -x sh /home/cdb/Documents/Scripts/PVE_Tray_Icon-Poll_Process.sh
screen -d -m watch -n15 sh /home/cdb/Documents/Scripts/PVE_Tray_Icon-Poll_Not-Process.sh

These 2 processes consist of scripts looking for when processes start & when they disappear:
Code:
#!/bin/bash
export DISPLAY=:0.0
export XAUTHORITY="/home/cdb/.Xauthority"
export XDG_RUNTIME_DIR=/run/user/1000
if pgrep -f 'Austerity|Pericles' >/dev/null 2>&1
  then
     python /home/cdb/Documents/Scripts/PVE
  else
     kill $(pgrep -f 'python /home/cdb/Documents/Scripts/PVE')
fi

Code:
#!/bin/bash
if [ pgrep -f 'Austerity|Pericles' ] ; then
:
else
kill $(pgrep -f 'python /home/cdb/Documents/Scripts/PVE')
fi

It's the last script that fails, the one that is supposed to kill the python script displaying the icon in the system tray when the VM stops running.
If I run the kill line in a terminal manually it runs fine. It doesn't matter if I include the XOrg export stuff in the kill script's beginning like it is in the one that starts the icon. It also doesn't make any difference whether I use those [ ] brackets around pgrep & the machine names, nor does it matter if I use the ; then on the same line, that can omit the ; & have the then on the next line above the no-op : . I've also changed the indents in this case that I pasted here because I was desperately trying anything to get it to work, of course that made no difference either.

Thanks in advance.
-J
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!