I want to filter a log file using logcheck, but instead of setting rules for the log messages I want to ignore, I would like to define rules just for the ones that I want to receive in my inbox. Is it possible to do somehting like that using negative logic (like egrep -v)?
This Regex [^abc] equals not a, b, or c
I can't give great examples, but I believe you can ignore everything and then list the patterns you want flagged in either the violations.d or cracking.d directories.
So in ignore.d.server, remove all files, create a single file containing '^.'
Define patterns in violations.d
You can create a separate config directory for this, copying all of the /etc/logcheck contents to a new directory, editing logcheck.conf to list the correct RULEDIR, and then test with a command something like:
sudo -u logcheck logcheck -c /tmp/logcheck/logcheck.conf -o -t
Related
I have done a simple pipeline where I take a couple of files, merge them (well not really, but let's pretend they are merged) into one whose filename is a simple combinations of the two (file1_file2.output) and perform some operations. The pipeline works perfectly if I manually provide the filenames for both file1 and file2, but what I really what to do is something like this:
Let's pretend I have 5 files A, B, C, D and E. I want to run the pipeline for those pairs: A-D, B-D and C-E and this is the Snakefile
rule all:
input:
expand("output/{file1}_{file2}.output")
rule Paste:
input:
F1="{file1}",
F2="{file2}"
output:
out="output/{file1}_{file2}.output"
shell:
"paste {input.F1} {input.F2} > {output.out}"
What is the best way to do so?
You have to define the real names of the target files in rule all. Then use the wildcards to get the input files. It would look like this:
rule all:
input:
expand("output/{combination}.output", combination=["A_D","B_D","C_E"])
rule Paste:
input:
F1="{file1}",
F2="{file2}"
output:
out="output/{file1}_{file2}.output"
shell:
"paste {input.F1} {input.F2} > {output.out}"
Please note that using a poor separator like "_" might mess up the wildcards determination if your input files (A,B,C,D,E) also contain "_". I would use something you are sure will not be used in a file name (ie: "__", "_-_", or anything appropriate)
I am trying to use rsync to complete an unfinished transfer from a remote server to a local machine using
rsync -a user#domain.com:~/source/ /dest/
where /dest/ is the location of the partially completed transfer. However, due to bandwidth concerns I need to run rsync to a /tmp_dest/ on a different machine that does not have a copy of /dest/, from where I can then later move /tmp_dest/ to /dest/
The solution I have come up with thus far is to use rync's --exclude-from option, using a file containing a complete list of files from /dest/.
The command would look something like this
rsync -a --exclude-from 'list.txt' user#domain.com:~/source/ /tmp_dest/
At this point I feel as though I have scoured everywhere for a solution and tried every variant I came across.
This included relative and absolute paths for the 'list.txt'
relative:
path 1/file 1
path 2/file 2
--or--
absolute:
/absolute/source/path 1/file 1
/absolute/source/path 2/file 2
I have tried the above with combinations of including - to explicitly exclude that line (where I have seen examples of people wanting to also + other files)
- /absolute/source/path 1/file 1
- /absolute/source/path 2/file 2
I have tried putting leading **/ in front of the file paths to rectify the relative path problem
**/path 1/file 1
**/path 2/file 2
I have also tried navigating to the directory containing 'list' and executing rsync from there, to avoid the issue where rsync looks for
/path/to/the/list/something1/to.exclude
/path/to/the/list/something2/to.exclude
/path/to/the/list/something3/to.exclude
and undoubtedly finding nothing
I have also ensued that the correct line breaks are being used in the 'list' file. i.e. LF (Unix) line breaks.
I have tried to create the 'list' with the following command
find . -type f | tee list.txt
this initially created a file looking something like this
./yyyy-mm-dd folder 1/sub folder [foo]/file.a
./(yyyy) folder 2 {foo2}/file.b
./folder, 3/sub-folder 3/file.c
as you can see, there are spaces and other characters in the file paths, but from my current understanding, this shouldn't affect. But perhaps I am mistaken and will need to escape any characters with special meaning, which I may then need help with
which I then perform a replace on ./ in notepad++ or some other text editor that preserves the LF (Unix) line breaks to get the desired result.
(e.g. as above, I've tried replacing ./ with nothing, with /absolute/path/for/source/ noting the leading slash, or even double wildcards to match any parent tree structure containing the files.
The only thing I feel that I haven't tried is escaping the spaces in the file names and paths, but I have read that this shouldn't be an issue.
Perhaps I am overlooking something and any help would be appreciated.
Here is from rsync man page how to use "--exclude-from":
--exclude-from=FILE read exclude patterns from FILE
Use the following command:
rsync -a --exclude-from=list.txt user#domain.com:~/source/ /tmp_dest/
And also it is better to use full path name of list.txt file
I'd like to replace some unknown values within a directory of binary files. Some, but now all the the files in the directory contain (mid way through a line) something like the following.
"myValue":"65"
I'd like to be able to modify them all to something like
"myValue":"57"
I don't know the initial value as it's different in each file but I'd like them all to be the same. I guess i'm going to need sed with regex but I'm absolutely useless with regular expressions.
here's how:
cd directory
gsed -i 's/"myValue":"[0-9]\+"/"myValue":"57"/g' *
(following jthill's & andlrc's comments, i use gsed instead of sed.)
I need a nice column for Centrify tool which include all the log files under the different folders, for example;
/oradata1/oracle/admin/A/scripts/rman_logs/*.log
/oracle/oracle/admin/B/scripts/rman_logs/*.log
/oradata2/admin/C/scripts/logs/*.log
I used this but after the * character user can see all logs;
/ora(data(1|2)|cle)/oracle|admin/admin/*/scripts/rman_logs
/ora(data(1|2)|cle)/oracle|admin/admin/*/scripts/rman_logs
Which expression I must use.
If I understandy our question correctly, you want only .log files. You can use a positive lookahead to assert that it is indeed a log file (contains .log at the end of filename), and match the filename whatever it is (.*).
Then it's really easy. (?=.*\.log(?:$|\s)).* Of course, you can also add specific folders if you wish to restrict the matches, but the positive lookahead will still do its work. I.e. (?=.*\.log(?:$|\s)).*/scripts/.*
EDIT: As your comment, you only need those folders, so you just specify their filepaths in alternations and add [^.\s\/]*\.log at the end. So:
(?:\/oradata1\/oracle\/admin\/A\/scripts\/rman_logs\/|\/oracle\/oracle\/admin\/B\/scripts\/rman_logs\/|\/oradata2\/admin\/C\/scripts\/logs\/)[^\s.\/]*\.log You may shorten the regex by trying to combine filepath elements, but, imo, not necessary as you might as well specify each filepath individually, if they don't overlap too much.
I have found a global expression.
this is not a good way but it works and save me from lots of job. The main files are under the ....../scripts/rman_logs/ for all servers so I use this way.
I can produce these lines and can be a command group for users so this works good
tail /////scripts/rman_logs/*.log
tail ////scripts/rman_logs/.log
Thanks for your helps.
I have a bunch of PHP coded websites that have been recently moved to a PHP 5.4 server and they're throwing deprecation warnings and errors.
Is there a way to mass find & replace function names with the proper ones? For example, I would like to be able to replace all instances of session_unregister('someVar') with unset($_SESSION['someVar'])...
Should i use regex or is there an other way?
For this particular example you could use sed like this:
echo "session_unregister('someVar')" | sed 's/session_unregister(/unset\($_SESSION[/;s/)/])/'
A bit more flexible would be to use the C preprocessor. Assume your php source file name is my.php. Add extension .h so it becomes my.php.h. At the beginning of the file, insert:
#define session_unregister(X) unset($_SESSION[X])
Assume the file contains lines like in your example: session_unregister('someVar')
Run the preprocessor like this:
cc -E my.php.h
Now you should instead see unset($_SESSION['someVar'])
(plus some extra garbage you don't want).
Note that this just answers your particular question, but I wouldn't recommend it without more detailed testing.