User Tools

Site Tools


process_check_script_for_cron

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
process_check_script_for_cron [2011/11/11 16:37]
k2patel
process_check_script_for_cron [2012/04/06 15:10]
k2patel
Line 3: Line 3:
 This script will check process if it is not running ​ This script will check process if it is not running ​
 and will start the process if not running. and will start the process if not running.
 +
 +==== First ====
  
 <code bash | proc_script.sh>​ <code bash | proc_script.sh>​
Line 17: Line 19:
 fi fi
 </​code>​ </​code>​
 +
 +==== Second ====
  
 I made some changes as there is actually no need to equality check: I made some changes as there is actually no need to equality check:
 +
  
 <code bash | proc_scriptjt.sh>​ <code bash | proc_scriptjt.sh>​
Line 32: Line 37:
 echo “Process Running - do nothing” echo “Process Running - do nothing”
 fi fi
 +</​code>​
 +
 +==== Third ====
 +
 +
 +This is in python :)
 +
 +<code python>
 +#!/bin/env python
 +# -*- coding: utf-8 -*-
 +"""​
 +Created on Wed Apr  4 14:46:52 2012
 +
 +@author: k2patel@hotmail.com
 +"""​
 +
 +import subprocess
 +import psutil
 +
 +#​procfs.utilist()
 +running = 0
 +#psutil.
 +
 +for proc in psutil.get_process_list():​
 +    if proc.username == '​kpatel':​
 +        ## Actual Command
 +        ## ssh -f -N -i /​home/​kpatel/​.ssh/​id_rsa -R 2200:​localhost:​22 k2patel@71.245.248.138
 +        ## Actual CMDLINE output
 +        ## ssh-f-N-i/​home/​kpatel/​.ssh/​id_rsa-R2200:​localhost:​22k2patel@71.245.248.138
 +        if proc.cmdline == (['​ssh',​ '​-f',​ '​-N',​ '​-i',​ '/​home/​kpatel/​.ssh/​id_rsa',​ '​-R',​ '​2200:​localhost:​22',​ '​k2patel@71.245.248.138'​]):​
 +            running = 1
 +            ​
 +            ​
 +if running is 1:
 +    print "​Process is running"​
 +else:
 +    subprocess.call(['​ssh',​ '​-f',​ '​-N',​ '​-i',​ '/​home/​kpatel/​.ssh/​id_rsa',​ '​-R',​ '​2200:​localhost:​22',​ '​k2patel@71.245.248.138'​])
 +    ​
 </​code>​ </​code>​
process_check_script_for_cron.txt · Last modified: 2020/08/10 02:35 (external edit)