Wednesday, August 30, 2017

DavMail, Thunderbird and Systemd..

So I can't recall if I posted about this or not but since switching full time to Fedora I've had to get creative with email clients.  Since Evolution is clunky and rather ugly I decided to brave the DavMail world with Thunderbird.

Now for quite a while I've been suffering through DavMail just quitting on me.  Nothing gets logged anywhere, the pid just dies. However today in #systemadmins I tossed out a question and it was fielded by a guy who I'd consider quite the senior in the whole *nix/SysAdmin world.  Due took less than 20 minutes and had me a working systemd.service file that will run automagically and restart if it happens to die, oh and get this.. it will LOG too! *giggle*

Here's the file for those interested:

[Unit]
Description=DavMail Exchange Gateway
Requires=network.target
After=network.target
[Service]
Type=simple
RemainAfterExit=no
#ExecStart=/usr/bin/davmail /etc/conf.d/davmail.properties
#ExecStop=killall davmail
Environment=BASE=/path/to/davmail-linux-x86_64-4.8.0-2479/
Environment=PROPERTIES=/path/to/.davmail.properties
ExecStartPre=/usr/bin/bash -c "for i in $BASE/lib/*; do /usr/bin/systemctl set-environment CLASSPATH=${CLASSPATH}:$i ; done"
ExecStart=/usr/bin/java -Xms1G -Xmx1G -Djava.awt.headless=true -XX:ErrorFile=/tmp/davmail_errors.log -XX:-HeapDumpOnOutOfMemoryError -Dsun.net.inetaddr.ttl=60 -cp ${BASE}/davmail.jar:${CLASSPATH} davmail.DavGateway ${PROPERTIES}
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target



Wednesday, July 26, 2017

Python 3 + Paramiko UPDATE

I can hear the voice over from Unreal Tournament. back in the day, "MU MU MU MULTIKILL!"

I figured out the correct syntax for my SSH/paramiko script thus completing my second actual Python script.  WOOT. (With vast amounts of help from the guys in an IRC channel I frequent)

So my hangup on all of this boiled down to trying to use a Python2 command in Python3.. Ok well two instances of that: raw_input() was changed to just input().  And my print stdout() should have been print(stdout.read())
Once I got those values changed she ran like a well-oiled machine.  Here's what I've been working on:


import sys, paramiko, getpass


user = input("Username:") #Prompts for username#passwd = getpass.
getpass("Password for " + user + ":") #Prompts for password
key_file = input("Publickey full path:") #Prompts for full path to 
key file
name = input("Target Hostname:") #Prompt for target 
hostnamec
command = input("Enter target command:") #Prompt for 
remote command

#Calling the paramiko ssh function
ssh = paramiko.SSHClient() 
#Define value 'ssh' as calling the paramiko.sshclient
print('calling paramiko')ssh.set_missing_host_key_policy(paramiko.
AutoAddPolicy()) #Must come before connect line to add hosts 
to known_hosts#ssh.connect("name", username="user",
password="passwd")
ssh.connect(hostname = name, username = user, key_filename = 
key_file) # key_filename means to specify, 
pkey on the#other hand means to actually paste in the key text 
itself 
print('trying to connect')
ssh.invoke_shell()
stdin, stdout, stderr = ssh.exec_command (command)
print(stdout.read())
#ssh.close()

I will keep this, if anything as a paramiko snippet.  It works, it shows me how to SSH into a remote host and run a command.  At this early stage, I can't ask for much more.

Tuesday, July 25, 2017

Python + Paramiko = SSH unhappiness :(

Been reading the book, watching random YouTube videos on Python.. reading articles and blog posts. Figure one of the best ways to learn something is by doing, so I thought and thought and what's one of the most used parts of a script?

Connecting to a remote machine!

So I went with Paramiko as it seems to be the defacto SSHing inside Python .. thing.  Following examples is still tricky.  I created a new EC2 instance for this.. churned out a short script or snippet as I like to call it.  A paramiko_snippet on using the SSH client but am having issues sending remote commands.

I can connect, and invoke_shell() returns an active channel so I'm good there.

But when sending commands, 'channel.send('command')' returns nothing but a number.. in this case a 2.. next time I ran it gave me a 3.

Maybe it's some Python 2 versus 3 issue.  It's not clear yet, but my Google-Fu is strong and I will figure it out.

channel.send('ls')
2
channel.send('ls\n')
3

Thursday, July 13, 2017

Learning Python!

It's been a while since my last post.  Just been horribly busy with work and home stuff, and being in Montana it's damn hard to stay indoors!

Anyway for the past three weeks I've devoted myself to picking up a working knowledge of Python.  So far I like it!

The IRC channel I frequent is chock full of current|ex Amazon folks, Expedia, Disney, Mojo and a few other places that I'd consider 'Enterprise' level.  More than one handful of devops live in this channel so under a few actual, real DevOps Engineers I chose to start this adventure off with a book;

Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic.

It' easy to read and follow.  I typically read some while at lunch and spend nights watching the Udemy videos that follow 'Automate The Boring Stuff with Python'.  Once the Udemy videos are done I'm considering paying for a month of Lynda.com and checking out what they have.

In any case, why did I start this? After doing the whole sysadmin thing for almost 15 years I'm feeling stagnant.  I mean sure every time you change employers or introduce some new application you are learning new things.  And while I don't want to switch paths straight into development, I do really enjoy pulling together some code and forming something new with it.

Also under advisement from the crew I chose PyCharm as an IDE.  Absolutely love it!  Very intuitive, helpful, and damn easy to learn.  Discovered virtenv's the other day and last week I wrote my first actual script and used it at work!

Anyway I've got my eyes set on a new price in town which would come with a new title.  We'll see.

Thursday, May 25, 2017

Powershell Script: Remove Windows 10 Apps

Tired of all the bullshit apps that Microsoft bundles with Windows 10?  I know I am!

This is just a combination of the same stuff that can be found on MANY websites out there.  I just didn't want to create 15 individual .ps1's or copy/paste as many times.




Get-AppxPackage *xboxapp* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *soundrecorder* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *bingsports* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *windowsphone* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *people* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *onenote* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *bingnews* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *zunevideo* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *bingfinance* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *solitairecollection* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *windowsmaps* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *zunemusic* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *getstarted* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *skypeapp* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *officehub* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *windowscommunicationsapps* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *3dbuilder* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *feedback* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *bamboo* | Remove-AppxPackage
[void](Read-Host 'Press Enter to continue…'); Get-AppxPackage *eclipse* | Remove-AppxPackage



Feel free to pretty up the "Press Enter to continue..."