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 Both sides next revision
process_check_script_for_cron [2011/11/11 16:37]
k2patel
process_check_script_for_cron [2012/04/06 15:09]
k2patel
Line 32: Line 32:
 echo “Process Running - do nothing” echo “Process Running - do nothing”
 fi fi
 +</​code>​
 +
 +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)