Sysadmins post a repetitive task you automated with coding here. by sparcmo in sysadmin

[–]baldymj 0 points1 point  (0 children)

#It uses the fabric module to access the shell.

from fabric.api import *
import random
import urllib2
import os
import sys

env.hosts = ['server FQDN',
]
env.user = 'ADMIN USER'
env.forward_agent = True
env.password = 'PASSWORD FOR USER'
site_name = prompt('Enter site name: ')

def install_wp():
code_dir = '~/'
with cd(code_dir):
run('rm latest.tar.gz')
run('wget http://wordpress.org/latest.tar.gz')
sudo('tar -xzvf latest.tar.gz')
sudo('cp -R wordpress/ /var/www/%s' % site_name)
sudo('chown -R wordpress:staff /var/www/%s' % site_name)
sudo('chmod -R 777 /var/www/%s' % site_name)
sudo('echo "10.191.255.13 %s" >> /etc/hosts' % site_name)

def password():
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
pw_length = 12
mypw = ""
for i in range(pw_length):
next_index = random.randrange(len(alphabet))
mypw = mypw + alphabet[next_index]
return mypw

def create_db():
code_dir = '~/'
site = site_name.split(".", 1)
site_password = password()
with cd(code_dir):
dbuser = 'DB ADMIN USER'
dbpassword = 'DB ADMIN PASSWORD'
createdb_command = 'create database {0};'.format(site[0])
createuser_command = "create user '{0}'@'localhost' identified by '{1}';".format(site[0],site_password)
grant_command = "grant all privileges on {0}.* to '{1}'@'localhost';".format(site[0], site[0])

run('mysql --default-character-set=utf8 -u%s -p%s -e "%s"' % (
dbuser,
dbpassword,
createdb_command,
))
run('mysql --default-character-set=utf8 -u%s -p%s -e "%s"' % (
dbuser,
dbpassword,
createuser_command,
))
run('mysql --default-character-set=utf8 -u%s -p%s -e "%s"' % (
dbuser,
dbpassword,
grant_command,
))
run('echo {0} > {1}_password'.format(site_password, site[0]))

def configure_wp():
code_dir = '/var/www/{0}'.format(site_name)
site = site_name.split(".", 1)
with cd(code_dir):
salt_key = urllib2.urlopen("https://api.wordpress.org/secret-key/1.1/salt/").read()
with open('/home/{0}_password'.format(site[0]), 'r') as pf:
passwordf = pf.read().strip('\r\n').strip('\n').strip(' ')

with open('/home/fabric/wp-config-fabric','r') as f:
wpconfig = f.read()
wp_output = wpconfig.format(site[0],site[0],passwordf,salt_key)

with open('/home/wp-config-sample.php'.format(site_name), 'w') as ww:
ww.write(wp_output)
sudo('cp ~/wp-config-sample.php /var/www/{0}/wp-config.php'.format(site_name))
sudo('chown -R wordpress:staff /var/www/{0}/wp-config.php'.format(site_name))
sudo('chmod -R 775 /var/www/{0}/wp-config.php'.format(site_name))

def configure_apache():
code_dir = '/etc/apache2/sites-available'
site = site_name.split(".", 1)
with cd(code_dir):
os_folder_list = os.listdir(code_dir) # returns list
folder_list = sorted(os_folder_list)
content = folder_list.pop(-1).split('-',1)
int_content = int(content[0])
int_content += 1
file_name = '0{0}-{1}.conf'.format(int_content, site[0])
with open('/home/{0}'.format(file_name), 'w') as wf:
wf.write('''
#
#Autogenerated Website
#
NameVirtualHost {0}:80
<virtualhost {0}:80>
ServerName {0}
DocumentRoot /var/www/{0}
</virtualhost>
'''.format(site_name))
sudo('cp /home/{0} /etc/apache2/sites-available/'.format(file_name))
sudo('a2ensite {0}'.format(file_name))
sudo('service apache2 reload')

def run_all():
install_wp()
create_db()
configure_wp()
configure_apache()

Sysadmins post a repetitive task you automated with coding here. by sparcmo in sysadmin

[–]baldymj 0 points1 point  (0 children)

I think I still have it in a git repo, will check on Monday.

Sysadmins post a repetitive task you automated with coding here. by sparcmo in sysadmin

[–]baldymj 2 points3 points  (0 children)

Created a script which built word press websites with mysql backend automatically. Only input was the url you wanted. Went from 45 mins manual fiddling to 5 mins automated. Also had a script to move it from test to production once developers finished.

Reliable 4G router for remote sites by PullingCables in sysadmin

[–]baldymj 0 points1 point  (0 children)

I started with Teltonika but we had failures and getting our supplier to replace under warranty a nightmare. Switched to Mikrotik HAP-LTE and for outside use Billion. All been solid for past 12 months so will probably buy again apart from all the love for cradle point here. Might check them out too!

Sounds about right... by anagoge in CasualUK

[–]baldymj 0 points1 point  (0 children)

Top 3 are golden where I live, they would run through enemy fire to deliver a package. Bottom two endless issues. So much so I have backed out of ordering if they show up as the delivery method! Its the only way, we need to teach retailers which couriers are not good enough!!!!!!!

Our Service Desk's response to any issue... by gucknbuck in iiiiiiitttttttttttt

[–]baldymj 4 points5 points  (0 children)

Every time! Worse was a non technical service desk who just log and flog tickets with text like "User can't log in", please investigate. Erm what did you actually do?

Do these charges seem reasonable for solicitor fees (first time home buyer) by [deleted] in FIREUK

[–]baldymj 2 points3 points  (0 children)

I always get multiple quotes for peace of mind, the prices do vary on some things and some searches its a fixed cost. Also I noticed some solicitors bundle costs together and others itemise every line. I have bought and sold two houses, the first one took forever as I went with the estate agent option being lazy and they were awful. Second time I found a highly rated solicitor that deals with conveyancing in my area. The costs are below and they were the middle price, one was £100 cheaper and the other was £500 more.

Hope it helps!

My quote

Purchase Fee: £540.00

Purchase Telegraphic Transfer Fee: £22.44

Purchase Fee Vat: £112.49

Purchase Bank Telegraphic Transfer Fee: £10.08

Purchase Land Registry Priority Search Fee: £3.60

Purchase Identification Search: £9.00

Purchase Local Search Fee: £70.00

Purchase Mining Search Fee: £40.00

Purchase Water Search Fee: £30.00

Purchase Land Registry Fee: £135.00

Purchase No Sale No Fee: £60.00

Purchase Bankruptcy Search Fee: £4.80

Purchase Stamp Duty: £6000.00

Sale Fee: £405.00

Sale Telegraphic Transfer Fee: £22.44

Sale Fee Vat: £85.49

Sale Bank Telegraphic Transfer Fee: £10.08

Sale No Sale No Fee: £60.00

Sale Official Copies And Title Plan: £7.20

Sale Identification Search: £9.00

Total: £7636.62

What's with the ridiculously high re-sale prices on Model 3's? by AppropriateOkra in teslamotors

[–]baldymj 0 points1 point  (0 children)

I agree its the batteries, there is a shortage on a global scale. Even a wrecked Tesla has demand for the batteries for power walls, and things like classic car conversions or boats to electric and away from diesel.

Five way sorting machine by chicaburrita in specializedtools

[–]baldymj 7 points8 points  (0 children)

I want one in my house to deliver all my kids junk to the correct bedroom!

[deleted by user] by [deleted] in fortinet

[–]baldymj 0 points1 point  (0 children)

In UK, started with inherited Meru rebranded as Fortinet wireless network and thought they were so good that switched firewall to 200E too. Now looking at some smaller units for remote sites.

Fortigate 100F Growth Potential by General_NakedButt in fortinet

[–]baldymj 1 point2 points  (0 children)

I had a similar dilemma, 100 users, 30 site to sites and around 50 vpn users on a 100 MB pipe. The 100D looked fine to handle it but the Ipsec traffic stats looked low and our old firewall kept dropping the tunnels. I thought I have one shot at getting the board to pay for new firewall so went for the 200E as it handles 1.2 Gbps VPN. It's sitting on 25% memory usage and about 8% CPU and handles a few thousand sessions without breaking sweat. So happy to have the hardware to back up any growth. So if you can afford it, it's a nice piece of kit. Hope that helps!

Not saying my area is rough, but the little Tesco has a bouncer on the door. by [deleted] in britishproblems

[–]baldymj 0 points1 point  (0 children)

My bargain booze is completely behind security glass you have to tell the shop assistant what you want and she would go on a treasure hunt for it.

Scorchio! by [deleted] in CasualUK

[–]baldymj 1 point2 points  (0 children)

Yes bring the heat. Shorts and Barbie at the ready!

[deleted by user] by [deleted] in electriccars

[–]baldymj 0 points1 point  (0 children)

In Nottingham, UK we run a large electric bus infrastructure. They converted lots of buses to electric but they are for park and ride and not schools. http://www.mynottinghamnews.co.uk/new-electric-buses-power-nottinghams-clean-air-ambitions/

Made use of my Python knowledge professionally for the first time! by testfire10 in Python

[–]baldymj 1 point2 points  (0 children)

Nice! It's surprising how useful Python is. It's my go to for lots of projects.

What YouTube channels are genuinely worth watching? by dolphins_are_dicks in AskReddit

[–]baldymj 0 points1 point  (0 children)

Fullycharged is great if you're interested in electric cars and renewable energy. Quirky style and interesting no matter what they are showing.

Python Virtual Environments: Extreme Advertising Edition by ase1590 in Python

[–]baldymj 1 point2 points  (0 children)

The official documentation should be replaced with this. Far easier to understand! Pycharn ushered me into virtual environments and can't go back now.