Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- get_cmd(){
- ps --no-headers -p $(pidof "$1") -o cmd
- }
- get_pid(){
- if [[ $(pidof "$1") =~ ^[0-9]+$ ]]; then
- return 0
- else
- return 1
- fi
- }
- # Read initial data from user.
- until [[ $sec =~ ^[0-9]+$ ]]; do
- read -p "check period (sec): " sec
- done
- until ( get_pid "$name" ); do
- read -p "process name: " name
- done
- # Get cmdline by process name.
- cmd=$(get_cmd "$name")
- [ -z "$cmd" ] && echo "ERROR: cmdline by programm name $name is not found!"
- while true ; do
- # ( get_pid "$name" ) || $cmd
- if ( get_pid "$name" ); then
- echo "Waiting, sleep for $sec sec..."
- else
- echo 'Run cmd...'
- $cmd
- fi
- sleep $sec
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement