Wednesday, July 15, 2015

Monitor active time of a process in windows OS

I wrote a simple script that will run on any windows operating system silently, then log if the specified application is running (eg. notepad.exe), if it is not running it will not update the log and the reason is to avoid large generated log file.

<<< logger.bat >>>
@echo off

set processname=notepad.exe                    
set MYPATH=c:\a
set LOGFILE=%processname%_%date:~4,2%%date:~7,2%%date:~10,4%.log
set PATHLOG=%MYPATH%\%LOGFILE%
set _my_datetime=%date%_%time%


echo %_my_datetime%, Searching for %processname%... >> %PATHLOG%
:loop
set _my_datetime=%date%_%time%
for /f "tokens=1 delims=," %%a in ('tasklist /fo csv ^|FINDSTR /I /C:"%processname%"') do call :searchprocess %%a
ping -n 6 127.0.0.1>NUL
goto :loop


:searchprocess   
echo %_my_datetime%, %success% >>  %PATHLOG%&goto :eof

<<< monitor_notepad.vbs >>

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "c:\a\logger.bat" & Chr(34), 0
Set WshShell = Nothing


You just have to create shortcut to startup folder.


Thursday, January 8, 2015

How to install OPENVPN

yum -y install wget wget http://swupdate.openvpn.org/as/openvpn-as-2.0.10-CentOS6.x86_64.rpm rpm -ivh openvpn-as-2.0.10-CentOS6.x86_64.rpm (i = Install, v = verbose, h = hash ) ovpn-init /usr/local/openvpn_as/bin/ovpn-init /usr/local/openvpn_as/bin/ovpn-init --force passwd openvpn passwd it adduser it passwd it GO TO IE https://:943/admin Login as "openvpn" with the same password used to authenticate to this UNIX host. During normal operation, OpenVPN AS can be accessed via these URLs: Admin UI: https://:943/admin Client UI: https://:943/

Monday, January 5, 2015

Morning Check Script

SPmorning_check.sh /opt/scripts (#1011) pwd /opt/scripts /opt/scripts (#1012) cat SPmorning_check.sh #!/bin/bash # #Morning checkout script - Check all processes are running # CONFIG="/opt/scripts/config/SPproc.conf" DISK_CHECK="/opt/scripts/sub/disk_check.sh" ############################################################################################# ############################### FUNCTIONS ################################################## ############################################################################################# #for i in `cat proc.conf | awk -F\| '{print $2}'`; do echo -n "$i "; ping -c2 "$i" &>/dev/null && echo success || echo fail; done foo () { yes '' | head -n2 #Echo several blank line echo "Ping Test Results" for i in `cat $CONFIG | egrep -v "^#|^;"`; do network=`echo $i|awk -F\| '{print $3}'` if [ "$network" = "$1" ] then ip=`echo $i|awk -F\| '{print $2}'` ping -c1 "$ip" &>/dev/null && echo -n "[ OK ] " || echo -n "[ CRITICAL ] " echo $i | awk -F\| '{print "\t \t" $2 "\t" $1}' fi done yes '' | head -n3 #Echo several blank line } ############################################################################################# ############################### FUNCTIONS ################################################## ############################################################################################# echo " ###################################################" echo " WIRELESS NETWORK in GTP Availability" echo " ###################################################" foo 'AP' echo " ###################################################" echo " Internet Service Provider Availability" echo " ###################################################" foo 'ISP' echo " ###################################################" echo " Check Browsing" echo " ###################################################" foo 'WEB' echo " ###################################################" echo " GTP Managed Servers Availability" echo " ###################################################" foo 'MS' echo " ###################################################" echo " Cloud Servers Availability" echo " ###################################################" echo " DIGITAL OCEAN" foo 'DIGITALOCEAN' echo " RACKSPACE" foo 'RACKSPACE' echo " ###################################################" echo " Disk Space Check" echo " ###################################################" $DISK_CHECK ops.stratpoint.com $DISK_CHECK gw1 /opt/scripts/sub (#1025) pwd; cat disk_check.sh /opt/scripts/sub #!/bin/bash HOSTS=$1 LOCAL_HOST=`hostname -s` disk_thresh="80" # Function which displays threshold check results # function threshold { percentage="$1" stringlen="$2" outputval="" while [ $stringlen -lt 20 ] do outputval=$outputval" " let stringlen++ if [ $stringlen -gt 19 ] then if [ $percentage -gt $disk_thresh ] then outputval=$outputval"CRITICAL" else outputval=$outputval"OK" fi fi done echo "$outputval" } for host in $HOSTS; do hostname=$host if [ "$hostname" == "$LOCAL_HOST" ] then sshreq=`hostname | cut -f1,2,3 -d.; df -h` else sshreq=`ssh -24aqx -o 'BatchMode yes' $hostname "hostname | cut -f1,2,3 -d.; df -h " 2>/dev/null` fi hostline=`echo "$sshreq" | head -1` headers=`echo "$sshreq" | head -2 | tail -1 | awk '{ print $5"\t"$4"\t"$2"\t"$6}'` diskstatus=`echo "$sshreq" | tail -n+3 | awk '{ print $5"\t"$4"\t"$2"\t"$6}'` echo -e "Hostname: $hostline" echo -e "-------------------------------------------------\n" echo -e "$headers\n" echo "$diskstatus" | while read x; do percentageval=`echo "$x" | awk -F '%' '{print $1}'` echo -n "$x" padlength=`echo $x | awk '{print $4}'` threshold "$percentageval" "${#padlength}" done echo -en "\n\n" done /opt/scripts/config (#1029) pwd; cat SPproc.conf /opt/scripts/config SPwf1|192.168.1.10|AP