I have amule-daemon installed on Debian 11 WSL. Process amuleweb crashes every now and then so I need to restart it.
I'm trying to automate this with the following bash script:
#!/bin/bash
if [[ $(pgrep amuleweb) ]]; then
echo "amuleweb is running..";
else
echo "amuleweb is not running, restarting now..";
amuleweb --amule-config-file=/home/debian/.aMule/amule.conf
fi
but no matter if amuleweb is running or not (I'm checking with "ps aux | grep amule"), the script always returns "amuleweb is running.."
This is an example with amuleweb stopped.
debian@CUSPIDE:~$ ./amuleweb.sh
amuleweb is running..
debian@CUSPIDE:~$ [[ $(pgrep amuleweb) ]]
debian@CUSPIDE:~$ echo $?
1
If I run the pgrep command directly from a terminal, it works, but within my script it always returns "0".
How do I fix it? Thanks
if pgrep -a amuleweb
instead. After debugging, you can change it toif pgrep amuleweb > /dev/null
if you want. Probably you need-x
.