Python Forum
python 3 find difference between 2 files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python 3 find difference between 2 files
#1
Hi,
I'm working a file system monitoring script. When I compare two files in the below script, it's returning non-zero value even though both files are same. I checked for any special characters also.
When I run the diff command on shell it shows no difference and echo $? returns zero. Please help me solve this issue.

[root@]# cat fs.txt
home=17
apps=7
work=54

[root@log]# cat apps_WARN_20200514-1210
7
[root@log]# cat apps_WARN_20200514-1211
7

[root@]# ./check_fs_usage.py
0a1
> 7
1


#!/usr/bin/env /opt/anaconda3/bin/python

import datetime
import os
import sys
import subprocess

DT = datetime.datetime.now().strftime("%Y%m%d-%H%M")
FP = '/root/pyscripts/log/'

with open ('/root/pyscripts/log/fs.txt', 'r') as FS:
    for x in FS.readlines():
        if int(x.split('=')[1]) >= 5 and int(x.split('=')[1]) <=10:
            with open(FP + x.split('=')[0] + "_WARN_" + DT, "w") as WF:
                WF.write(x.split('=')[1])
                subprocess.call("ls -1tr | grep " + x.split('=')[0] + "_WARN| head -n -2 | xargs -d '\n' rm -f --", shell=True)
                FN = WF.name
                FN = FN.split('/')[4]
                OldFN = subprocess.check_output("ls -1tr | grep " + x.split('=')[0] + "_WARN | grep -v " + FN, shell=True)
                OldFN = str(OldFN, 'utf-8').strip()
                os.chdir(FP)
                STATUS = subprocess.call('diff ' + FN + ' ' + OldFN, shell=True)
                print(STATUS)
                
I also tried, but same error:
STATUS = subprocess.call('diff ' + x.split("=")[0] + '_WARN*  > /dev/null 2>&1', shell=True)
Reply


Messages In This Thread
python 3 find difference between 2 files - by pd007 - May-14-2020, 04:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find duplicate files in multiple directories Pavel_47 9 3,104 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  count every 28 files and find desire files RolanRoll 3 2,074 Dec-12-2021, 04:42 PM
Last Post: Axel_Erfurt
  Have to use Python 2.x to find "yesterday' files tester_V 6 2,829 Sep-19-2021, 12:26 AM
Last Post: tester_V
  find 'yesterdays files' tester_V 8 3,838 Jun-18-2021, 02:10 AM
Last Post: tester_V
  Find and replace in files with regex and Python Melcu54 0 1,849 Jun-03-2021, 09:33 AM
Last Post: Melcu54
  how to find difference between fake driving license or real using python? pjaymn 2 2,559 Dec-20-2020, 08:41 PM
Last Post: jefsummers
  List of error codes to find (and count) in all files in a directory tester_V 8 3,680 Dec-11-2020, 07:07 PM
Last Post: tester_V
  helping PyInstaller To Find files Harshil 0 1,484 Aug-30-2020, 10:16 AM
Last Post: Harshil
  Find specific subdir, open files and find specific lines that are missing from a file tester_V 8 3,581 Aug-25-2020, 01:52 AM
Last Post: tester_V
  Find all “*.wav” files that created yesterday on linux host with python. pydeev 6 4,780 Jan-07-2020, 06:43 AM
Last Post: pydeev

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020