| 1. |
Solve : zero bytes files? |
|
Answer» This one is for my job but I will not get paid for that but it will make my life a bit easier for me so I will PAY from my money. and when 5 of them is one after another. This means what? Quote from: Salmon Trout on February 10, 2019, 05:02:09 AM This means what? it means 5 files are created one by another with zero bytes, like this dat_9_2_2019_18_50.log 0 bytes dat_9_2_2019_19_30.log 0 bytes dat_9_2_2019_20_43.log 0 bytes dat_9_2_2019_22_10.log 0 bytes dat_9_2_2019_23_25.log 0 bytes that 5 files are deleted PC should reboot after that and counter will have number 1 in counter.txt dat_10_2_2019_00_50.log 0 bytes dat_10_2_2019_01_30.log 0 bytes dat_10_2_2019_02_43.log 0 bytes dat_10_2_2019_03_10.log 0 bytes dat_10_2_2019_04_25.log 0 bytes that 5 files are deleted PC should reboot after that and counter will have number 2 in counter.txt dat_10_2_2019_05_50.log 0 bytes dat_10_2_2019_06_30.log 0 bytes dat_10_2_2019_06_43.log 0 bytes dat_10_2_2019_08_10.log 0 bytes dat_10_2_2019_09_25.log 0 bytes that 5 files are deleted PC should reboot after that and counter will have number 3 in counter.txt I get an email that something is wrong and script stop to reboot PC until I delete counter.txt or change number 3 in it to 0 it can be situation like this one dat_5_2_2019_18_50.log 10 Kbytes dat_5_2_2019_19_30.log 0 Kbytes dat_5_2_2019_20_43.log 10 Kbytes dat_5_2_2019_22_10.log 0 bytes dat_5_2_2019_23_25.log 8 Kbytes Files with 0 bytes should be deleted and counter.txt should have 0 in it or like this one dat_4_2_2019_18_50.log 10 Kbytes dat_4_2_2019_19_30.log 11 Kbytes dat_4_2_2019_20_43.log 10 Kbytes dat_4_2_2019_22_10.log 0 bytes dat_4_2_2019_23_25.log 8 Kbytes File with 0 bytes should be deleted and counter.txt should have 0 in it But, logically any five files, listed in time order, will be "created one after another". Quote from: Salmon Trout on February 10, 2019, 06:23:53 AM But, logically any five files, listed in time order, will be "created one after another".Every new file is created about every ~45 minutes from last created file and yes you are rightYour comments please: So this is what you want? 1. Before the first run, create counter.txt and write the value 0 in it. 2. Every 30 minutes the batch will a. Look at folder: c:\administrator\data\ Count how many files are 0 bytes with this name pattern: dat_d_m_yyyy_hh_mm.log NOTE: the file name changes in number of characters, if day or MONTH is greater than 9? So we just use file mask dat_*.log Is that OK? b. if there are fewer than 5, just delete them, leave counter alone. if there are 5 or more, delete them, add 1 to counter, save to counter.txt, if new number is 3, something is wrong, send email (how??) if new number is 1,2, or 3, reboot computer. if number is greater than 3, do not reboot computer, you will manually reset after reading email. Your comments please: So this is what you want? 1. Before the first run, create counter.txt and write the value 0 in it. 2. Every 30 minutes the batch will a. Look at folder: c:\administrator\data\ Count how many files are 0 bytes with this name pattern: dat_d_m_yyyy_hh_mm.log NOTE: the file name changes in number of characters, if day or month is greater than 9? So we just use file mask dat_*.log Is that OK? That is exactly what is should be. b. if there are fewer than 5, just delete them, leave counter alone. OK if there are 5 or more, delete them, add 1 to counter, save to counter.txt, OK if new number is 3, something is wrong, send email (how??) bmail -s mail.myserver.com -f [email protected] -t [email protected] -h -a "Check PC software may not be working" -b "" -m .\path.txt if new number is 1,2, or 3, reboot computer. OK if number is greater than 3, do not reboot computer, you will manually reset after reading email. and delete counter.txt or change number from 3 to 0 BmailI have made a script which generates a logfile, I have tried it (manually not scheduled) with 0, then 3, then 5,5,5 zero byte files. It is still rough, but you can see what it does. You will not really see "Script exit" after "Rebooting computer" because the reboot will exit the script. If the script starts and finds the counter is 3 it just exits, (because you saw the email last time, and are coming to fix). I will just show the logfile now, tell me what you think. 10/02/2019 21:07:30.38 Started script 10/02/2019 21:07:30.40 Count read from file: 0 10/02/2019 21:07:30.60 Zero size files: 0 10/02/2019 21:07:30.60 Script exit ************************************** 10/02/2019 21:07:51.28 Started script 10/02/2019 21:07:51.30 Count read from file: 0 10/02/2019 21:07:51.47 Zero size files: 3 10/02/2019 21:07:51.63 0 bytes dat_2019_02_10_21_07_39.log 10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_40.log 10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_42.log 10/02/2019 21:07:51.66 Deleting 3 0 byte files 10/02/2019 21:07:51.82 Rebooting computer 10/02/2019 21:07:51.83 Script exit ************************************** 10/02/2019 21:08:20.46 Started script 10/02/2019 21:08:20.47 Count read from file: 0 10/02/2019 21:08:20.71 Zero size files: 5 10/02/2019 21:08:20.88 0 bytes dat_2019_02_10_21_07_58.log 10/02/2019 21:08:20.89 0 bytes dat_2019_02_10_21_08_00.log 10/02/2019 21:08:20.91 0 bytes dat_2019_02_10_21_08_01.log 10/02/2019 21:08:20.92 0 bytes dat_2019_02_10_21_08_02.log 10/02/2019 21:08:20.94 0 bytes dat_2019_02_10_21_08_03.log 10/02/2019 21:08:20.97 Deleting 5 0 byte files 10/02/2019 21:08:21.16 Found 5 or more files 10/02/2019 21:08:21.17 Count increased to 1 10/02/2019 21:08:21.21 Rebooting computer 10/02/2019 21:08:21.22 Script exit ************************************** 10/02/2019 21:08:46.24 Started script 10/02/2019 21:08:46.27 Count read from file: 1 10/02/2019 21:08:46.46 Zero size files: 5 10/02/2019 21:08:46.63 0 bytes dat_2019_02_10_21_08_30.log 10/02/2019 21:08:46.65 0 bytes dat_2019_02_10_21_08_32.log 10/02/2019 21:08:46.66 0 bytes dat_2019_02_10_21_08_33.log 10/02/2019 21:08:46.68 0 bytes dat_2019_02_10_21_08_34.log 10/02/2019 21:08:46.69 0 bytes dat_2019_02_10_21_08_35.log 10/02/2019 21:08:46.72 Deleting 5 0 byte files 10/02/2019 21:08:46.93 Found 5 or more files 10/02/2019 21:08:46.94 Count increased to 2 10/02/2019 21:08:46.96 Rebooting computer 10/02/2019 21:08:46.99 Script exit ************************************** 10/02/2019 21:09:12.14 Started script 10/02/2019 21:09:12.14 Count read from file: 2 10/02/2019 21:09:12.34 Zero size files: 5 10/02/2019 21:09:12.53 0 bytes dat_2019_02_10_21_08_56.log 10/02/2019 21:09:12.54 0 bytes dat_2019_02_10_21_08_57.log 10/02/2019 21:09:12.56 0 bytes dat_2019_02_10_21_08_58.log 10/02/2019 21:09:12.57 0 bytes dat_2019_02_10_21_09_00.log 10/02/2019 21:09:12.59 0 bytes dat_2019_02_10_21_09_01.log 10/02/2019 21:09:12.61 Deleting 5 0 byte files 10/02/2019 21:09:12.79 Found 5 or more files 10/02/2019 21:09:12.81 Count increased to 3 10/02/2019 21:09:12.82 Sending email 10/02/2019 21:09:12.86 Script exit ************************************** 10/02/2019 21:20:22.67 Started script 10/02/2019 21:20:22.67 Count read from file: 3 10/02/2019 21:20:22.70 Counter was 3 or more 10/02/2019 21:20:22.73 Script exit ************************************** this one will be good only in this situation 10/02/2019 21:07:51.28 Started script 10/02/2019 21:07:51.30 Count read from file: 0 10/02/2019 21:07:51.47 Zero size files: 3 10/02/2019 21:07:51.63 0 bytes dat_2019_02_10_21_07_39.log 10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_40.log 10/02/2019 21:07:51.64 100 bytes dat_2019_02_10_21_07_41.log 10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_42.log 10/02/2019 21:07:51.66 Deleting 3 0 byte files 10/02/2019 21:07:51.82 not Rebooting computer 10/02/2019 21:07:51.83 Script exit in this case 10/02/2019 21:07:51.28 Started script 10/02/2019 21:07:51.30 Count read from file: 0 10/02/2019 21:07:51.47 Zero size files: 3 10/02/2019 21:07:51.63 0 bytes dat_2019_02_10_21_07_39.log 10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_40.log 10/02/2019 21:07:51.64 0 bytes dat_2019_02_10_21_07_42.log 10/02/2019 21:07:51.66 not Deleting 3 0 byte files 10/02/2019 21:07:51.82 not Rebooting computer 10/02/2019 21:07:51.83 Script exit script should leave zero bytes files and next time it runs if there is more zero files like this than it delete and reboot. 10/02/2019 21:08:20.46 Started script 10/02/2019 21:08:20.47 Count read from file: 0 10/02/2019 21:08:20.71 Zero size files: 5 10/02/2019 21:08:20.88 0 bytes dat_2019_02_10_21_07_58.log 10/02/2019 21:08:20.89 0 bytes dat_2019_02_10_21_08_00.log 10/02/2019 21:08:20.91 0 bytes dat_2019_02_10_21_08_01.log 10/02/2019 21:08:20.92 0 bytes dat_2019_02_10_21_08_02.log 10/02/2019 21:08:20.94 0 bytes dat_2019_02_10_21_08_03.log 10/02/2019 21:08:20.97 Deleting 5 0 byte files 10/02/2019 21:08:21.16 Found 5 or more files 10/02/2019 21:08:21.17 Count increased to 1 10/02/2019 21:08:21.21 Rebooting computer 10/02/2019 21:08:21.22 Script exit if script find only 3 zero bytes files than it should leave it so next time it runs if there is 5 files of zero bytes than reboot computer, but if one of last 5 files is full and is not empty than it should delete zero bytes files and reset counter to 0counter = 0 no zero byte files 12/02/2019 20:23:13.24 Started script 12/02/2019 20:23:13.26 Count read from file: 0 12/02/2019 20:23:13.46 Zero size files: 0 12/02/2019 20:23:13.49 No 0 bytes files found; exiting 12/02/2019 20:23:13.52 Script exit ************************************** Counter = 0 3 zero byte files 12/02/2019 20:28:45.94 Started script 12/02/2019 20:28:45.97 Count read from file: 1 12/02/2019 20:28:46.16 Zero size files: 3 12/02/2019 20:28:46.33 0 bytes dat_2019_02_12_20_28_38.log 12/02/2019 20:28:46.34 0 bytes dat_2019_02_12_20_28_39.log 12/02/2019 20:28:46.37 0 bytes dat_2019_02_12_20_28_40.log 12/02/2019 20:28:46.39 Fewer than 5 0 bytes files; exiting 12/02/2019 20:28:46.41 Script exit ************************************** Counter = 0 6 zero byte files (repeated) 12/02/2019 20:32:23.08 Started script 12/02/2019 20:32:23.12 Count read from file: 0 12/02/2019 20:32:23.34 Zero size files: 6 12/02/2019 20:32:23.53 0 bytes dat_2019_02_12_20_30_43.log 12/02/2019 20:32:23.55 0 bytes dat_2019_02_12_20_30_44.log 12/02/2019 20:32:23.56 0 bytes dat_2019_02_12_20_30_46.log 12/02/2019 20:32:23.58 0 bytes dat_2019_02_12_20_30_47.log 12/02/2019 20:32:23.61 0 bytes dat_2019_02_12_20_30_48.log 12/02/2019 20:32:23.62 0 bytes dat_2019_02_12_20_30_49.log 12/02/2019 20:32:23.64 Found 5 or more files 12/02/2019 20:32:23.66 Count increased to 1 12/02/2019 20:32:23.69 Deleting 6 0 byte files 12/02/2019 20:32:23.92 Rebooting computer 12/02/2019 20:32:23.94 Script exit ************************************** 12/02/2019 20:33:40.52 Started script 12/02/2019 20:33:40.55 Count read from file: 1 12/02/2019 20:33:40.75 Zero size files: 6 12/02/2019 20:33:40.94 0 bytes dat_2019_02_12_20_33_24.log 12/02/2019 20:33:40.95 0 bytes dat_2019_02_12_20_33_25.log 12/02/2019 20:33:40.97 0 bytes dat_2019_02_12_20_33_26.log 12/02/2019 20:33:40.98 0 bytes dat_2019_02_12_20_33_27.log 12/02/2019 20:33:41.00 0 bytes dat_2019_02_12_20_33_29.log 12/02/2019 20:33:41.03 0 bytes dat_2019_02_12_20_33_30.log 12/02/2019 20:33:41.05 Found 5 or more files 12/02/2019 20:33:41.06 Count increased to 2 12/02/2019 20:33:41.09 Deleting 6 0 byte files 12/02/2019 20:33:41.30 Rebooting computer 12/02/2019 20:33:41.31 Script exit ************************************** 12/02/2019 20:43:01.70 Started script 12/02/2019 20:43:01.73 Count read from file: 2 12/02/2019 20:43:01.97 Zero size files: 6 12/02/2019 20:43:02.16 0 bytes dat_2019_02_12_20_35_34.log 12/02/2019 20:43:02.17 0 bytes dat_2019_02_12_20_35_36.log 12/02/2019 20:43:02.19 0 bytes dat_2019_02_12_20_35_37.log 12/02/2019 20:43:02.20 0 bytes dat_2019_02_12_20_35_38.log 12/02/2019 20:43:02.23 0 bytes dat_2019_02_12_20_35_39.log 12/02/2019 20:43:02.25 0 bytes dat_2019_02_12_20_35_41.log 12/02/2019 20:43:02.26 Found 5 or more files 12/02/2019 20:43:02.28 Count increased to 3 12/02/2019 20:43:02.31 Deleting 6 0 byte files 12/02/2019 20:43:02.51 Sending email 12/02/2019 20:43:02.55 Script exit ************************************** 12/02/2019 20:44:23.95 Started script 12/02/2019 20:44:24.01 Count read from file: 4 12/02/2019 20:44:24.04 Counter was 3 or more 12/02/2019 20:44:24.04 Script exit ************************************** Script looking verry good but What happends in this case? 12/02/2019 20:43:01.70 Started script 12/02/2019 20:43:01.73 Count read from file: 2 12/02/2019 20:43:01.97 Zero size files: 6 12/02/2019 20:43:02.16 0 bytes dat_2019_02_12_20_35_34.log 12/02/2019 20:43:02.17 0 bytes dat_2019_02_12_20_35_36.log 12/02/2019 20:43:02.19 0 bytes dat_2019_02_12_20_35_37.log 12/02/2019 20:43:02.20 0 bytes dat_2019_02_12_20_35_38.log 12/02/2019 20:43:02.23 10 Kbytes dat_2019_02_12_20_35_39.log 12/02/2019 20:43:02.25 0 bytes dat_2019_02_12_20_35_41.log 12/02/2019 20:43:02.26 Found 5 or more files 12/02/2019 20:43:02.28 Count increased to 3 12/02/2019 20:43:02.31 Deleting 6 0 byte files 12/02/2019 20:43:02.51 Sending email 12/02/2019 20:43:02.55 Script exitIn that case, the 5 zero bytes files are deleted, the count is increased to 3, the email is sent, computer is not restarted. What did you want to happen? In all of these tests these files are also there, they are ignored. 10/02/2019 20:12 37 dat_2019_02_10_20_12_16.log 10/02/2019 20:12 37 dat_2019_02_10_20_12_17.log 10/02/2019 20:12 37 dat_2019_02_10_20_12_18.log 10/02/2019 20:12 37 dat_2019_02_10_20_12_20.log To be clear, the script only counts the files that are 0 bytes. All other files with size larger than 0 are not counted or processed, and their presence or absence does not trigger any actions. |
|