Advertisement
promanaged

ip_run.sh

Jan 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.97 KB | None | 0 0
  1. #!/bin/bash
  2. # Все TXT-файлы помещаются в подкаталог ip_files_txt
  3. ip_files=( `ls ip_files_txt/*.txt` )
  4. # Лог запусков ip.sh сохранятеся в файл ipsh.log, формат - дата, индекс файла, имя файла
  5.  
  6. newrun()
  7. {
  8.     kilall -9 ip.sh; killall -9 ip
  9.     ./ip.sh FILE=$current_file &
  10.     sleep 600
  11. }
  12.  
  13. getfile()
  14. {
  15.     if [ -e ipsh.log ]
  16.     then
  17.         last_file_idx=`tail -n 1 ipsh.log | awk '{print $2}'`
  18.         if [[ $((${#ip_files[*]} - $last_file_idx)) -gt 1 ]]
  19.         then
  20.             let "current_file_idx = $last_file_idx + 1"
  21.         else
  22.             let "current_file_idx = 0"
  23.         fi
  24.     else
  25.         let "current_file_idx = 0"
  26.     fi
  27.     current_file=${ip_files[$current_file_idx]}
  28.     data=`date +%Y-%m-%d-%H:%M`
  29.     echo "$data $current_file_idx $current_file"
  30.     echo "$data $current_file_idx $current_file" >> ipsh.log
  31. }
  32.  
  33. while true
  34. do
  35.     getfile
  36.     newrun
  37.     echo
  38. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement