31.07.2015 г.

Search for ip and resolv with hostname for enybody file

#!/bin/bash

#Path to file with ip-s
FILE="/home/ips.txt"
#Command to resolv ip- with hostname
DIG="dig +short -x "
#Search for ip in file SEARCH=`cat $FILE | egrep -Eo '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | sort -t . -k 1,1n -k 2,2n -k3,3n -k4,4n`

#For clasuse
for i in $SEARCH;do
    echo -ne "$i\t-\t" "\e[1;33m `$DIG$i`\e[0m" "\n"
done

22.07.2015 г.

Python backup firebird base

 import os,shutil, subprocess  
 from datetime import datetime  
 file_destination = ["/home/borko/base/firebird.fdb"]  
 #Must change path to folder if user not called "borko"  
 copy_destination = "/home/borko/base/archive/"  
 #Full path to gbak  
 gback_file = "/opt/firebird/bin/gbak"  
 #Get time and date to add into archive  
 date = str(datetime.now())  
 datetime = date.replace(' ','')  
 count=0  
 #Input how much file save in folder!!!!  
 save_file = 2  
 #Set params for Gbak  
 server='127.0.0.1'  
 user = "SYSDBA"  
 password = "masterkey"  
 #List with older file which must delete  
 list_file_delete = []  
 #Function check for problems  
 def check_file_and_filder(folder,name):  
     if not os.path.isdir(folder):  
         try:  
             os.makedirs(folder)  
         except:  
             pass  
     for file_search in name:  
         if not os.path.isfile(file_search):  
             print "File not exists"  
 #Function calculate file in folder  
 def calculate():  
     count = 0  
     del_count=1  
     for i in file_destination:  
         search_name = i.split("/")[-1]  
         for search in os.listdir(copy_destination):  
             if search.startswith(search_name):  
                 list_file_delete.append(os.path.join(copy_destination,search))  
                 count+=1  
         if count > save_file:  
             print "Poveche sa s %d" % (count-save_file)  
             how_much = (count-save_file)  
             new_list_for_delete = {i:float(os.stat(i).st_mtime) for i in list_file_delete}  
             elem_to_delete = dict(list(sorted(new_list_for_delete.items(), key=lambda x: x[1]))[:(count-save_file)])  
             for del_elem in elem_to_delete.keys():  
                 os.remove(del_elem)  
 #Function mace backup  
 def backup_resurse():  
     for i in file_destination:  
         backup = subprocess.Popen('''{0} -v -t -user {1} -password {2} {3}:{4} {5}{6}.fbk'''  
         .format(gback_file,user,password,server,i,copy_destination, i.split("/")[-1]+datetime),shell=True)  
 #Start the magic  
 if __name__ == "__main__":  
     check_file_and_filder(copy_destination,file_destination)  
     calculate()  
     backup_resurse()  

2.07.2015 г.

Find Picture in Folder and print only name of them

for i in `find /home/name/Image -type f -name "*.jpg"`;\
do n=`echo $i | awk -F"/" '{print $NF}'`\
| echo ${n//.*}; done




for i in `find /home/name/Image -type f -name "*.jpg"` # Found some picture's
n=`echo $i | awk -F"/" '{print $NF}' #From the top row print only last name of the result
echo ${n//.*} #Remove .avi from file

Change file after time use root access (use for configure network)

su -c bash -c "sleep 1m; mv file_orig.txt file_orig-backup.txt"

su -c #Run root only for command
basj -c #Run bash
"sleep 1m" #Sleep 1 minute
The last is the command you want.