Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: zero bytes files  (Read 6883 times)

0 Members and 1 Guest are viewing this topic.

Blisk

    Topic Starter


    Intermediate

    Thanked: 1
    • Experience: Familiar
    • OS: Windows 7
    zero bytes files
    « on: February 10, 2019, 02:25:10 AM »
    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.
    It is next thing, we have an old PC with some odl software on it. And that software stops to work every fev days or weeks. Nobody knows why and how.
    So I made a script which check a presence of dat_9_2_2019_18_20.log file. If script finds out that file is 0 Size and it is present in folder c:\administrator\data\dat_9_2_2019_18_20.log than it send me an email so when I see email I go to basement and restart that old PC.
    I asked my boss many times to buy new PC and new software but he refuse he said it is to expencive and this still works good and it is my job to go now or than to reset that pc.
    So I get an idea.
    I can run script by task scheduler to check if that file  dat_9_2_2019_18_20.log is present and its size is 0 bytes than it restart pc automatically.
    Problem is that software did not stop to work everytime when one file with 0 bytes is present, but when fev of them are in that folder. Rebooting to often is not good, because it takes about 15-25 minutes to restart PC to  work again.
    So I thought if I can have a script which will start in task scheduler every 30 minutes and check folder c:\administrator\data if there are for example 5 files  or more like these
    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
    and all of them are empty than pc will reboot automatically. But it can reboot only 3 times after that I get an email and script stops to reboot. until I check what is going on and delete counter.txt file where script write number 3 which stops script to reboot after 3 times do that.
    I already have script to send an email but this counting zero bytes files and reboot, that I can't manage to work it out.
    In folder c:\administrator\data\ there is about 300 files and most of them are fev Kb and some are 0 bytes, those 0 bytes I usually delete and it can be all deleted or moved to another folder after script reboot PC. But those files fev KB must stay. Problem I also see here when one file (dat_9_2_2019_23_25.log 0 bytes) and right next after that file is another full file (dat_9_2_2019_23_50.log 10Kb), than that 0 bytes file should be deleted and counter.txt put to zero 0, or deleted, to star all over again. Because that means software still works ok.
    so how much for this script?

    Salmon Trout

    • Guest
    Re: zero bytes files
    « Reply #1 on: February 10, 2019, 03:19:05 AM »
    1. You want to delete ALL dat*.log files that are zero bytes in size?
    2. or wait until there are >= 5 such files?
    3. From folder c:\administrator\data\ ?
    4. You say you want to reset counter.txt to "zero 0". What does that mean? You want that exact text? The word zero, then a space, then a figure 0?
    5. Where is counter.txt located?

    6. A good question to ask - why are all these zero byte files being created? is this caused when the software stops for an unknown reason?

    7. It is not clear if you want the PC to reboot after the deletions.






    Blisk

      Topic Starter


      Intermediate

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: zero bytes files
      « Reply #2 on: February 10, 2019, 03:29:06 AM »
      1. You want to delete ALL dat*.log files that are zero bytes in size? Yes deleted or moved to new folder, one or other, with PC reboot.
      2. or wait until there are >= 5 such files?  yes soure it should wait, to count files and when 5 of them is one after another.
      3. From folder c:\administrator\data\ ? yes
      4. You say you want to reset counter.txt to "zero 0". What does that mean? You want that exact text? The word zero, then a space, then a figure 0? in file counter.txt script will write just a number how many times PC reboots and when find number 3 it stops to reboot. So when I delete file or change number 3 in 0 than script works again and reboot if find 5 files with 0 bytes
      5. Where is counter.txt located? doesn't matter it can be in  c:\administrator

      6. A good question to ask - why are all these zero byte files being created? is this caused when the software stops for an unknown reason?
      yes I notice that when software stops to work all those dat****.log files are created one by another

      7. It is not clear if you want the PC to reboot after the deletions. when there are 5 files with 0 bytes than files can be deleted and imediatelly after that PC reboots. It doesn't need to reboot and after that files are deleted it can be deleted with rebooting.

      Salmon Trout

      • Guest
      Re: zero bytes files
      « Reply #3 on: February 10, 2019, 05:02:09 AM »
      and when 5 of them is one after another.

      This means what?

      Blisk

        Topic Starter


        Intermediate

        Thanked: 1
        • Experience: Familiar
        • OS: Windows 7
        Re: zero bytes files
        « Reply #4 on: February 10, 2019, 06:10:41 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


        Salmon Trout

        • Guest
        Re: zero bytes files
        « Reply #5 on: February 10, 2019, 06:23:53 AM »
        But, logically any five files, listed in time order, will be "created one after another".

        Blisk

          Topic Starter


          Intermediate

          Thanked: 1
          • Experience: Familiar
          • OS: Windows 7
          Re: zero bytes files
          « Reply #6 on: February 10, 2019, 06:27:08 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 right

          Salmon Trout

          • Guest
          Re: zero bytes files
          « Reply #7 on: February 10, 2019, 06:59:46 AM »
          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?

          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.



          Blisk

            Topic Starter


            Intermediate

            Thanked: 1
            • Experience: Familiar
            • OS: Windows 7
            Re: zero bytes files
            « Reply #8 on: February 10, 2019, 07:15:24 AM »
            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


            Bmail
            « Last Edit: February 10, 2019, 07:41:26 AM by Blisk »

            Salmon Trout

            • Guest
            Re: zero bytes files
            « Reply #9 on: February 10, 2019, 02:17:04 PM »
            I 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
            **************************************

            Blisk

              Topic Starter


              Intermediate

              Thanked: 1
              • Experience: Familiar
              • OS: Windows 7
              Re: zero bytes files
              « Reply #10 on: February 11, 2019, 02:20:01 AM »
              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 0

              Salmon Trout

              • Guest
              Re: zero bytes files
              « Reply #11 on: February 12, 2019, 01:47:10 PM »
              counter = 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
              **************************************









              Blisk

                Topic Starter


                Intermediate

                Thanked: 1
                • Experience: Familiar
                • OS: Windows 7
                Re: zero bytes files
                « Reply #12 on: February 12, 2019, 01:54:29 PM »
                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 exit

                Salmon Trout

                • Guest
                Re: zero bytes files
                « Reply #13 on: February 12, 2019, 02:06:05 PM »
                In 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

                Salmon Trout

                • Guest
                Re: zero bytes files
                « Reply #14 on: February 12, 2019, 02:13:17 PM »
                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.