Go to file
2023-08-26 08:54:49 +03:00
cronutil add cronutil 2021-06-24 18:30:44 +03:00
.gitignore Initial commit 2021-06-14 08:50:35 +03:00
build-python.sh change shebang 2023-05-01 17:04:10 +03:00
LICENSE Initial commit 2021-06-14 08:50:35 +03:00
README.md removed confutil.py 2023-08-26 08:54:49 +03:00
sendmail.py add checking the connection 2021-12-19 17:51:07 +03:00
simplewc.py add support dns.he.net 2022-04-19 17:06:52 +03:00

utils

Small tools needed to solve immediate tasks independently or as part of a project


build-python.sh

Description:

Building Python from sources.

Dependencies:

POSITION PARAMETERS DESCRIPTION DEFAULT
1 [qn] execution without pauses
2 [version] version of Python 3.9.5
3 [path/to/log] path to log /dev/null

Example usage in terminal with make the script executable:

wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/build-python.sh
chmod u+x ./build-python.sh
sudo ./build-python.sh - 3.9.5

Example usage in terminal without download:

sudo su - -c "bash <(curl -s https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/build-python.sh) qn 3.9.5 install-python.log"

cronutil

Description:

Control wrapper for the schedule package.

Dependencies:

Scheduler works only on a weekly scale. This is due to the use of the schedule package.
Target format: wD:HH:MM:SS, where:

wD - day of week unit: '1', '2', ... , '6', '7', '*'
HH - hour unit in 24-hours format: '00', '01', ... , '22', '23', '**'
MM - minute unit: '00', '01', ... , '58', '59', '**'
SS - second unit: '00', '01', ... , '58', '59', '**'

Units can be listed separated by commas. Examples:

'*:**:**:**' - every second of every minute of every hour of every day
'*:**:**:*5' - every 05,15,25,35,45,55 seconds of every minute of every hour of every day
'*:2*:**:**' - every second of every minute of every 20,21,22,23 hours of every day
'*:2*:**:*5' - every 05,15,25,35,45,55 seconds of every minute of every 20,21,22,23 hours of every day
'3,5:2*:**:*5' - every 05,15,25,35,45,55 seconds every minute every 20,21,22,23 hours of Wednesday, Friday
'1,7:12:00:**' - every second 00 minutes 12 hours of Monday, Sunday
'1:07:00:00' - every 00 seconds 00 minutes 07 hours Monday

Example usage in Python:

from time import strftime
from cronutil import Scheduler


def now():
    print(strftime('%Y.%m.%d %H:%M:%S'))


cron = Scheduler()
cron.add('2,4:**:*0:00,15,30,45', now)
cron.start()
cron.add('2,4:**:59:59', cron.stop)

sendmail.py

Description:

Sending email from Python.

Dependencies:

PARAMETERS DESCRIPTION DEFAULT
-u, --user smtp valid user REQUIRED
-p, --pass smtp valid password REQUIRED
-d, --dest destination addresses REQUIRED
[-h] print help and exit
[--smtp] smtp hostname or ip address smtp.gmail.com
[--port] smtp port number 587
[--stls] smtp required TLS True
[--from] mail from alias --user value
[--subj] mail subject 'no subject'
[--text] mail body text 'no text'
[--type] mail body type: plain, html plain
[--file] mail attachment files None
[--time] minutes of attempts to send 3

Example usage in terminal:

# download
sudo wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/sendmail.py -O /usr/local/bin/sendmail.py
sudo chmod +x /usr/local/bin/sendmail.py
# example 1
sendmail.py -u user@gmail.com -p pass -d addr1@gmail.com,addr2@gmail.com
# example 2
/usr/local/opt/python-3.9/bin/python3.9 /usr/local/bin/sendmail.py -u user@gmail.com -p pass -d addr1@gmail.com,addr2@gmail.com --file "/path/to/file1,/path/to/file2"

Example usage in Python:

from sendmail import Mail

msg = Mail(smtp_user='user@gmail.com', smtp_pass='pass', mail_dest='addr1@gmail.com,addr2@gmail.com')
log = msg.send()
print(log)

simplewc.py

Description:

Update Let's Encrypt wildcard certificate with DNS-01 challenge.

Dependencies:

PARAMETERS DESCRIPTION DEFAULT
--domain domain for which the wildcard certificate is issued REQUIRED
--server master server containing the domain zone REQUIRED
--keyname name of the key to update the zone REQUIRED
--keydata content of the key to update the zone REQUIRED
[-h] print help and exit
[--acmepath] alternative path to bin (example: ~/.acme.sh/acme.sh) None
[--force] "force" argument for the acme.sh False
[--test] "test" argument for the acme.sh False

Example usage in cron with Python:

# at 00:00 on Monday
0 0 * * 1 /usr/bin/python3 ~/simplewc.py --domain EXAMPLE.COM --server 8.8.8.8 --keyname KEY --keydata YOU_KEY_CONTENT > /dev/null
# 00:00 on day-of-month 1 and 15
0 0 1,15 * * /usr/bin/python3 ~/simplewc.py --domain EXAMPLE.COM --server dyn.dns.he.net --keyname - --keydata YOU_DDNSKEY > /dev/null

Example usage in terminal with make the script executable:

chmod u+x ./simplewc.py
./simplewc.py --domain EXAMPLE.COM --server 8.8.8.8 --keyname KEY --keydata YOU_KEY_CONTENT --test --force
./simplewc.py --domain EXAMPLE.COM --server dyn.dns.he.net --keyname - --keydata YOU_DDNSKEY --test --force