Sunday, December 29, 2019

Razer Blade Pro 2017

One of the laptops in my house is a Razer Blade Pro. While some may find it a good laptop, I have found it a complete headache. Here's a few of the problems we have had with it.

The first thing to go on the laptop was the batter. It swelled up and bent the case out of shape. After getting that replaced, the next thing to go on the laptop... was the  battery. Yes, it crapped out twice. The second time it was out of warranty, so instead we bought a third party replacement. It never worked quite right as it never fully charges even after calibrating it. After looking around online, this appears to be a common problem. Most people attribute it to the heat.

The laptop itself had been quite buggy, often having issues if you try to take advantage of the 4k screen. Most games had to be ran in HD because 4k would either cause things to crash or just never run. Windows 10 also never really seems to be happy, but that may just be the Windows default nowadays.

Recently the laptop was randomly cutting power. After lots of software tweaking, we noticed that the GPU temperature would shoot up almost instantly the second you launched a game. While I expect an increase in heat, the speed it would ramp up had me worried. So being an IT person, I say take it apart and maybe we will find something with the cooling loose. Right now the laptop is still apart because the design of this thing is terrible.

So first we open it up and everything looks fine, but we can't see much. So I say let's take the motherboard out and flip it over so we can see the heatsink better. Almost done and a piece of plastic comes out. It is the locking piece for a flexible connector. Figure whatever, I'll try to fix that later. Now this thing actually had a lot of these cables and they were small with no tabs to hold to manipulate them. After we get it apart, I realized just how bad it was.

Identifying what was what was a bit difficult, but from what I can tell, the heatsink is limited to the CPU and GPU, however it does not appear to extend to any of the chips. I do not know if there is a distinct north bridge on it, but a large cluster of chips in a position that would make sense for a north bridge are right on a spot where the case would get extremely hot. There was nothing there, not even a passive cooling heatsink. I also found a spot on the copper that had a crimp in it and what looks like a weld. I cannot tell if that is supposed to be there, but it is messy. Furthermore, the copper was rather strange looking, like there was some chemical spilled on it causing distorted colors and a couple of pits. I honestly have no guess as to what they did to it, but it looks damaged.

So after all that frustration, I decide to try putting it back together, but take the thermal pad thing on the one PCIE NVME drives and put it on that cluster of chips that seem to be getting really hot. So there I am putting it back together when I realize the button for the track pad is screwed to the motherboard. I have no idea why, but I need to take it off so I can lift up the motherboard to get one of the numerous tiny flex cables connected. I get the cable in, push the plastic lock down... and it came off. So now there are two broken. One for the power button and one for the track pad to click.

I also would like to mention that the RAM is soldered on, not a design feature I like or support.

This laptop has a crappy battery, a very minimal cooling system, soldered on non-upgradable RAM, a lot of crappy tiny flex cables, and it seems to just eat itself up.

Saturday, December 28, 2019

My First WoW Addon

Recently I have been playing a lot of World of Warcraft Classic. Something about the game design back then just felt a lot better. I originally started playing during the Burning Crusades expansion, so this is my first time playing something closer to the original design. Despite this, some modern conveniences were put in there for a reason and I got used to some of them. As a result, I turned to the wild world of Add-Ons. I had a lot for what I needed, however there was one thing that was really getting annoying. Whenever I tried to do something as my Shaman in Ghost Wold form, I got told I cannot do it while shapeshifted. All the Add-Ons I found revolved around being mounted or taxied. So I figured I should make my own.

Rather than start from scratch, I decided to check out how a couple other similar ones were made. The first thing I noticed was it was actually fairly small. In fact, checking out a few others showed me just how extensive the interface for Add-Ons was when most things were fairly trivial.

Before pushing everything in to full swing, I decided to look for a good development environment. I had not done much with Lua and tend to not work on too many files at once, usually it is just a single file in Vim with tmux going and so I have a window to run it on. My search led me to WowAddonStudio. I had to download the old 2015 version of Visual Studio, but that was not that big of a deal. Since it was me just starting out, I wanted to see how it would build an Add-On and compare it to how others had built theirs.

After starting up a blank Add-On, I then compared between two others that did something similar. As per my usual, the style and methodology of each made them a little annoying to deal with. Programming in Haskell has led me to see some things as quite ugly, and programming in Python has led me to dislike code that seems unnecessarily obfuscated. So taking a little from each, comparing, and mashing them together, I made my first Add-On for WoW that probably needs some more stuff added. Granted I tried it with my Shaman but did not have a Druid to compare and see if it interfered or interacted with that at all, and I assume it will.

ClassicICantCast

I still have a lot of reading to find out just exactly what all the numbers mean and all that and just made a little dummy Add-On for myself to modify for the sake of dumping data on events. It's not much, but I think it's a start to get back into programming and maybe even take some things a little more seriously.

Saturday, December 14, 2019

Techs from the Crypt: Job Interview Gone Wrong

I was debating for a short while whether to write this or not as it was fairly recent. Obviously my decision is to write it. Now usually I get on with people just fine and working retail I tend to stay in a neutral position and let others steer the conversation. I know there are some personality types I just don't get along with and admit it is a problem with myself to a degree. Unfortunately it seems to be fairly common among the tech savvy areas of things. I go along the philosophy of if it works for what I need, I go with it unless there is a reason not to. So most of the tech in my house ends up with some odd hack or it is just sort of there without much fine tuning because I have no reason to. Quite a lot of tech people I seem to run into are the kinds who... their way is the right way and if there's a problem they see, even if it's not a problem, you should just do what they say because they know best. What does this have to do with a job interview? Well, I recently had a job interview where I almost hung up on the person because they were everything I dislike about certain IT people.

So on LinkedIn I get a message about a position. It looked automated with some grammatical errors, but I've learned to take chances and just go for anything because you never know what door could open for you. I say that I'm interested and get a request for a number and a good time to chat about the position. I give my cell and say afternoon. Perhaps that was an error on my part, but by afternoon I mean 12pm to 1pm because that's what I always heard it for growing up in upstate NY. Generally up there we considered after 3 to enter into the evening, so I expected at the latest sometime before 3 I would get the call.

The time came and past (me on lunch), so I forgot about it and was driving home from work. Around 3.40pm and I get the call. I don't have Bluetooth or anything for my car because I keep things relatively downgraded miss it. When I get home, it's a message from the guy asking to either talk or schedule a time to talk. I thought we did schedule it, but like I said afternoon but some people that means something different.

I call him back and we start to talk. I explain a bit about what I do and why I may be looking for a better opportunity which usually gets a good response, but it fell flat. I may have misread because I just took some extra strength Dayquil to keep a head cold at bay. I chalk it up to that in my head and move on. A few oddities stuck out to me in the conversation.

The first was related to hard drives. He asked about regular and solid state so I gave the spiel about the differences and using SSD to boot with HDD for storage for speed and savings on storage capacity. He then asked about M.2, which I'm bad with names of stuff. Tell him I can't remember and when he mentioned what it is the alphabet soup of PCIE NVME came to mind and I remembered because I just bought my first laptop with that kind of storage. So I chime in and mention that yes I actually have a couple of laptops at home with those kinds of storage and it's my first time using them. He asked about what they use at the school system I work at and I tell him mostly HDD because it's relatively cheap storage and there are a few SSD to boot from on some machines. I get told by him that no new servers have regular HDD because the speed is too slow and at the very least they get SSD for cost effectiveness. He then asks why we have HDD and I explain we are a public school system, we don't have the money to be cutting edge. In the back of my mind I'm wondering where he's been because HDD are still in wide use, still manufactured, and very common. Last I knew a lot of places aim for large storage with redundancy for the best value possible. I shake that off and just assume maybe he's more of the high-end side of things.

The next thing to stand out was when we started talking about Internet speeds and stuff. I know enough networking to get me by in most situations, but I don't do it on a daily basis so I can take a moment to remember things. He asked about my plan and all that and I tell him right now I have a 30 up 10 down. We go for a while and then he goes "Megabytes or Megabits?" I say "Megabits, that's how you measure network speeds." So then he asks me my throughput in megabytes. I tell him I'm not sure off the top of my head, just divide it by 8. He says "yeah, that's right so it's like 2 or something... 2.75." No, it's not but whatever you say. Just for those that don't know, you can estimate with the two closest whole numbers, in which 3*8 is 24 and 4*8 is 32, so it's between 3 and 4. As I said, I was on Dayquil and I also try to be nice and neutral because I worked retail long enough to know how to avoid most arguments.

We continue on, I am starting to get annoyed because the guy keeps either trying to correct me or tell me what the answer is to things I can't remember all the specifics on. Part of my problem is my job is so generalized I can't always shift gears and I'm sure a lot of techs out there know what I'm talking about when the shifts and alphabet soups get confusing after a while.

The questions started getting rather personal and weirded me out a bit, I was wondering if the guy was even being serious at this point. Questions like do I have a lab at my house, what do I do in my free time, what my WAN IP is. I tell him what I'm comfortable with telling him and tell him I do not know my WAN IP.

"Well, are you at your computer?"
No, and it's off right now.
"Well, if you logged into your router, what would it say?"
Well, I have little bit of a weird setup with two routers, the business class Comcast one and my own personal one, so one would be a 10 dot something and the other would be an actual WAN.
"Oh, I see. It's not weird, it's wrong."

At this point, I'm thinking who the hell is this guy? I didn't call him for tech support.

No, it's just a network in a network.
"Yes, it's called a double NAT and that's wrong."
Well, it works for what I need it to and I don't have any problems with it.
"Well, it's wrong. You should put your Comcast router in bridge mode and then it will work right."
I don't have any problems with it and I just go with what works.
"You should listen to me and spend the 20 minutes to put it in bridge mode. I know what I'm talking about, I do this all the time. It would get rid of any weird issues you have with connectivity or VPN."
I haven't had any problems with vpn or connectivity. I'll fix a problem when it becomes a problem.

At this point I honestly wanted to shout a few expletives, tell him to hire an HR or PR guy to talk to people, and hang up on him. I get I do things in ways they might not be done. At work I get keyboards for different chromebooks to connect to other models with some pliers and modify them, doing things not by the books to get the results I want when I want is what I do. I also didn't ask for help with my setup, my setup works for me.

I really did consider just hanging up on him before considering telling him to get some help from an HR or a PR guy to get help talking to people. I opted to finish the call as calmly as I could. After I finished and had some time to think it over, I sent a response on LinkedIn. For your reading pleasure, here's what I said:

I appreciate you taking the time for that interview, but after reflecting upon the conversation, I no longer have interest in a position for your company. The main reason is because your way of talking struck me as a type of person I could not work with or for. I wish you luck with your search.

That was about the best I could think to say because I really wanted to be rude. I'm sure someone may think I am over-reacting or even in the wrong. Maybe I should listen to the high and mighty people who know of problems I don't even know I have. As far as a job interview going wrong, this was a first that went in this sideways direction. I've interviewed with people who have tried to cheat me like a car salesman, people who have no interest, people who think I am clueless, people who right out of the gate feel I have no business getting to that stage of the interview process, but never someone who wants to give me tech support I never asked for.

In reflection as a whole, I am truly growing tired with the stereotypical "IT pros."  My best advice to any IT people would be learn to laugh, shrug things off, and let things go. If you can't, shout them randomly on the Internet, then move on.

Thursday, December 12, 2019

Job Hunting: Interviews Questions of Non-Technical Nature

Recently I went through a job interview process that I was doing great with. The first part I managed to nail it right on the head and move to the second interview phase. The reason I did well on the first interview phase is because it was technical questions and I'm a technical minded person. The second interview I absolutely bombed out because these were the non-technical questions and I am not so good with those. The good news is, I realize my mistakes there and now I'm going to put down what I learned in hopes to do better and possibly help others.

The first question, and one I generally dislike is the obligatory "tell me about yourself." I'm always a blunt person and the truth is, I'm just looking for the next best opportunity and do what I do or what is asked of me. Plain and simple. The problem is, they want an introduction about who you are and what benefits you could offer the employer. A big mistake you can make is to talk too much about yourself with no explanation of what you are offering or the mistake I made, which was to let the interviewer take lead and give an explanation when asked. The reason the second one screwed me over was simply because when the person interviewing saw my resume, he felt I had no relevant experience for that specific type of job and I had no opportunity to say otherwise without rudely  interrupting him. So let me give an example of how I would answer that without being under pressure and having the ability to edit and refine my response because I can do that with a written variation.

"Well, I do a broad range of IT related stuff both at work and personally. I am constantly learning new things whenever I can so I can quickly and adapt to many different jobs by either learning the skills necessary very quickly or I may possibly have pursued the topic or something similar and have some knowledge of what is needed or how to find out more information. I think my wide variety of knowledge puts me in a good position to benefit on jobs that require teamwork with my versatility and at the same time it makes working by myself easier as there are not many situations I come across I don't already have some familiarity to. I also have a strong drive to advance myself and would love to work for a place that offers the opportunities to do so and provide me with new challenges."

The key points to include are selling yourself, showing work ethic, ability to do teamwork and work individually, and of course the company itself. Continuing on, most jobs now seem to have some desire to be all psycho-analytical to make sure you're an actual decent person. I worked in retail a long time and can easily make people find me to be very likeable when I can revolve a conversation around them. When it's flipped... well, I'm really a jerk in person. I don't think I'm that good of a person. That makes these questions a little difficult for me because I often times feel like I'm stretching things too much. The other problem is I always think I have a perfect example but get caught in these "you had to be there to understand" type of situations. Doing these on the spot makes it very challenging, so I'm going to try to remember the questions I was asked and answer them properly here in hopes of giving myself more direction in future encounters. I highly encourage anyone when preparing for an interview to consider these types of questions and maybe write down some talking points that actually work for the situation. This will keep you from cornering yourself.

So one of the questions was to tell him about a time there was conflict between employees and how I resolved it.

"Luckily I have never come across any major conflicts, but I have seen many small conflicts, and regardless of the size of the conflict they can still cause problems. I think a good example would be one that I was involved in as one of three people. I was working in the morning and had a manager come in and tell me about something that was recently changed for how we set up the displays. I followed the managers instructions and everything was fine until the next person came in. I took a lunch break and when I got back she said I had set up the display wrong and that she had fixed it. I told her what the manager told me and she responded by saying while I was on lunch she was told differently. It was a little strange so after some discussion back and forth, I decided the only way we could figure this out was to go straight to the source. We called the manager back, had a quick discussion and found that what he told me was what he wanted us to do and that it was an accident that he told her otherwise. I think most conflicts arise from communication failures. That is why I think for a lot of conflicts in work, simply advising to ask the necessary people is beneficial to remember."

That was after staring at the screen for 15 minutes going through situation after situation. I also tried to set up the expectations that this won't be ground-breaking but still useful. Another question I was asked about was have I ever had conflict with a stakeholder (or manager, etc.) and how did I resolve it.

"I don't believe I've had any real major conflicts with stakeholders. I will lend them whatever advice I can and advise them to the best of my ability, however since it's their stake, whatever they say goes. Throughout my work experience there have been plenty of times where I have questioned a stakeholder's reasons, but I accept that does not mean I am right. I think the best we can do is advise, perform, or step aside."

I find that question particularly hard because I've always simply let things roll off my shoulders that it's not really something that would likely happen. Granted, I'll make jokes about it later. That's about all the ones I remember from that one specific interview. There are still some other more common questions I have down pretty good, but let's run through some.

What goals do you have or where do you see yourself going or where do you want to be?

"I want opportunities to grow and advance. I feel a need to arise to new challenges whenever possible. If I can, I want to just keep climbing and growing. The best part would be to do that with one place, just continually climb the ladder."

What is your greatest strength? For me, this always goes a bit technical.

"Figuring things out. Be it troubleshooting or learning something new, I can do it well. When a problem occurs, I easily can think outside of the box and put something together."

What is your greatest weakness? The trick here is to pull a reversal without anyone really noticing.

"I can over-problem solve. I often times can get too into fixing something where I end up going well outside of the scope I was originally there for. It's a little bit obsessive of me, but I have a hard time saying a problem is solved if there more I can still potentially do."

There are probably more questions I may add in the future, but these work for now.

Thursday, July 25, 2019

Techs from the Crypt: Renovations

So recently at one of my job sites, they are doing major renovations. Part of those renovations is building a man trap entrance in the entrance. There was an office already next to the doors, so they decided to use that as the reception. There wasn't anything that I needed to do, as it was all the job of maintenance and contractors. All the ethernet was already ran to that room.

After being questioned about it, I told them who they needed to talk to and that everything should already be setup. So I figured they could just plug everything in and be ready to go. That was at the beginning of the summer. Now, with school about to start, they were getting everything in place. I got a work order about the internet not working. The setup is a little weird, it goes to a POE phone, then to the computer as a daisy chain. Often times people plug the ports in backwards, so the phone won't get POE and turn on.

So I went to the job site and hooked up the stuff. Nothing. That's a little weird, I thought. So I moved around the connections in the room and over on the switch. Still nothing. So I figure maybe they pulled a connection loose when moving things around.

I get out my network tester and plug it in. It reads 11 feet with no connection. That's a little strange when the cord alone is only 8 feet. So I pull off the plate and pull out the ports. Everything looked secure. This is strange. Sitting back on the floor, I run through the scenario in my head and survey the area.

That's right, they put a window in the wall. They couldn't, could they? In disbelief I grab all the cords and yank them out of the wall.






They cut THROUGH  the cables. They cut through FIVE ethernet cords and said absolutely nothing about it. I don't know which was worse, the fact that it happened or me expecting better of people. Of all the lazy, half-assed, idiotic, and just plain stupid things I've seen done, this is one I won't soon forget. Just the other year we paid a contractor to run those drops, and this year they paid someone to screw it up. Now I have to waste my time because some idiots couldn't be bothered to check before they cut.

A word to anyone in or to be in the IT field, expect stupid. When presented with all options, the dumbest reason is usually the real reason.

Tuesday, May 14, 2019

Asus Router Connection Problems and Possible Fix

I have an Asus RT-AC3100, but this fix may potentially work on other models.

So the symptoms of the problem I was having included:
  • inconsistent pings or unable to ping another device (sometimes it worked if I tried to ping from one and then the other)
  • Network printing drops off
  • inconsistent network discovery if it works at all
  • high latency for simple local pings (like 9-15ms as opposed to 1ms)
  • network map constantly dropping and adding devices as their activity changed
  • inconsistent snmp, sometimes devices not responding for days (I had a few days when the router showed as down, but all my other devices as up, which is impossible to actually happen)
I searched the internet for days trying to find any hints at this, and it was always the same story, upgrade your firmware. Well, I do. I check at least once a month for updates and update, even if I have to upload it manually. So what is the solution I just found? Well, it's dumb and stupid but it looks like it's working.

Solution:

Go into the LAN option under Advanced Settings. Click on the Route tab. Change Enable static route to yes. Then we add a network to it, I'll assume yours is like mine. Under network/host, add 192.168.1.0. Netmask should be 255.255.255.0. Gateway will be the router ip, 192.168.1.1. I just ignored metric and left the interface on LAN. Click the + and then apply. It took my router a moment after rebooting before it went into full swing, but that could have been in part due to this old mac book pro being a bit weird with the network connection in general.

I hope this helps anyone having these issues.

Monday, April 8, 2019

I Can Linux and So Can You (bash commands) pt.3

Previously we worked on viewing and editing files using cat, vi, and sed. Now let's talk about searching and reporting. While it would be simpler and easier to learn Python or Perl for these purposes, we are instead going to discuss grep, awk, and some basic regex. Despite the awkwardness of awk and the accessibility of regex for programming languages like Perl and Python, awk is still utilized by many. Other variations also exist such as gawk (gnu awk) and nawk (new awk), but awk works for both and generally is shipped with the box. So I will stick to that for now. First through, I think a discussion of regex is in order. So buckle up, because it's gonna get bumpy.

Sidebar, you can test these out with grep real quick. Simply do this:

$ echo 'The quick brown fox jumped over the lazy dog.' > test.txt

Then run the regex without the outside slashes like so:

$ grep --color -E 'regex here' test.txt
or
$ egrep --color 'regex here' test.txt

Regular expressions use lots of special syntax for searching and grouping complex text. Often times people will be familiar with some of it due to the commonality of certain methods. I'm sure most are familiar with "wildcards" (*). There are also some different types of regular expressions, but I will try to avoid specific things and keep this as generic as possible. So let's start with a sentence to search.

The quick brown fox jumped over the lazy dog.

Every letter in the alphabet there. Now let's assume we are trying to find this line. Let's work to match as much of this line as possible and cover as much as we can. To encapsulate all of it, I will keep it between two forward slashes because that's commonly how you will come across it. So let's talk about the start of the sentence. That can use a special character, in this case it's ^. There are many special characters ([\^$.|?*+(){}) which to match them litterall requires putting a backslash (\) in front of them. Next we want to match a capital letter. The thing we want is the nested character bracket ([) for this. This allows us to search a grouping of characters in a single position, for example vowels would be [aeiou], capitals would be [A-Z], numbers would be [0-9] or \d, lower case would be [a-z], alphanumeric would be [A-Za-z0-9] or \w. Okay, so let's make magic.

/^[A-Z]/

Okay, that will only match a string that begins with a capital letter. Now let's narrow it a little more. Next we want to match 2 non-space characters and a space. To match a non-space character we use \S and to match spaces (space and tab) is \s or a literal space is a space. Or we can do \w for a word character, or \l for a lower case. So all of these work.

/^[A-Z]\S\S\s/
/^[A-Z]\w\w /
Confused yet? Yeah, it's complicated with many ways to do the same thing, but they are slightly different. Okay, so now let's talk about the next word. It's five lowercase letters. We can do this pretty easy, there's a way to look for a pattern of n length or between n and m characters long. We do something like [a-z]{5} for five characters or something like say... [a-z]{2,5} would be between 2 and 5 characters long. So let's do the 5.

/^[A-Z]\S\w\s[a-z]{5} /

Okay, so now we have the word brown. Let's assume we don't know the length of the word we are matching, just that it's made of word characters. We know it's at least one character long. The plus (+) character comes into play here. A search plus a + will match 1 or more instances of it. So \w+ matches brown, \d+ matches 8675309 or 1.

/^[A-Z]\S\w\s[a-z]{5} \w+/

Can we get more complicated? Yes we can. We know the next word is fox and a space. Let's match literally anything after this of 0 or more characters. For that we use the period (.) which matches one of anything and asterisk (*) which matches 0 or more of the pattern. If you wanted to do one or more, you would do .+ to achieve that. We'll add a space after, so it would either match two spaces or a word followed by a space. The catch is that it will match from the end of brown to the last instance of a space.

/^[A-Z]\S\w\s[a-z]{5} \w+ .* /

Okay, so two things left, the word dog and a period. Let's say we want to match either dog, or cat or neither? Well, we can do one or both. To do or we use the pipe character (|), and to keep it clean we will use a group, which goes in parentheses (()). To match 1 or 0 instances of something, the pattern gets followed by a question mark (?).

/^[A-Z]\S\w\s[a-z]{5} \w+ .* (dog|cat)?/

Okay, the light at the end of this tunnel is near. Or is that a train? No matter, into the breach! The sentence ends in a period. We need to match a period. Two things. First, since the period is a special character we need to escape it with a backslash (\). Second, the end is marked with a dollar sign ($), like in vi and vim.

/^[A-Z]\S\w\s[a-z]{5} \w+ .* (dog|cat)?\.$/

Now look at that. What a mess that is. Obviously we won't often need super complicated stuff like that. There's still a lot more, but this should help get you started. For a better reference you can check out this regex quick reference, and it also goes over the difference in types of regex. If you want a good amount of flexibility, Perl compatible regex is usually the way to go.

So now let's talk commands. Searching and reporting are two things computers should excel at. Most Linux distributions today come with egrep and gawk and there are also counterparts like grep and awk, which they are based on. You can use the -E option with grep or egrep. I suggest using the color option if it's not already aliased on your distribution so you can see what part matches. I'll cover aliases in another portion. The awk and gawk commands are part of a type of programming language made for searching and reporting. Usually you can turn to Perl or another programming language, but awk works for a quick and dirty one-liner.

So let's start with searching. The grep and egrep commands can be used to search files or output of other commands. When you need to narrow your output to a readable level, this will be the go-to. I often times just use grep because I'm just searching for a word and not some expressions, but we'll check out both. I think a good populated folder to use for demonstration will be dev, there are consistencies in there. So let's take a look.

To get an idea of how many files are in dev, take a moment to just look.

$ ls /dev

I'm not going to post mine because that's a long list. Now let's say we are trying to find if a partition exists on our hard drive. Well, it's listed in here. We know our drive is sda, so how do we list all the sda drives? Well, we pipe the output from ls through grep to do a search.

$ ls /dev | grep 'sda'
sda
sda1
sda2
sda3
sda4
sda5
sda6

Cool, so here we see I have 6 partitions (The first three are Windows related, 4 is extended, 5 is kali, and 6 is swap). So let's assume we want to just make a cut-and-paste command to search for hard drives in other older systems. Some use hda instead of sda. Let's also assume we want to check for multiple hard drives, so there could be an sdb or an hdb. Easy.

$ ls /dev | grep -E '^(h|s)d[a-z]'

If we don't include the ^ at the beginning I get watchdog in the result for the hdo part. That's really all there is to it for simple searches of output. We can also search through the files of entire directories with the -r option.

Beyond search filters, it's often necessary to report the findings. Often times that reporting or searching will be useful to dump into an actual readable format. For now, let's use a custom file we will call searchtest.txt, here's what I put in it.

id:title:author
1:The Origins of Modern Science:Herbert Butterfield
2:Catch 22:Joseph Heller
3:1984:George Orwell
4:Animal Farm:George Orwell

I made a column title as well. So let's run a quick search.

$ grep -i 'george' searchtest.txt
3:1984:George Orwell
4:Animal Farm:George Orwell

The -i option tells it to ignore the case. Now this is all fine and dandy, but still a bit difficult to read. So let's clean up the reporting phase using awk. We'll discard the id and just print the title and author.

$ awk -v FS=: '{print $2,$3}' searchtest.txt
title author
The Origins of Modern Science Herbert Butterfield
Catch 22 Joseph Heller
1984 George Orwell
Animal Farm George Orwell

Okay, so we have a lot going on here. We are using -v to set some variables, in this case the Field Separator (FS) from the default of whitespace to colon (:). This allows us to access fields by a dollar sign ($) followed by the place number. In the case of this file, we have $1, $2, and $3. We then have an actual code block where we print fields $2 and $3 separated by the Output Field separator (OFS), which defaults to a space. Okay, this is still messy. We could alter the OFS to make it clearer. There is another method to format your print statements a little better, printf.

$ awk -v FS=: '{printf "%-29s|%s\n", $2, $3}' searchtest.txt
title                        |author
The Origins of Modern Science|Herbert Butterfield
Catch 22                     |Joseph Heller
1984                         |George Orwell
Animal Farm                  |George Orwell

Okay, so now we can actually read it. Here's how the printf is working. The %s is a string we're going to substitute in, in order of the arguments passed to printf. The %-29s is to make sure the string is padded to a length of 29 characters long and the - makes it align to the left, default without the - is to the right. Now let's say we want to not include that first line. We can add a filter for that.

$ awk -v FS=: '/^[0-9]/ {printf "%-29s|%s\n", $2, $3}' searchtest.txt
The Origins of Modern Science|Herbert Butterfield
Catch 22                     |Joseph Heller
1984                         |George Orwell
Animal Farm                  |George Orwell

So there we can see that it accepts a regex filter. You can use this to filter through, select, and print out reports of any text files you have. Learning more about printf will also all you to do a lot of formatting on the reporting as well. The awk and gawk commands happen to be programming languages in themselves as well, but going into all of that detail right now would be lengthy. So for now, let's discuss a bit more for the ins and outs of printf.

The printf function exists in many programming languages and even as a Bash command. You may be wondering what %s means. Well, the % indicates a control and the s indicates a string. In this case, it's printing a string. If you wanted to simply print a percent, you'd have to type %%. You also have %c, which prints a single character ascii decimal value, %d and %i which print numbers, %e and %E print a number in scientific notation, %f and %F for floating point numbers, %g and %G which print in either scientific notation or floating point (whichever takes fewer characters), %o prints numbers in octal, %u prints unsigned integers, and %x and %X print in hexadecimal where %X prints in uppercase and %x uses lower case.

Formatting modifiers can be added to it as well, like the - justifies to the left, default is to the right. A + tells it to print positive or negative signs. A number indicates the space it should use at minimum and a decimal, like 5.2 would indicate a 5 character width with a floating point precision of 2. A leading zero will pad a number with zeros instead of spaces. A # tells it to use an alternate form for certain numbers, like hexadecimal 0x prefix. A ' will print numbers in the thousands to use a comma separator. As you can see, most of the formatting revolves around numbers, but the main thing is setting a width lets you put your output in columns, which can make it easier to read.

So for example, if you did a printf with %07.2 to 12.3, you'd get

0012.30

It's seven characters wide, padded at the beginning with zeros and held to a precision of two.

For now that's enough, next I will cover applying the regex to searching and substituting with vi and sed.

Saturday, April 6, 2019

Job Hunting: Finding a Tech Job, Resume, Cover Letter, and Interviewing

Over time of applying to various jobs, I've slowly refined my Resume, Cover Letter, and Interviewing techniques. I have searched online for how to write and organize everything to do as well as I possibly can, but the problem is that most things I find online are fairly general purpose. Each industry requires a little bit of a different technique, but I also find that depending on your experience and education it can also influence the way you want to write it and present yourself.

So let's start with the resume portion first. A tech resume can be generalized or specialized, but I'd recommend keeping a few copies for specialized cases. For example, if one job puts more emphasis on networking, that should be shown first, whereas another job may want more emphasis on server administration. So let's start with what sections the resume should have.

There should be a technical skills, education, professional experience, references, and a short description of yourself and abilities. Each of these may have different amounts of information and that can influence the order you put everything in. Also, you should try to order information by whats more relevant for the job and leave out any irrelevant fluff. The exception on removing irrelevant information is with previous job experience, feel free to add any jobs you have done to keep at least three. If you don't have any professional experience, there are other things we can do, but let's get to that later.

So at the beginning of your resume, you want to put your name, phone number, email, and address. Following that, you want a little blurb. For this, you want to basically write an advertisement for yourself. I always had difficulty with this because I can be a very blunt person and even more to the point when discussing myself.

Here's the one I use in my current resume for IT Specialist positions:

IT specialist with skills for repair, networking, and administration. Experienced with working across multiple locations and with many people. Great time management and people skills from working jobs that require traveling across multiple locations.

One thing I avoid is self reference. It's implied, so I just simply avoid it. Remember that people reading these can be going pretty fast, so I just simply avoid it. Not to mention it's redundant. It might not be best practice, but it works. The first sentence is stating basically me with everything the job wants. After that, I attempt to sell myself as being great at a job.

The next thing we need to look at is what order to put the sections in. One of the things that will drive this is how well the information in these topics will present you. For example, if you have little to no education, technical skills would be a better thing to present first. Job experience may be what you want to present first if you have a rich job history. I, personally, only have an AAS in CIS and some spotty job experience because I'm a free spirit! Okay, I just have a lot of issues finding a job due to life and bad choices. However, I do have some useful technical skills. So for me, I do technical skills, then education because I don't want that to be forgotten about, and then job experience.

So I'm going to follow mine in order for now. Technical skills. Most resumes say skills. We put technical skills because technology. The idea here is we put down job related stuff we can do. It will often echo the requirements and tasks listed in the job description. You should keep this limited in scope, 4 to 5 points is the better range to keep it in.

Another thing I put in mine as the first bullet point are my certifications. Certifications are a magical double that count as a demonstration as both skills and education. If you put education first, you can look at putting certifications in there as they are also formal training. I also make a point to write it with the company related name each time.

Another important point when writing these is to use keywords that demonstrate points of the job you would be performing. One of the big players is troubleshooting. Here's what mine look like at the moment.
  • Certified with Comptia CySA+, Comptia Security+, Comptia Network+, and Comptia A+
  • Troubleshooting experience for hardware and software problems as well as server and firewall configurations
  • Networking configuration and cabling on both small scale single building and large scale multiple building setups
  • Hardware repairs such as screens and hardware installations such as access points and projectors
  • Experience with many operating systems including Linux, Windows Servers, Windows 10, and Mac OSX including for enterprise systems
So that's my short list of not-so impressive skills. Note that for the certifications, I put them in a reverse order of skill, the higher ones first. Everything should be relatively short and to the point. You can also put in things that are things you do outside of a job but that is still relevant.

Now let's talk the education section. Education is simply showing what education you have. It should include the institute, location, year of completion, and the degree or certificate achieved. Some pieces of information can be left out if necessary. For me, there is just one entry. It says my college, the city and state it's in, my degree and the year I graduated.

If you are still in college, you will want to include some of your courses that are relevant and current GPA. This can supplement some of your professional experience if you have a lack of relevant information to put in it. It's a pretty simple and straight-forward thing to write. You can also use the course description to write the description or directly copy and paste it. That's what I did for my resume when applying for an internship.

Next we talk about Professional Experience. This is one of those sections that has a good chance of having information that's not relevant. The reason is you want at least 3 but no more than five previous jobs listed. Even if a job is not relevant, spin whatever you can to something vaguely what they might be looking for. You highlight job duties that best represent a skill or task that the job requires. Here's an example of some of my job duties.
  • Desktop support for hardware, software, and peripherals
  • Network management including cabling and device configurations
  • Creating and maintaining images for large-scale deployments for entire labs and even buildings
  • Server configuration and management for Windows 2012 and CentOS used for computer imaging services
I tried my best to put in words that I find in job descriptions I apply for and other pieces of information that someone scanning the resume might be looking for.

At the very end goes your references. You should have three to five. Three to five tends to be the magic number.

Okay, so you have your resume, how long is it? One page is usually good, hopefully it's one full page. You can go onto a second page, but do not fill the page. Mine is two pages, but the second page is just references.

Now something that is super important and often overlooked, the cover letter. I often forget or am too lazy to write this on most applications. The funny thing is, all my calls I get are ones I specifically wrote a cover letter. I have come across plenty of cover letter cookie cutters. Do NOT use these. I made that mistake before and often realized after sending one that I forgot to change things here and there or that with some job titles it just read really strange. Not to mention it was rather robotic and just not something someone reading would consider.

Let's talk about writing one from start to finish. It may be a lot of work, but the payoff is worth it.

First we start with the obligatory addressing of "To whom it may concern." For the body you start with a simple introduction. That will consist of who you are and why you are looking at the job. If you already have a job, it may be worth explaining why you are leaving. For example, if you are looking for a job that's closer to home, that's fairly reasonable to why people may want to look for another job. If you want to avoid talking about your current job, then you can talk with more focus on the job you are applying for. You also want to in a sense echo the blurb you wrote, but in a more formal letter style. Make sure to highlight any key strength that they would want. Then to finish it off strong, tell them about how much you want to benefit them.
That is pretty generalized. Let me show you my most recent with some information censored out.
My Name is Matthew DeSantis. I am currently employed by ********** and trying to find a good job close to home. I have enjoyed working for the school systems and would like to continue to do so. I am familiar with the settings, requirements, and technologies that schools use. Currently I maintain three different schools (**********, **********, and **********) and have become accustomed to balancing different schedules of multiple places and assigning priorities to keep things as efficient as possible. As much as I love my current job, working for a different county comes with its own challenges and I would like to at the very least contribute to something closer. I would love to have the chance to contribute more to ********** and demonstrate what I can do and how I can be an asset.

Okay, so it's rather poorly written, but it was the best I could do at the time. I hope that helps demonstrate what a cover letter that isn't a cookie cutter might be like.

 Moving forward. You got a call back, now you have an interview. A lot of places now start with phone interviews to filter people out. Phone interviews are easy. It's mostly just questions and answers. I did one recently, and it was probably the easiest thing I've ever done. It started out with being asked for some basic information about myself and since I already worked the same job but for a different area, I brought that up to build a connection. You want to build a connection with the person quickly so they remember what you say. Try talking about a similar experience someone on your job might have to make this "one of us" sentiment. In the questions, be confident in your answers, but if you don't know do not waste the time of you or the interviewer. Be honest that you don't know and if you have a guess, let them know what you think the answer is. I had all the answers, but my sarcastic nature lead me to make a few jokes before actually answering. If you're like me, just remember to keep the jokes on the safe side.

Let's talk in-person interviews. In person interviews are always awkward for me for a few reasons that I'm sure others can associate with. I have some social anxiety, I'm a naturally sarcastic person, I can be pessimistic and opinionated, and I talk with my hands. In person, you should be aware of what you're doing and I sometimes lack that awareness.

So now what do you do for the interview? Let's talk about one I was in recently. I sat down with multiple people, as seems to be pretty common now for some reason. It started with a simple written test for technical skills. These consisted of some IP and subnet knowledge and some simple hardware knowledge.

After that we went on to questions. One of the questions I got asked was about what I was like and my job. This is one of the questions I often struggle with because it's so broad and open-ended. I tend to just describe my work history and work load. If you don't have much, try to think of something that might be relatable. After a handful of generic questions like what are your strong points and weak points, it gets to technical questions. These ones are easy for me.

I was asked about experience with Active Directory, which most places just expect a simple "yes, I can add, delete, and move around" stuff. Even if you've never done it before, it's nothing a quick Google search can't prepare you for. I was asked about my experience with different types of software and it's easy enough to rattle off everything I use at work or in my free time. I was asked about hardware repair as well. Most will ask about basic networking as far as do you know what the types of equipment are, how to plug them up, basic setup, really anything someone who is technical minded should be able to at least figure out with access to Google. I was also asked about my favorite and least favorite technologies. I'm not really one for a favorite, but least favorite is always printers, and with good reason. Printers use a combination of mechanical and computerized parts opening them up for many points of failure. Only other question I remember is about what to do if a computer is dropped from Active Directory. My solution is usually to boot it up in Clonezilla, unlock the Administrator account, then just rejoin it like normal.

After the line of questioning, I was given a couple of hands on tasks. The first was to find the mac address for a computer logged into windows. I was going to look through the network and sharing center, but decided ipconfig /all on the command line would be quicker and just did that. After that, they had a computer setup as broken to be fixed and try to get it working again. I had a hunch exactly what was wrong, but for due diligence, I decided to go through the diagnostic steps as well. It was simply just stuff being unhooked internally like the RAM and HDD, it wanted the video card used instead of the onboard. Nothing a simple step by step process couldn't solve in a few minutes.

All in all, if you've done this stuff before, it should be easy. The problem is when you've never done it before. My first time interviewing for the job I had now was a disaster. I made it all the way up to the in-person interview and it felt like it was all falling apart. After all the questions, they wanted a practical demonstration. So they handed me a list of tasks, set me at a laptop, and said have at it. I was allowed to Google and everything. Honestly, I should have been more apt to look up what I didn't know, and it was most of it. I actually ran the clock on the interview up to the last second to finish it. Here's the reason why. I had never done it before and I didn't do any research before going their on what I needed to know. When you apply to a job, you are given a list of job duties and responsibilities. Use that to your advantage and fill in any gaps before you get there.

All that being said, I hope this helps someone in their job hunt. Don't be discouraged if you have yet to find one, the job market for IT is very saturated at the time of writing this. It seems like everyone has at least some IT experience. If you want good areas to look at that have a good chance for getting your first job, while not exactly paying the best but still good enough, consider looking at schools and hospitals. Virtually every place has some IT staff, so make sure to look at other places than strictly computer places. I have also found a good handful of car dealerships desperate for IT staff.

Saturday, March 16, 2019

I can Linux and So Can You (Bash commands) pt.2

So we can navigate and manage files from Bash. Now let's look at how to view, edit, and alter file permissions. So let's get started.

First, let's create a directory to work in. For that we can use the command mkdir. Let's also keep in the Documents folder.

$ cd Documents
$ mkdir testing
$ cd testing

So let's create a blank file. There are a few ways to do this. There is the touch command and simply writing nothing to a file name. The touch command is used for some extra stuff, so let's start with just putting nothing to a file.

$ : > test

If you ls to view the files, you should see one called test. The : is a minimal function that does nothing. As a result, you then send the output, or lack there of, to a file. Now making a blank file doesn't really do much, so let's write something to the file.

$ echo "This is a test" >> test

This appends the string "This is a test" without the quotes to the file test. The difference between > and >> is that > write to the file overwriting the original and >> will append to the file. To quickly view this file, we use the cat command.

$ cat test
This is a test

Okay, so if we want to overwrite the file and replace it with something, we use > and if we want to clear it all we use : > and rm if we want to just delete it. So how about we look at editing a file.

On Linux systems, and a handful of others, vi is usually included. In fewer cases, vim is included. If you have vim, I'd recommend that, but for now I'll just go over some basic vi commands. The vi editor is a visual editor that can be very powerful. The problem often is that it takes some getting used to as it's not like most programs people use today. Let's open a blank file and make a quick script.

$ vi hello.sh

It should dump you into the vi editor. To type into the editor, we need to enter insert mode. For this we press the letter i. Type in the following.

#!/bin/bash
echo "Hello, world!"

Now let's save and exit. First press esc so we can enter a command. After that we start the command with : and we want to save, which is w, and quit, which is q. So we can type :wq and press enter. Now we have a file we can actually run, almost. If you want to run it right now, you can type in this.

$ bash hello.sh
Hello, world!

Okay, that's great, but let's make it so we can execute the file directly. For that, we need to learn the chmod command, or change mode. When we talk about modes, we are refering to the permissions for read, write, and execute. In this case, we are interested in execute permissions. The permissions are also broken down into owner, group, and everyone. So let's look at how that works.

User permissions can be represented by either a letter, or a number 0-7. Here's a basic rundown.

Execute: x and 1
Write: w and 2
Read: r and 4

To apply multiple modes with numbers, we simply add what we want together, for example:

--- is 0
--x is 1
-w- is 2
-wx is 3
r-- is 4
r-x is 5
rw- is 6
rwx is 7

I often times find that when setting up new stuff I use numbers and when simply modifying a singular permission to do something, like execute, I use letters. Now when using numbers, we will often use three numbers for the owner (u), group (g), and everyone else's (o) permissions in that order. So say we want to open up a file so that anyone and everyone can see, run, and even edit the file, we do it like so.

$ chmod 777 hello.sh

I'd recommend against that because it's bad practice. If you need to get back to normal, chances are it was 644, so we just put in like so.

$ chmod 644 hello.sh

We want to add just execute permissions. To accomplish this we can figure out the number (755) or we can add the execute permissions. To add permissions with a letter we use the + and the letter. To remove a permission we use - and the letter. So let's make it executeable.

$ chmod +x hello.sh

Now we can run the file as need be. That is simply by running them like so.

$ ./hello.sh
Hello, world!

Notice the ./ in front, that indicates we are running the script in the folder we are already in. Now if we do an ls -l we get something that looks like this.

$ ls -l
total 8.0K
-rwxr-xr-x 1 root root 34 Mar 15 21:28 hello.sh
-rw-r--r-- 1 root root 15 Mar 15 20:52 test

Notice the -rwxr-xr-x, this shows us our permissions. Now hold up a moment, what if we don't want everyone and their dog being able to run the script? Okay, let's remove the executable permission for everyone. Everyone will be o. So we remove it like so.

$ chmod o-x hello.sh
$ ls -l
total 8.0K
-rwxr-xr-- 1 root root 34 Mar 15 21:28 hello.sh
-rw-r--r-- 1 root root 15 Mar 15 20:52 test

Okay, so now everyone can just simply read that file. We can do even more complicated stuff like applying multiple modes, removing multiple modes and doing so to multiple sets of permissions by separating with commas. At that point, I'd rather just do some simple addition and figure out the numbers. If you want information you can always enter in this command.

$ chmod --help

That will print out the help information. For now, we got the basics. So let's get back to file editing. We could open up a text editor, find it, delete, then replace it, or we could do it with a command. While when doing it with a command is a bit blind, it's easily scriptable. For this we use the sed command. As with most commands, you can get more information with the --help option. So let's look at checking this out.

$ sed --help
$ sed -i 's/world/universe/' hello.sh
$ cat hello.sh
#!/bin/bash
echo "Hello, universe!"

So, that was pretty nice, but how does it work? Well, the -i option is the in place flag. This lets it know we want to edit the file and not just print the output to standard output. The second part is what is called a Regular Expression, or regex for short. Regular expressions are an extremely complicated subject that has a lot of power to give at the cost of potentially massive headaches. But understanding the basics are a good thing to know. For now I will forego the description and stick to the basic examples. The real use here is allowing the creation of automated scripts to configure things for you as most configuration files are text based in the wonderful world of Linux.

So what can we do with sed? Using the regex, here's a few options.

s/this/that/ substitutes this with that.
s/this/that/g does the same thing, but for every instance of this.
/this/d deletes this.
s/this//g deletes all instances of this.
/something/s/this/that/ replaces this with that on line that matches something
y/abc/def/ transforms abc to def
/something/y/abc/def/ transforms abc to def on line that matches something
/this/p prints all the lines matching the pattern

With good regex experience, you can accurately automate editing of files how you need, of course with an understanding of possible expectations. With too much reliance, you could have a world of headaches. As a good practice, before editing a file, you may want to copy it to keep an old version just in case. In fact, it's something you'd do enough that it's actually built into the command! So let's look at that. Let's change universe back to world, but keep the other one as a copy with the suffix .old.

$ sed -i.old 's/universe/world/' hello.sh
$ ls
hello.sh  hello.sh.old  test

If you want, cat each file and see the difference for yourself. Or you could run each one. Either way, we got the basics down without getting into regex, so let's move on.

In more complicated situations, you will probably want to do this manually instead of spending hours on end creating a regex pattern to match something you can do yourself in a minute. Or perhaps we want to add more stuff to our script. Let's go back to the great vi editor. Let's open our hello.sh

$ vi hello.sh

So let's say we want to jump down to the very last line. For that, we type a capital G. The cursor should have jumped to the bottom of the screen. Now let's insert a line in here, so press i. Let's use some of the commands we've already done. Then add the following lines.

echo "This is a test" > testing
echo "This is appended to testing" >> testing
sed 's/test/something/' testing

After that, let's save and exit. Now let's run it.

$ ./hello.sh
Hello, world!
This is a something
This is appended to somethinging

Well, now isn't that weird? We don't want that somethinging. Okay, let's fix this, for that we need to make sure we only do this on the first line. So let's vi this file again.

$ vi hello.sh

If you've been following along, we need to edit line number 5. You can either arrow down to the line or enter the command :5 to jump down, remember to press enter. Now we can either arrow over to the spot we want to edit, on the ' or we can press w. So either arrow their, or type :5<enter>w. Now instead of pressing i, we press a. It works like this, i is to insert on the cursor, a is after, I is the beginning of the line and A is the end of the line. So press a, then type a 1 for line 1, then escape.

Okay, now let's say we want to save this as a different name, like newhello.sh. For the we type in :w newhello.sh and press enter. After that we can :q to get out of here and go run our new script. But wait, it says we can't! That's because although we saved the file as a different name, we still have the original open. After we alter a file, we need to explicitly save or ignore the changes to leave. Let's ignore it with the command :q! and press enter.

Okay, now we're out, and want to run our new file. If you try, you will probably get a permission denied error. That is because this new file did not inherit the permissions of the original. Let's copy those over, since we already know how to do it manually.

$ chmod --reference=hello.sh newhello.sh
$ ./newhello.sh
Hello, world!
This is a something
This is appended to testing

Woohoo! We're getting things done now. So now let's quickly run through some vi/vim basics that should be helpful in the future, or else we could be here a while if we keep stopping along the way.

$ vi newhello.sh

Okay, let's work on this file for good measure. As mentioned before, G jumps us down to the bottom, so do that.
Now let's jump to the top, we do that by pressing gg, yes that's twice tapping g.
To jump to the end of the line, we press $. To jump the the beginning of the line, we use 0. If there is whitespace at the beginning, we can get to the beginning of the line of text with ^.
Arrows can move the cursor around in the same directions, or you can do h for left, j for down, k for up, and l for right.
Let's jump to line 2 with :2<enter>.
Pressing w jumps you forward to the beginning of the next word or punctuation and a capital W jumps you based on whitespace. Likewise, b and B go backwards of w. The letter e jumps you to the end of a word and a capital E jumps you to the end before whitespace. So experiment with that on line 2.
Now, let us get back to the beginning of the line. Let's highlight the word test. To do that we want to jump to beginning four words down. So we type 4W<enter>. Now we press v to enter visual mode, then e to jump to the end of the word. From here we can do a lot of things, let's start with copying the word. Press y for yank.
Okay, it's copied, let's hit p to paste. Wait, what? ttestest? That's not right, is it? Well, p pastes right after cursor. Let's undo that with u. to redo, it's ctrl+r, not just r.
Let's try that again, press capital P. There we go, that pastes before the cursor. Now let's just delete this. So press these keys, bvex. The x key is the delete key that will delete directly under the cursor or whatever is highlighted in visual mode. So let's put test back, after all, we copied it. Press P. Hmm... that says testtest and not test. Here's the thing, unless we dump what we deleted into oblivion, it copies. If you don't want to copy it, before we press x, we do "_ to indicate a "black hole register." So instead it would have been bve"_x.
Okay, let's just replace it instead. So type in bvec, it will delete the word and dump us into insert mode, so now we can just type in test.
Press escape and now let's talk about what r does. If you type in r, it will replace the character directly under the cursor. Press r and then any character you want and you can see it replace. It's actually something I use quite a lot. Now if in the previous command we did r instead of c, and tried to type test, we would have gotten tttttttt as soon as we hit t. Might be useful when changing a hex code to black or white.
So let's say we want to copy the line. Tap y twice, yy. After that, regardless of where the cursor is, tap p or P. Now we have two copies of that line. To delete that line (cut the line). If you don't want to cut the line, you can do "_dd like with x.
On the topic of whole lines, there is a line visual mode. For that, it's a capital V instead of lower case v. Tap V to select all the lines you want, and like with insert, esc to exit if you need.
Finally, let's talk about copying to the clipboard. Sure, you can highlight the terminal and copy the normal way. The problem is, then you lose the powerful and quick navigation when in visual mode. We just need to copy to the correct register. Remember the _ black hole register? Well, we want the + register. So before using y, yy, d, dd, or x, type "+. Likewise we can do "+ before p or P to paste from the clipboard.

Okay, so quick rundown of registers, you can use a bunch of them. It's the character directly after the double quote ("). If you want to view registers or see where things are being copied to, run the command :reg and it will bring up a list of all the registers in use.

This is just a broad view of vi, but it will work for now. So we've edited files with sed and vi, we've altered permissions with chmod, we've sent output to files, so what else could we mess with? Access times for files are tracked. Often times we can use these with various ways to incrementally backup data. Because of this, there is a command to alter this. To do this, we touch the file. Let's start by looking at that wonderful help menu (:q! to leave vi, if you forgot already).

$ touch --help

So there are a few things I see touch frequently used for, the most common being making a blank file.

$ touch blankfile
$ : > blankfile

Both of these accomplish the same thing, just one take a little less effort. However, as mentioned, we can alter the access time. Here's the basics.

$ ls -l
total 20
-rwxr-xr-- 1 root root 144 Mar 16 13:06 hello.sh
-rwxr-xr-- 1 root root  37 Mar 16 12:30 hello.sh.old
-rwxr-xr-- 1 root root 145 Mar 16 13:21 newhello.sh
-rw-r--r-- 1 root root  15 Mar 15 20:52 test
-rw-r--r-- 1 root root  43 Mar 16 13:31 testing
$ touch test
$ ls -l
total 20
-rwxr-xr-- 1 root root 144 Mar 16 13:06 hello.sh
-rwxr-xr-- 1 root root  37 Mar 16 12:30 hello.sh.old
-rwxr-xr-- 1 root root 145 Mar 16 13:21 newhello.sh
-rw-r--r-- 1 root root  15 Mar 16 18:44 test
-rw-r--r-- 1 root root  43 Mar 16 13:31 testing

Look at that, we altered access time. So let's try something else.

$ touch -t 7001010000.00 test
$ ls -l
total 20K
-rwxr-xr-- 1 root root 144 Mar 16 13:06 hello.sh
-rwxr-xr-- 1 root root  37 Mar 16 12:30 hello.sh.old
-rwxr-xr-- 1 root root 145 Mar 16 13:21 newhello.sh
-rw-r--r-- 1 root root  15 Jan  1  1970 test
-rw-r--r-- 1 root root  43 Mar 16 13:31 testing

Look at that? Isn't it... epoch? Just wanted to make that joke. Okay, so you can do a handful of things with this. There's an -a option, which keeps it to altering just access time and not the modification time. With the -t we can do a 2 year or 4 year date. In the case of this example, we use a 2 year date for 1970, the 01 for month, 01 for the day, 00 for the hours, 00 for minutes and .00 for seconds. There is also the -d option that can take a date string, but the numbers are a little easier. The -m option alters just the modification time.

Another thing to mention is that the -c option to prevent creating a file if no file exists. If you may accidentally create an artifact because of a goof or something, might want to consider that as an option.

These are just some of the basics of viewing, editing, and altering files. There are plenty more, especially if you have selinux enabled. For now, this should get you going for a lot of Linux stuff. Exploring basics of regular expressions and some more uses of vi and vim will be a great asset for the future. There are certainly many other tools to learn, but now we can do many things necessary to actually get to using a Linux system.

Thursday, March 14, 2019

I Can Linux and So Can You (Bash commands) pt.1

Often times I here people talking about wanted to learn Linux but have no clue where to start. I also noticed that those that do rely almost solely on a GUI. So let's say screw that GUI and try doing things on Bash. Open up a terminal and let's get started.

So let's start with some background. Bash, the Bourne Again Shell is based on the Bourne Shell (SH) and is commonly used by Linux and even now Mac. Other shells may be used like Dash (on Debian), Almquist Shell (Ash on Unix, also used on BSD and old Android versions), Tcsh (on BSD), Korn Shell (ksh, variants like mksh are on Android). Most of them are very similar and use similar conventions. I'm going to assume you're on Bash because that seems to be the most common Linux one.

The prompt should end in either a $, which is a standard user or # which is the root user. The prompts themselves may all look different and are customizable. I'll show commands after the prompt and their output. So let's get our bearings here. Let's check out what shell we are in, for that run the command:

$ echo $SHELL
/bin/bash

The $SHELL is a variable that says what shell you're in. Okay, so let's see what directory we are in. Chances are it may say on your prompt, but let's do a command.

$ pwd
/home/matt

You may see a tilde (~) in your prompt, that's the directory. It's shorthand for your home directory. So let's get an idea of the files and directories where we are. It's a very simple command:

$ ls
bash_history  Documents  Music     Public     Videos
Desktop       Downloads  Pictures  Templates

This gives us a basic list of the directory contents. Often times this is actually an alias to include colors based on the file type, like blue for directories. Mine is set as an alias for "ls --color=tty" and may be different for you. Now let's check out some of the flags you may use for ls to see some more information.

$ ls -a
.               Desktop        .msf4       Videos
..              Documents      Music       .viminfo
.armitage       Downloads      .oh-my-zsh  .vimrc
.armitage.prop  .gnupg         Pictures    .wine
.bash_history   .ICEauthority  .profile    .zcompdump-XXX-L-5.6.2
bash_history    .java          Public      .zcompdump-XXX-L-5.7.1
.bashrc         .local         .rnd        .zsh_history
.cache          .maltego       .set        .zshrc
.config         .mozilla       Templates

The -a flag shows hidden files, which are denoted by the beginning period "." You may also notice a single "." and a double ".." These are special, the "." refers to this directory and the ".." refers to the parent directory. Now we may want to look at even more information about our files, like permissions and ownership. For this, we use the -l option, which can also be used with the -a option if you want along the lines of ls -a -l or ls -al.

$ ls -l
total 32
-rw-r--r-- 1 matt matt    0 Jan  3 14:52 bash_history
drwxr-xr-x 2 matt matt 4096 Dec  6 14:17 Desktop
drwxr-xr-x 4 matt matt 4096 Feb 12 13:49 Documents
drwxr-xr-x 2 matt matt 4096 Feb 16 15:15 Downloads
drwxr-xr-x 2 matt matt 4096 Dec  6 14:17 Music
drwxr-xr-x 3 matt matt 4096 Feb 16 15:15 Pictures
drwxr-xr-x 2 matt matt 4096 Dec  6 14:17 Public
drwxr-xr-x 2 matt matt 4096 Dec  6 14:17 Templates
drwxr-xr-x 2 matt matt 4096 Dec  6 14:17 Videos


As you can see, there's a decent amount of stuff, so let's go column by column. The first column first letter is the file type, in this case d is directory and - is a normal file. The next three letters indicate read, write, and execute permissions for the user. An r means they can read, w can write, x can execute but a - in its place means the permission is off. The next three letters are for the group permissions and the last three are for everyone. The next column after that is the number of links, followed by owner, group, size, then a date of last modification and time, then the name of the file. There are still yet more permissions you can view that come into play with selinux. That is the -Z option. An example on a raspberry pi running CentOS I have looks something like this.

# ls -Z
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 anaconda-ks.cfg
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 epel-release-latest-7.noarch.rpm
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 http_fping.mod
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 http_fping.pp
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 http_fping.tt
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 README

The extra column is for selinux stuff. It can add another layer of security on your system and is a little outside of what I want to start with. So let's move on, shall we?

So ls can list directories anywhere, you just simply need to specify a path. But how do we know what path to use? Well, let's go over some Linux directory basics. The main folder is the root, which is /. This is not to be confused with /root, as that is the root user and / is the root to the file system. All of your files get attached under the root directory. Your user file will likely be in /home/<username>. So let's start by taking a glance at the root directory, so a simple ls / should do the trick.

$ ls /
bin   home            lib32       media  root  sys  vmlinuz
boot  initrd.img      lib64       mnt    run   tmp  vmlinuz.old
dev   initrd.img.old  libx32      opt    sbin  usr
etc   lib             lost+found  proc   srv   var

So what are all of these? The ones you should learn to familiarize yourself with are bin, which contains your binaries, or executable programs and sbin which has system binaries. The boot folder has your information for the system booting, like grub (grand unified boot loader). The dev folder contains device files like hard drives, attachable media, discs, ports, sockets, and so on. The configuration files for most stuff on a system level will be in etc. The home folder contains user folders, except for root, that's in root. When you plug in media, it will often be in media. The mnt folder is used for mounting, similar to media I guess. The opt folder contains optional programs which may also be in the usr folder, along with other binaries. The proc folder contains process information and system information. The tmp folder contains temporary files and if you think you lost something or downloaded something and can't find it, you may want to look in here. Other than that, I don't often use or look in the other folders or files myself. They have uses, I just have never needed to actively go into them.

We can probe around further to look into say... etc by doing ls /etc. So now we can look around the system, so let's talk about moving. Specifically, we need to change directory. The command for this is cd, and is the exact same command on Windows cmd. So let's change to root by running this command.

$ cd /

Chances are your prompt has changed replacing a ~ with a /. I would show you, but it varies system to system and can be configured. However now when we do an ls, it will list the / folder and not /home/<username>. So now we can move around, but how do we really jump around? There are some simple quick ways around.

cd ~ will move you to your home directory.
cd - will take you to the directory you were just in, so you can quickly toggle back and fourth.
cd .. will take you up one directory.

With those, you can begin exploring. I'd show some examples, but some that would eat a lot of space real quick. With cd and ls, you're on your way to not needing a file browser! So what other common things do we do with a file browser?

To copy a file, we have the cp command.
To move or rename a file we have the mv command.
To delete a file we have rm.
To delete a directory we can use rm or rmdir if it's empty.

Okay, so let's run through these commands with some context. If we want to copy a file called test1 and call it test2 we would do this.

$ cp test1 test2

Easy enough, and of course file paths can be used to copy to another directory, like so.

$cp test1 ../test2

This would copy it to the parent directory. So let's look at moving and renaming, since it's the same command.

$ mv test1 ../Documents/
$ mv test1 testing123
$ mv test1 /etc/samba/smb.conf

The first command moves test1 to the Documents folder, perhaps say from Downloads. The second one simply renames the file. You can also move and rename at the same time by just including the file name like the third example. So how about deleting a file? Simple.

$ rm test1

Now let's say we have a directory we need to delete.

$ rmdir uselessDirectory

If the directory is not empty, we need to delete everything first. Luckily we can do it all in one shot.

$ rm -R uselessDirectory

The R stands for recursive. It's just a fancy way of saying it deletes everything from the bottom up. Here's where things get a little weird, some systems alias rm to always prompt you about deleting every file. If you don't want a prompt, you use the -f option like

$ rm -R -f uselessDirectory

If it still prompts, it's an alias. We can look at getting around that later. For now, we know we can navigate, move, copy, rename, and delete stuff. So now we can pretty much shove aside a file browser, right? Well... we can still use it for a couple more things, but this seems long enough. Next I'll go over viewing, editing, and altering files.

Sunday, February 17, 2019

How to Linux or Something Like That

I am by no means a Linux expert, but at work I am the one they tend to defer to with "how do I Linux" questions. So maybe it would be worthwhile to make a small beginner guide on how to at least pretend you know what you're doing. So let's get out the basic "gotchas" of Linux and some semantics.

Linux is a kernel. Linux is to Ubuntu (or whatever you flavor is) as Windows NT is to Windows 7. I sometimes com across those snarky "Linux isn't an OS" comments online and it gets annoying, but this is the brief explanation to those.

Linux itself comes in different distributions referred to as "distros" or "flavors." If you're gonna talk about Mint, flavors seems like the better term, although it may get weird when you talk about Puppy being your favorite flavor. Sometimes different distributions are just the same one with a different desktop environment (DE) or software pre-loaded on it. Some desktops include things like Gnome, KDE, X11, xfce, MATE, LXQt, etc. There are a lot of desktop environments. To further add to some confusion, there are also window managers (WM) like xmonad, i3, and a million other ones. When discussing with others the environments they use, it can get complicated and layered because everyone uses a million and one things just to stick two windows on the screen at just the right location and spacing.

Personally, I use things mostly default because I often have to move around to a lot of different environments. I use CentOS minimal (no DE), Kali, Windows 7, Windows 10, Mac OSX Sierra, Ubuntu and various derivatives of, just to name a few.

If you're looking to pick the right distro for you, you can check out Distro Watch, they keep up to date on everything. Browsing there, you can find quite literally hundreds to choose from. Each one varies to some extent with the file structure, commands, or general way of doing things.

One of the big things for people starting out is the package manager. Without being able to install software, there are limitations for those that don't just make things themselves and package managers are the biggest help. It's one of the things that I loved when starting out with Linux. You can download or keep up-to-date all of your software in a simple manor. Each distro has its own way of doing things. Debian based has aptitude, RedHat based has yum, Arch based has pacman, and so on. Most have some form of package tool and special format.

I'm on Kali right now, so if I want to update all of my stuff, I may do something like:

apt-get update && apt-get upgrade -y

This is really dependent on what distro you're on, what kind of updates you're getting (like if you're on a rolling distro), and the like.

Now a brief look at file structures. The root file is /. It contains a handful of folders such as bin (user binaries), boot (boot files), dev (device files), etc (configuration files), home (user folders), lib (libraries), mnt (mount), opt (optional apps, usually ones you install outside of a package manager will end up here), proc (process information), root (root user, not to be confused with the file root), sbin (system binaries), srv (service data), tmp (temporary files), usr (user programs), and var (variable files such as logs, default web root for web services, etc.). Chances are you actually have many more than that, and it all depends on the distribution. I'm personally a fan of how Linux handles devices in the dev folder allowing you access to devices in similar ways you interact with files.

Shells. Your shell on a Linux system is an invaluable tool for when all else fails. Knowing how to use it is immensely helpful, and customizing it to make it your own is very satisfying. Most variations seem to default to Bash (Bourne Again Shell), based off of the Bourne Shell. There are numerous other variations such as Korn shell (ksh), Almquist Shell (ash), Dash (default for recent debian distros), C shell (csh), tcsh (unix compatible c shell that Mac used for a while), Friendly Interactive shell (fish), Z shell (zsh), and many more. Most of them have cross compatibility with minor changes here and there for syntax and the big distinction being how they handle interactive sessions.

Personally, I use zsh with Oh-my-zsh!, and tmux (a terminal multiplexer) when I'm getting down and dirty. For scripting, I stick to good ol' Bash... or Python or Tcl, depends on what I'm doing really. Tcl seems to pop up at random and I use it at work for a custom backup script for the many switches we have (with expect).

Some of the more basic things you would do to get started on Linux and really grab into the shell is basic file navigation and text editing. When it comes to text editing, I love Vim. My favorite thing about Vim/Vi is how quick and easy it is to do stuff when you know what you're doing. My second favorite things is when people copy a command with vi or vim in it and have no idea what they're doing. You see kids, Vi is a visual text editor that requires knowing commands in it to edit, save, and even exit it. There is also nano, which is to speed with most newcomers, but not every distro comes with it. So let's go over a quick and incomplete Vi/Vim lesson!

To quit the program you type :q
To move the cursor, you can use arrows or h (left), j (down), k (up), l (right)
To insert text (go into insertion mode), i inserts on the cursor, a inserts after, I inserts at the very beginning, A at the very end of the line
To stop inserting, press esc
Backspace doesn't always work, delete always does, x will delete when not in insertion mode
To save you type :w
To save and quit you can type :wq or :x
To quit without saving, you type :q!

There are also ways to copy and paste, regex substitute, find, and all sorts of things. If you start getting used to it now, you can soon start to learn all the other cool things.

Let's say we want to edit the hostname on a computer. We do something along the lines of:

cd /etc
vim hostname

Then press i, type in the hostname, press esc, then :wq
We can then restart the computer. So what are some quick and easy commands to get started?

cd <directory> (change directory)
mkdir <directory> (make directory)
touch <file> (create a file)
rm <file> (remove a file)
cp <file1> <file2> (copy a file)
mv <file1> <file2> (move or rename a file)

There are a lot of commands, and it changes from system to system to some degree. Without getting into one specifically, it's hard to go too in-depth.

So how do you pick a distro for you to get started? Major distributions are a good start with the large communities and lots of documentation and tutorials. Ubuntu, Mint, CentOS, Debian, Fedora, Manaro are just a handful of some of the major ones. I personally started out with Ubuntu. With Ubuntu I could do everything with GUI and introduce myself into command line stuff at my own pace. After that, I learned how to configure and run systems entirely from the command line.

Saturday, February 16, 2019

ROT Cipher in Python

Recently I was messing around with some stuff and kept needing a Caesar Cipher deciphered and kept using some not-so-good online ones. So what better thing to do than make one myself. Why even stop at a Caesar Cipher and just make an adjustable ROT tool. So rather than copying one that probably works better and has a nicer design, I made my own.

#!/usr/bin/python3
#
# Made by: Matthew DeSantis
#          www.anarchy46.net

import sys
import os

# Upper case limits
CAP_MIN = ord( 'A' )
CAP_MAX = ord( 'Z' )
# Lower case limits
LOW_MIN = ord( 'a' )
LOW_MAX = ord( 'z' )

# Rotate the characters
def rotate ( offset, c ):
    o = ord( c )
    # Uppercase
    if o >= CAP_MIN and o <= CAP_MAX:
        o = o + offset
        # Loop back to beginning
        if o > CAP_MAX:
            o = o - CAP_MAX + CAP_MIN - 1

        # Loop back to end for backwards
        elif o < CAP_MIN:
            o = CAP_MAX - CAP_MIN + o + 1

    # Lowercase
    elif o >= LOW_MIN and o <= LOW_MAX:
        o = o + offset
        # Loop back to beginning
        if o > LOW_MAX:
            o = o - LOW_MAX + LOW_MIN - 1

        # Loop back to the end
        elif o < LOW_MIN:
            o = LOW_MAX - LOW_MIN + o + 1

    return chr( o )

# Cycle through the string
def cipher ( offset, text ):
    output=''
    for t in text:
        output += rotate( offset, t )
    return output

if __name__ == '__main__':
    try:
        # Max rotation offset
        max_off = CAP_MAX - CAP_MIN + 1
        offset = int( sys.argv[1] )
        # Get the offset from max (like if 27 is in and max is 25, you get 2)
        # Then set positive or negative
        offset = offset and (abs( offset ) - abs( max_off * int( offset / max_off ) )) * (offset / abs( offset )) or offset

        # Text is passed via args
        if len( sys.argv ) > 2:
            text = " ".join( sys.argv[2:] )
            eol = os.linesep

        # Or text is passed via pipe (./rot.py 13 < example.txt)
        elif not sys.stdin.isatty():
            text = "".join( sys.stdin.readlines() )
            eol = ''

        # No text!
        else:
            raise Exception( "Missing text!" )
        print( cipher( int( offset ), text ), end=eol )

    # Not a valid number or the like.
    except ValueError:
        print( "Invalid type." )
        exit( 1 )

    # Catch anything else because oops.
    except Exception as err:
        print( err )
        exit( 1 )


So saving this as rot.py, I can use it for stuff in the terminal:

./rot.py 13 This is a secret message

Or I can use it to decrypt a file:

./rot.py -13 < secret.txt

I tried to make it as flexible as possible. Decryption can be done by using a negative, or you could cipher it negatively, whatever makes you happy. My math for doing the offset is a bit of evil. The idea is to rotate no more than once around while preserving which way around it goes. There are most certainly better ways to do it, but I was feeling "artistic."

Sunday, February 10, 2019

Free Imaging Server for Deployment

Free is always nice. All businesses love the idea of cutting costs. Sometimes the free stuff can even offer more and better options. Will that be the case here? I don't know. What I do know is that at work we cut costs in almost any way imaginable and this is one way.

FOG Project

This is a very nice solution for the mass deployment and management of operating systems. It is compatible with Windows, Linux and Mac OSX, which is rather impressive. So let's get into a broad overview of the installation and features.

For setting up the server, it's fairly straight forward. I have had the best luck with CentOS, but we have also ran it on Ubuntu. When I tried doing another Ubuntu install when upgrading some things, various issues popped up. I would also recommend that when you create an /images folder for it to store the images that you make it a separate partition or hard drive. I had an issue with some folders using too much room and leaving the OS in an unbootable state and if I had the files separate, recovery would have been easier.

The setup also offers for the server to function as a DHCP and/or DNS server, so making a standalone for a deployment when the necessary server infrastructure might not be there is a good thing to have. This can let you create a quick and easy deployment environment with out too much work. There is also a way to set up multiple servers where others act as storage nodes, which can increase the deployment speed.

The IPXE boot menu for Fog offers a lot of options to customize it. You can change the colors and styles. You can also change the boot method after between options in GRUB or to boot to rEFInd.

There are the basic deploy and capture image options. You can also register a host, will take an inventory and allow for you to manage it in many ways. This can include changing the name, joining a domain, debugging, memory tests, hard drive checks, file recovery, reset local passwords, wake on lan, virus scanning, hard drive wiping, and snapins. It can also deal with printers, keep a login history, schedule powering off, auto-logouts, and this is all just some surface level overview.

There is an ability to group together computers for mass deployments and managing. I use it when setting up computer labs or any group that I could potentially need to install the same software on all of them.

The image management is fairly straight forward. Of course it resizes the partitions for you to take up all the space necessary.

Snapins are very useful. You can create Batch scripts, Bash scripts, Powershell scripts, VB scripts, and send out MSIs. You can essentially create a nice base image, then add extras or tweak with snapins.

After that, there are options for managing printers, printing out reports, and lots of settings you can tweak.

As a basic example of what I would normally do, let's assume I need to deploy an image for a computer lab. After registering each computer to Fog with a name and adding it in a group together, I would then deploy an image and have it join to the domain. After that is all set up, I would then deploy a snapin for the Lanschool MSI for the students. The teacher computer would be kept separate, but I can use snapins to install the Lanschool teacher console and any extra software. In cases where the installer is not an MSI, I would use a batch script with a Samba share that hosts the exe.

With all of those hots registered, I can then use the wake on lan feature to turn them on when needed to remote into them and work. I can also use snapins to deploy simple batch scripts to do various things (personally, I prefer to use PsExec for simple things).

It's a nice tool with lots of features and instructions how to do almost anything you could want.

Tag Cloud

.NET (2) A+ (5) ad ds (1) addon (4) Android (4) anonymous functions (1) application (9) arduino (1) artificial intelligence (1) backup (1) bash (6) camera (2) certifications (3) comptia (5) css (2) customize (11) encryption (3) error (13) exploit (5) ftp (1) funny (4) gadget (4) games (3) GUI (5) hardware (16) haskell (6) help (14) HTML (3) imaging (2) irc (1) it (1) java (2) javascript (13) jobs (1) Linux (19) lua (1) Mac (4) malware (1) math (6) msp (1) network (13) perl (2) php (3) plugin (2) powershell (8) privacy (2) programming (24) python (10) radio (2) regex (3) repair (2) security (16) sound (2) speakers (2) ssh (1) story (5) Techs from the Crypt (5) telnet (1) tools (13) troubleshooting (11) tutorial (9) Ubuntu (4) Unix (2) virtualization (2) web design (6) Windows (16) world of warcraft (1) wow (1) wx (1)