замена одинарных кавычек на двойные в файле

Проблема, по-видимому, в том, что crontab не знает PATH, где находится команда arp.

Я бы использовал:

* * * * * /usr/sbin/arp -n >> results.txt

Тем не менее, я бы использовал arpwatch для мониторинга изменений ARP. Он работает как демон и регистрирует изменения MAC-адреса в файле с течением времени вместе с эпохой изменения. Он также может отправлять сообщения в системный журнал и электронную почту.

От человек арпвотч

Arpwatch keeps track for ethernet/ip address pairings. It syslogs activity and reports certain changes via email. Arpwatch uses pcap(3) to listen for arp packets on a local ethernet interface.

Report Messages

Here's a quick list of the report messages generated by arpwatch(1) (and arpsnmp(1)):

new activity This ethernet/ip address pair has been used for the first time six months or more.

new station The ethernet address has not been seen before.

flip flop The ethernet address has changed from the most recently seen address to the second most recently seen address. (If either the old or new ethernet address is a DECnet address and it is less than 24 hours, the email version of the report is suppressed.)

changed ethernet address The host switched to a new ethernet address.

Syslog Messages

Here are some of the syslog messages; note that messages that are reported are also sysloged.

ethernet broadcast The mac ethernet address of the host is a broadcast address.

ip broadcast The ip address of the host is a broadcast address.

bogon The source ip address is not local to the local subnet.

ethernet broadcast The source mac or arp ethernet address was all ones or all zeros.

ethernet mismatch The source mac ethernet address didn't match the address inside the arp packet.

reused old ethernet address The ethernet address has changed from the most recently seen address to the third (or greater) least recently seen address. (This is similar to a flip flop.)

suppressed DECnet flip flop A "flip flop" report was suppressed because one of the two addresses was a DECnet address.

Files

/var/lib/arpwatch - default directory

arp.dat - ethernet/ip address database

ethercodes.dat - vendor ethernet block list

3
23.10.2019, 15:30
2 ответа

Чтобы заменить одинарные кавычки ('), проще всего поместить команду sed в двойные кавычки и избежать двойных кавычек при замене:

$ cat quotes.txt 
I'm Alice
$ sed -e "s/'/\"/g"  quotes.txt 
I"m Alice

Обратите внимание, что одинарная кавычка не является специальной в двойных кавычках, поэтому ее нельзя экранировать.

Если вместо этого кто-то хочет заменить обратные кавычки (`), как изначально упоминалось в вопросе, их можно использовать, поскольку -находится в одинарных кавычках:

$ cat ticks.txt
`this is in backticks`
$ sed -e 's/`/"/g'  ticks.txt
"this is in backticks"

В двойных кавычках вам нужно экранировать обратную косую черту с помощью обратной косой черты, поскольку в противном случае начинается старая -подстановка команды формы.

См. также:

10
27.01.2020, 21:07

Для изменения одного символа trможет быть самым быстрым:

tr \' \" <infile >outfile

Обратите внимание, что обе кавычки необходимо экранировать в среде оболочки. Или для замены в этом же файле используйтеsponge(из пакета moreutils)

tr \' \" <infile | sponge infile
6
27.01.2020, 21:07

Теги

Похожие вопросы