Page 1 of 1

Conditional bash script to check command already running

Posted: Thu Apr 01, 2021 5:10 pm
by mail2rst
I want to run nextcloud preview generator command through linux cron command. I need two bash files for two situations
1# My_hourly bash file run every hour to generate new added files thumbnail But check before this process running or not. If already running then exit if not then run command
2#My weekly bash file run weekly & reboot the system but check “preview:pre-generate" Process is running or not. If running then exit if not running then reboot command to system
3#My network bash file check network (router=192.168.1.254) online. if network fail then reboot.
My_hourly bash file:-
`
#!/bin/sh
if ! pgrep -x "preview:pre-generate" > /dev/null
then
“sudo -u www-data php /var/www/nextcloud/occ preview:pre-generate"
fi

My_weekly bash file:-

#!/bin/sh
if ! pgrep -x "preview:pre-generate" > /dev/null
then
/sbin/shutdown -r now
fi

My_network bash file
#!/bin/bash
ping -c4 192.168.1.254 > /dev/null

if [ $? != 0 ]
then
sudo /sbin/shutdown -r now
fi





`
is these bash file format & logic is correct or need to edit. Thanks in advance