1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#!/usr/local/bin/python import ftplib import time import sys import datetime from datetime import date, timedelta import shutil yesterday = date.today() - timedelta(1) yesterday_minus_1 = yesterday.strftime('%Y%m%d') ftp = ftplib.FTP('ftp.server.com') ftp.login('fuser','password') def printerFunc(val1,val2,val3): print val1, val2, val3 def getCurrentLogFile(dt=datetime.datetime.now()): return "/home/application/log/ftpGet."+dt.strftime("%Y%m%d")+".log" def printToCurrentLog(line): filename = getCurrentLogFile(); fileObj = open(filename,'a') fileObj.write(datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S : ")+line+"\n"); fileObj.close(); def download(ftp,directory,file): ftp.cwd(directory) f = open(file,"wb") ftp.retrbinary("RETR " + file,f.write) f.close() ftpList = ["ftp", "ftp", "ftp"] directoryList = ["/Production/" , "/Production/Templates/Active/", "/Production/Configuration/"] fileList = ["secdef.dat.gz", "templates.xml", "config.xml"] for a, b, c in zip(ftpList, directoryList, fileList): printerFunc(a,b,c) for directory, file_name in zip(directoryList, fileList): download(ftp, directory, file_name) |
Month: May 2014
FInd Large Files Specified By Size Linux – BASH
1 2 3 4 |
[root@SERVER ~]# cat largefilefinder.sh #!/bin/sh find / -type f -size +200000k -exec ls -lh {} \; | awk '{print $9 ": " $5}' |
You can execute this and get your results to stdout.
1 2 |
[root@SERVER ~]# ./largefilefinder.sh /rhel-server-6.3-x86_64-dvd.iso: 3.5G |
Confirm String exists in log file and is not stale longer than 600 seconds – PYTHON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
[user@SERVER10 bin]$ cat checkLog.py import os import math import sys import datetime import time from datetime import timedelta import shlex, subprocess import smtplib import logging while True: logging.basicConfig(format='%(asctime)s %(message)s' , \ filename="/opt/strategy/log/restart.log", level=logging.DEBUG) now = datetime.datetime.now().strftime("%H:%M:%S") nowFormat = datetime.datetime.now().strftime("%Y%m%d") cmd = 'tail -n1000 /opt/strategy/log/Server_'+nowFormat+'-*.log | grep -i done | tail -n1 | awk "{print $1}" | cut -d " " -f1| cut -d "." -f1' callCmd = subprocess.check_output(cmd, stdin=None, stderr=None, shell=True, universal_newlines=False) strConvert = str(callCmd) nStr = strConvert[:7] intConvert = time.strptime(nStr, "%H:%M:%S") nowConvert = time.strptime(now, "%H:%M:%S") logTime = time.mktime(intConvert) nowTime = time.mktime(nowConvert) timeDiffSeconds = nowTime - logTime print "======================================================================================================================================================" print "Difference in Seconds: %d" % timeDiffSeconds print "======================================================================================================================================================" print "Log Tuple Date Construct: %s" % intConvert print "======================================================================================================================================================" print "Now Tuple Date Construct: %s" % nowConvert print "======================================================================================================================================================" print "Log Seconds Conversion: %d" % logTime print "======================================================================================================================================================" print "Now Seconds Conversion: %d" % nowTime print "======================================================================================================================================================" time.sleep(60) print "Testing difference in seconds" if timeDiffSeconds > 600: print "Done Fitting is no longer working" os.system("/opt/bin/mailAdmins.sh") logging.debug('Server has been restarted due to done being over due') time.sleep(600) |
Examine Log File To Be Sure O values Are Not Recieved – BASH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#Version 1.0 #DEBUG ON #set -x tail=$(which tail) echo=$(which echo) logDir=/opt/user/log binDir=/opt/user/bin retVal=$? #break=$(which break) todaysDate=$(date +"%Y-%m-%d*") todaysDateNoWc=$(date +"%Y-%m-%d*") Message=/tmp/Message.txt lastFile="" while true do currentFile=`ls -t ${logDir}/server.${todaysDate}-* | head -1` if test "${lastFile}" != "${currentFile}" then # the file has been changed totalErrorMessages=0 lastFile="${currentFile}" fi count=`grep -c -i 'Received values for 0 option(s) from server with 0 invalid values' ${currentFile}` if test ${count} -gt ${totalErrorMessages} then totalErrorMessages=${count} $binDir/mailIt.sh fi sleep 60 done |