Top 6 common uses for grep | top six uses for grep linux systems administration centos redhat

Grep is the number one tool used by linux systems administrators. I rely on this tool everyday, but its used in many different ways. I decided to list my top six uses.

 

Top use is grep with the recursive switch (grep -r). This is used for searching a particular filesystem path for a particular word. One common reason why I use this switch is when Im searching in a nagios configuration directory for mentions of a hostname. This allows me to find all the locations where a hostname has been mentioned and I can then alter it if needed.

 

This straightforward search allows you to look in a text file and find all the locations where the expression or search word can be found. The results will include the entire line where the expression has been matched.

 

The will do the opposite from he previous command, this will exclude all mentions of the search criteria. This will remove the entire line from the search results.

 

This will match the line but also include a certain number of subsequent lines, the number indicates how many lines after the match you would like included.

 

Again this the opposite of the previous command, this will include a certain number of lines before the match line.

 

This also proves to be very useful, this will remove case sensitivity from your search string.

 

Executing SFTP transfers in BASH scripts | linux centos ssh rcp sftp ftp bash script batch file automation

I need to write a script which fetched files off a ftp server and put it into a specify folder for processing.

I was used to using SSH for these job and now I was forced to connect to an SFTP server, this was my first time and everything is a little different.

I have attached the commands I used in my bash script to get the project over the line.

 

This command allows you get a listing of what is currently on the server.

This will fetch all the CSV files on the SFTP server and copy them locally.

This was partially tricky, don’t know why. They may be an easier way which I overlooked but this worked for me. For some reason to send file you need to specify the instructions in a batch file which is execute once connected.

 

IPTables blocking outbound port to specific host. | centos redhat linux iptables outbound port block drop dport ip

I needed to write a iptables rule to block outbound traffic to a specific host here.

Now I need to write a similar rule which will not block the entire host but just a single port to a host.

The rule is very simlar to the previously state but with the port flag, see below.

 

LVM How to shrink a partition | reduce the size of a partition on linux lvm lvs vgs pvs linux centos redhat ubuntu

I built a linux system which was constructed using the default configuration, in regards to disk space allocation.

When the system was completed I was not happy with the result, so i needed to reduce the space of one partition and increase another.

This is an uncommon procedure, so I wanted to document and let you know its relatively low risk and easy to perform. 

Heres how.

Start off my getting a detailed display of the current setup.

To resize the partition we must first amount it, please ensure none of the applications have locked any files as it will not unmount.

The check its actually unmounted.

Reduce the space in LVM on home

 

Then resize home partition (Shrink), this will raise an error informing you that you need to e2fsck first.

Run it

Re run resized2fs

Once completed you can then mount the partition.

As you can see the size of home is now 10G

 

And we have 35G free on this volume.

Enjoy!

 

 

Apple Macbook Pro 13″ 2010 with broken trackpad | apple macbook pro 13″ 2010 battery expanding trackpad broken not working

My Apple Macbook Pro 13″ (2010) spends 90% of its life as a desktop, its connected to my keyboard mouse and monitor and does not see much travel.

wp-1477273918456.jpgLast month I was going on a holiday, on the morning of my flight I disconnect my laptop and prepared it for my holiday. I thought I would test everything and ensured it all worked before taking it with me.

The laptops appeared to be operating fine, but the mouse (Trackpad) was not working. It appears to be raised a little higher than normal. Considering I could not use it on my holiday it stayed behind.

wp-1477273935277.jpgInstantly I thought, oh well! Iv had 6 good years it might be time for an upgrade! While on holidays my mind was working in the background…. I suspected the battery might have extended and was pushing the trackpad upwards…

After seeing the prices of the new MacBooks I thought lets give the old beast some more life! 

When I opened it up I was correct, the battery was ready to explode!

See photos!

wp-1477273975968.jpg

 

wp-1477273993488.jpg

My plan is to replace the battery with a new original batter and install a SSD, ill post the procedure when all the parts arrive.