Powered by Blogger.
Showing posts with label tips. Show all posts

Wednesday, July 31, 2013

Clear file by time create

No comments :
This is bash shell to clear file create by time with 60 m * 8 hour = 480 m :

 #!/bin/bash  

 homedir=( folderName1  
 folderName2  
 folderName3  
 folderName4  
  )  

 for d in ${homedir[@]}  
 do  
     echo "Homedir: /var/nginx/cached/$d"  
     find "/var/nginx/cached/$d" -type f -amin +480 -exec rm {} \;  
 done  

Tuesday, July 30, 2013

Source Code Formatter for Blogger

No comments :
This is website I made source code show like clear : codeformatter.blogspot.com

This is example :
 <?php  
 $result = shell_exec("comand shell");  
 print "<pre>".$result."</pre>";  
 ?>  

Clear cache by python

No comments :
I'm learning programming python, this is my script python to show list folder and clear file on them. :)
 #!/usr/sbin/python  

 import os  
 import subprocess  

 class CachedNginx:  
   def __init__(self):  
     pass  

   def clearCached(self, folder):  
     strDir = "rm -rf /dir/"  
     strDir += folder  
     strDir += "/*"  
     print (strDir)  
     result = subprocess.Popen(strDir, stdout=subprocess.PIPE, shell=True)  
     data, error = result.communicate()  
     if error == None:  
       print ("Clear success")  

 def listCached(cachedNginx):  
   list = subprocess.Popen("ls /dir/",stdout=subprocess.PIPE, shell=True)  
   data,error = list.communicate()  
   print ("You choise cache to clear : ")  
   number = 0  
   lists = {}  
   for cache in iter(data.splitlines()):  
     print ("["+ str(number) +"]" + cache.decode("utf-8"))  
     lists[str(number)] = cache.decode("utf-8")   
     number += 1  

   choise = input("Select number choise : ")  
   if int(choise) < number:  
       cachedNginx.clearCached(lists[choise])
  
 def main():  
   cached = CachedNginx()  
   listCached(cached)  

 if __name__ == '__main__':  
   main()  

Friday, July 26, 2013

Tips : how php exec shell on server

No comments :
 <?php  
 $result = shell_exec("comand shell");  
 print "<pre>".$result."</pre>";  
 ?>