One-liners: Difference between revisions
→Compare two wikis for extensions and skins: add footnote about one-liner not working |
add a find example |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 30: | Line 30: | ||
==Compare two wikis for extensions and skins== | ==Compare two wikis for extensions and skins== | ||
This one-liner invokes the API of two wikis asking for info on siteinfo, general, extensions and skins; in json format. Since that data is returned without any newlines, we use | This one-liner invokes the API of two wikis asking for info on siteinfo, general, extensions and skins; in json format. Since that data is returned without any newlines, we use <code>jq</code> to pretty-print the json output. Then it's an easy <code>meld</code> or <code>diff</code> to compare them. The <code>--silent</code> option to <code>curl</code> just suppresses the connection and retrieval metadata; while the <code>-L</code> is customary to follow redirects. | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
A='https://wiki.freephile.org/wiki' B='https://www.mediawiki.org/w' API='/api.php?action=query&meta=siteinfo&siprop=general%7Cextensions%7Cskins&format=json' meld <(curl --silent -L "${A}${API}" | jq '.') <(curl --silent -L "${B}${API}" | jq '.')</syntaxhighlight> | A='https://wiki.freephile.org/wiki' B='https://www.mediawiki.org/w' API='/api.php?action=query&meta=siteinfo&siprop=general%7Cextensions%7Cskins&format=json' meld <(curl --silent -L "${A}${API}" | jq '.') <(curl --silent -L "${B}${API}" | jq '.')</syntaxhighlight> | ||
The wiki farm detection has changed (@fixme) on this site making it slightly different from mediawiki.org. Still, the one-liner should work but is failing silently whereas a manually executed substitution of <code>meld <(curl --silent -L "https://wiki.freephile.org/wiki/api.php?action=query&meta=siteinfo&siprop=general%7Cextensions%7Cskins&format=json" | jq '.') <(curl --silent -L "https://www.mediawiki.org/w/api.php?action=query&meta=siteinfo&siprop=general%7Cextensions%7Cskins&format=json" | jq '.')</code> does launch meld with the proper content. | |||
Using more than a single line of code, you can do things with PHP's <code>yaml_parse</code> such as [https://github.com/freephile/meza/blob/37b9be51289b16868730cbc1070a188159323ee7/src/scripts/findDupesInLocalExtensions.php src/scripts/findDupesInLocalExtensions.php] | |||
==Perl edit== | ==Perl edit== | ||
| Line 94: | Line 99: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Find with exclusions == | |||
Trying to fix [[permissions]], I wanted to see if there were any executable files in the 'data' directory. It turned out that every file in the elasticsearch and uploads directories were +x somehow. So, I wanted to exclude those dirs and see if there was anything else. | |||
<syntaxhighlight lang="bash"> | |||
sudo find /opt/data-meza/ \( -name uploads -o -name elasticsearch \) -prune -o -type f -perm -ugo=x -ls | |||
</syntaxhighlight> | |||
{{References}} | {{References}} | ||