You are not logged in.
Pages: 1
Hello im trying to make a script that warns me if vmware is still running before i shutdown. but it always goes to else. does anyone know what i did wrong?
#!/bin/bash
if [[ $(pgrep -x 'vmware') ]] ;
then
notify-send "vmware is running!"
else
shutdown
fi
Last edited by philipW (2019-02-14 10:08:30)
Offline
#!/bin/bash
if [[ $(pgrep -c 'vmware') > 0 ]] ;
then
notify-send "vmware is running!"
else
shutdown
fi
Offline
Lupo, if yours would work, the original version would also work. It would seem 'vmware' isn't a proper match for the full name of the process. Check `pgrep -il vmware`.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Lupo, if yours would work, the original version would also work. It would seem 'vmware' isn't a proper match for the full name of the process. Check `pgrep -il vmware`.
You're right. Thanks.
Last edited by Lupo Alberto (2019-02-13 13:14:52)
Offline
In a situation like this I would do
if pgrep -il vmware &>/dev/null; then
notify-send "vmware is running!"
else
shutdown
fi
Also FYI you don't need the semicolon on the 'if' line unless you put the 'then' on the same line like in my example.
Last edited by alphaniner (2019-02-13 14:22:05)
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
I got it working with alphaniner's example. Trilby was also right there where more vmware processes that where running when i was not using the program. like vmware-usbarbit and vmware-hostd. I used pgrep -il "vmware-vmx" so it warns me when a vm is running and not when the program is open. Thanks for the help, guys!
Last edited by philipW (2019-02-14 10:07:40)
Offline
Pages: 1