incron - How to Edit File via incrond/python -
incron - How to Edit File via incrond/python -
how 1 go making script first edit newly found file within specific directory, , upload through incron/python? i'm bit confused how specify filename string in python script.
incrontab -e :
/var/test in_create /var/pythoncode/code.py python code:
s = open("confused.txt").read() s = s.replace("string1", "string2") f = open("confused.txt", 'w') f.write(s) f.close() essentially, trying have incron service find new file found within /var/test folder , , execute python code , replace string within new file found in /var/test. however, uncertain how approach "confused.txt" filename string, since each file found /var/test have dynamic name.
here's workaround assuming verse scripting -
step 1 - alter files in directory (change , names $file in ls).
step 2 - store lastly file name in variable $last_file
step 3 - run while loop find files newer $last_file -
find /var/test/ -newer $last_file or
find /var/test/ -type f -newer $last_file or
find /var/test/ -type f -iname "*.txt" -newer $last_file this list files newer lastly file edited. so, parse list "change file" script.
python incron
Comments
Post a Comment