Skip to content

Commit

Permalink
bash, mac, git, linux, nano, vmware, zabbix, openvpn
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsiryk committed May 26, 2017
1 parent 2728071 commit c4f4128
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 8 deletions.
43 changes: 42 additions & 1 deletion MacOS/mac_os.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@
Mac OS instructions
===================

Manipulating OS X login items from command line

- https://hamstergene.github.io/post/editing-osx-login-items-cmdline/
- http://hints.macworld.com/article.php?story=20111226075701552


Snoop new processes as they are executed, ``creatbyproc.d`` for files::

sudo newproc.d
sudo creatbyproc.d


List memory usage in real time::

sudo fs_usage | grep -v 0.0000


Force flush cached memory::

sudo sync && sudo purge


Enable/disable swapping in Mac OS X (not checked solution)::

# to disable swap (pager daemon)
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

# after stopping pager daemon, you may want to remove swapfiles
sudo rm /private/var/vm/swapfile*

# to enable swap, you need to boot in Single Mode (Hold [CMD + S] at booting time) and run this command:
sudo launchctl load /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist


Remove RecoveryHD partition::

diskutil list
diskutil eraseVolume HFS+ Blank /dev/<RecoveryHD_ID>
diskutil mergePartitions HFS+ <nameOfMainDisk> <mainDisk_ID> <RecoveryHD_ID>


List of users (with information)::

dscacheutil -q user
Expand Down Expand Up @@ -133,7 +174,7 @@ Create user agent::
# drwxr-xr-x 3 spider staff 102 Apr 28 16:46 LaunchAgents


Disabled jobs are stored in ``/var/db/com.apple.xpc
Disabled jobs are stored in ``/var/db/com.apple.xpc``

::

Expand Down
126 changes: 126 additions & 0 deletions MacOS/mac_programming.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ AppleScript Programming/System Events

https://en.wikibooks.org/wiki/AppleScript_Programming/System_Events

Loop (repeat) - http://alvinalexander.com/apple/applescript-for-loop-while-loop-examples


Show all processes of application::

tell application "Finder"
set l to get name of every process

repeat with i in l
log i
end repeat
end tell


Pass command-line arguments to AppleScript ``osascript script.scpt hello world``. ``script.scpt``::

Expand All @@ -15,6 +28,119 @@ Pass command-line arguments to AppleScript ``osascript script.scpt hello world``
end run


Debug UI elements (dirty)::

#!/usr/bin/osascript

tell application "Messages"
activate
end tell

tell application "System Events"
get properties
if UI elements enabled then
tell process "Messages"

set t1 to get every UI element
log t1 & "\n"

tell window "Messages"
set t1 to get every UI element
log t1 & "\n"

tell sheet 1
set t1 to get every UI element
log "get every UI element"
log t1 & "\n"

tell scroll area 1
set t1 to get every UI element
log "get every UI element"
log t1 & "\n"

tell UI element 1
set t1 to get every UI element
log "get every UI element"
log t1 & "\n"

tell group 1
set t1 to get every UI element
log "get every UI element"
log t1 & "\n"

tell group 2
set t1 to get every UI element
log "get every UI element"
log t1 & "\n"

tell static text "Apple ID Locked"
if not (exists) then
log "FALSE"
else
log "TRUE"
end if

end tell

end tell

end tell

end tell

set t1 to get every button
log t1 & ".\n"
end tell

set t1 to get every static text
log t1 & "\n"
end tell

set t1 to get every button
log t1 & "\n"

set t1 to get properties of every button
log t1 & "\n"

set t1 to get every UI element of every button
log t1 & "\n"

set t1 to get every static text
log t1 & "\n"

set t1 to get properties of every static text
log t1 & "\n"

set t1 to get every UI element of every static text
log t1 & "\n"

set t1 to get every scroll bar
log t1 & "\n"

get properties of every scroll bar
get every UI element of every scroll bar

(*get every UI element ¬
whose class is not button and class is not static text ¬
and class is not scroll bar
get properties of every UI element ¬
whose class is not button and class is not static text ¬
and class is not scroll bar*)

end tell

end tell
else
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
end tell
end if
end tell



::

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID ${uid}
Expand Down
11 changes: 11 additions & 0 deletions OpenVPN.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=======
OpenVPN
=======

Configuration
-------------

Server config::

# Allow multiple user connections
duplicate-cn
18 changes: 15 additions & 3 deletions bash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ BASH
====


http://talk.jpnc.info/bash_lfnw_2017.pdf


Bash get last line from a variable::

echo "${VAR##*$'\n'}"


Is file exist::

if [ ! -f /tmp/foo.txt ]; then
echo "File not found!"
fi


Functions on BASH::

#!/bin/sh
Expand Down Expand Up @@ -68,9 +83,6 @@ Multiline file creating::
EOF


::


Make sure only root can run our script::

if [[ $EUID -ne 0 ]]; then
Expand Down
3 changes: 3 additions & 0 deletions git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Git

https://git-scm.com/book/ru/v2


Delete credentials from GIT repository [rus] - https://the-bosha.ru/2016/07/01/udaliaem-sluchaino-zakomichennye-privatnye-dannye-iz-git-repozitoriia/

Force “git pull” to overwrite local files::

# Downloads the latest from remote without trying to merge or rebase anything
Expand Down
13 changes: 13 additions & 0 deletions linux_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
Linux commands
==============

Empty pagecache, dentries and inodes::

# run as root
free -h && sync && echo 3 > /proc/sys/vm/drop_caches && free -h


Flush swap::

# run as root
swapoff -a && swapon -a



Show count of processes of some user::

ps aux | awk '{print $1}' | grep <user> | wc -l
Expand Down
11 changes: 7 additions & 4 deletions nano.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
nano
====

Find+replace in **nano** press next combination::

[Ctrl]+[\]
Enter your search term [return]
Enter your replacement term [return]
[A] # to replace all instances


Show line nums - CTRL+C (without dynamic change), or::
Show line nums - ``[CTRL]+[C]`` (without dynamic change), or::

nano -c <file>


Thus to display line numbers always when using nano::

nano ~/.nanorc
set const

echo 'set const' >> ~/.nanorc
2 changes: 2 additions & 0 deletions vmware.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ VMWare command line
# set VM state to a snapshot
vmrun revertToSnapshot <path_to.vmx> <snapshot_name>

# remove a snapshot from a VM
vmrun deleteSnapshot <path_to.vmx> <snapshot_name> [andDeleteChildren]


8 changes: 8 additions & 0 deletions zabbix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ https://www.zabbix.com/documentation/3.0/ru/manual/encryption/using_pre_shared_k
- Configure host in Zabbix-server to use PSK. Need to wait some time, before Zabbix cache update.


Zabbix server 3.2
-----------------

Configuration
^^^^^^^^^^^^^

``/usr/share/zabbix/conf/zabbix.conf.php``



Zabbix agent 3.0
Expand Down

0 comments on commit c4f4128

Please sign in to comment.