Skip to content

Instantly share code, notes, and snippets.

View Daemonslayer2048's full-sized avatar

Jacob Hanafin Daemonslayer2048

View GitHub Profile
@Daemonslayer2048
Daemonslayer2048 / Restart.md
Created November 12, 2020 16:17
Restart Salt Minion Without Losing It

Simply running 'systemctl restart salt-minion' using the cmd.run module will cause the service to hang on the restart process.
The below command allows the restart signal to be detached from the service, preventing the hang

sudo salt Minion-Id at.at 'now +5 minutes' 'systemctl restart salt-minion'
# Mount your USB
mkdir /tmp/usb
mount *your usb*
cd /tmp/usb
# As we speak latest version is apk-tools-static-2.9.1-r0. If you get 404 you will need to change it with actual version.
wget http://uk.alpinelinux.org/alpine/latest-stable/main/aarch64/apk-tools-static-2.9.1-r0.apk
tar -xzf apk-tools-static-*.apk
# Pulling the "stage3" binaries;
@Daemonslayer2048
Daemonslayer2048 / .bashrc
Created March 17, 2020 03:06
how to tar/zip/untar/unzip
# function for .bashrc to facilitate (extraction of archive|archiving of file)
# extract based on the file extension.
function extract(){
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
@Daemonslayer2048
Daemonslayer2048 / null.sls
Last active June 11, 2019 13:33
A Note on Managing Service Files0 #Salt
service.systemctl_reload:
module.run:
- onchanges:
- file: /a/cron/file
cron:
service.running:
- enable: True
- reload: True
@Daemonslayer2048
Daemonslayer2048 / null.sls
Last active June 11, 2019 13:28
Basic salt commands to not forget #Salt
### Check output of jid
salt-run jobs.lookup_jid 20190605082230924924
### Get list of connected minions
salt-run manage.up ES/remmina.mo
@Daemonslayer2048
Daemonslayer2048 / null.py
Last active June 11, 2019 13:29
For loops with example list #Python
import subprocess
times = ["13:00", "13:52"]
for time in times:
subprocess.call('echo "touch /home/jhanafin/IAmAlive.txt" | at ' + time, shell=True)õ
@Daemonslayer2048
Daemonslayer2048 / null.py
Last active June 11, 2019 13:29
Reading output from subprocess.Popen #Python
def clear_schedule():
output = subprocess.Popen(['atq'], stdout=subprocess.PIPE, shell=True)
queue = output.communicate()[0].decode('utf-8')
for job in queue.splitlines():
qid = job.split('\t', 1)[0]
print (qid)
@Daemonslayer2048
Daemonslayer2048 / null.py
Last active June 11, 2019 13:29
Pulling XML from URL #Python
from xml.dom import minidom
from urllib.request import urlopen
import requests
url = 'http://c.speedtest.net/speedtest-servers-static.php'
xmldoc = minidom.parse(urlopen(url))
itemlist = xmldoc.getElementsByTagName('server')
@Daemonslayer2048
Daemonslayer2048 / null.py
Last active June 11, 2019 13:29
Parsing Ugly XML #Python
First a sample XML snippet
``` XML
<settings>
<servers>
<server url="http://speedtest.oppinord.no/speedtest/upload.php" lat="70.6632" lon="23.6817" name="Hammerfest" country="Norway" cc="NO" sponsor="Hammerfest Energi Bredbånd AS" id="21239" host="speedtest.oppinord.no:8080"/>
<server url="http://88.84.191.230/speedtest/upload.php" lat="70.0733" lon="29.7497" name="Vadso" country="Norway" cc="NO" sponsor="Varanger KraftUtvikling AS" id="4600" url2="http://speedmonster.varangerbynett.no/speedtest/upload.php" host="88.84.191.230:8080"/>
</servers>
</settings>
```
Assuming this is a file named ookla.xml. The following code will print the number of "server" tags that exist and print all ID's.