gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
Write simple bash script to check if process with name exists. If not - run command
- User
Write simple bash script to check if process with name exists. If not - run command
- Assistant
You can create a simple Bash script that checks for a process by name and starts a command if the process is not running. Here’s an example script that demonstrates this functionality:
bash#!/bin/bash # Define the name of the process you want to check PROCESS_NAME="your_process_name" # Define the command to run if the process is not found COMMAND="your_command_to_run" # Check if the process is running if pgrep -x "$PROCESS_NAME" > /dev/null then echo "$PROCESS_NAME is running." else echo "$PROCESS_NAME is not running. Starting it now..." # Run the command $COMMAND & fiUsage Instructions:
- Replace
your_process_namewith the name of the process you want to check for.
- Replace