Today I had a need for resize multiple images at the same time on Mac OSX. Normally I have had only need for resize one image or I have done resizing when exporting images out of Lightroom but today I had different needs so I had to search how to do that.
I found website called ainotenshi.org where was good explanation how to do that with native OSX tools. Just in case that site goes down some day here is the short demonstration how to do that.
In Mac OSX there is command line tool called sips which gives you easy way to resize images in batch.
NOTE! This will affect your images so make sure you have backups – there is no possibility for reverse that command!
I had need to resize images to 2048*x or x*2048 so it was like a walk in the park with sips: sips -Z 2048 *
Sips gives you possibility to resample images too so make sure to check out that tool. It comes with Mac OSX so you don’t have to install anything new on your computer.
This tutorial is aimed for totally beginners who have no any kind of clue how to install web server on Linux. In this case we go step-by-step process how to create a new droplet (a fancy word for the virtual server) in Digital Ocean and then we install Apache 2 and test the web site.
I do not go through the process how to register on Digital Ocean, so just figure it out. It should be easy, and if it is not you can go and register your server wherever you like. Just skip those first steps and then just install the Apache.
Create the Droplet in Digital Ocean
When you login you should see the view similar to picture above. Of course if you have no other droplets already list is empty. Just move mouse over the green button and click “Droplets” which has text “Create cloud servers” under it.
After that you should get a view which is similar than in the picture above. Select “Ubuntu” 16.03 x64, select whichever size you prefer. If you are going to use this in real life situations later with databases etc. I recommend that you do not go less than package which is $10/mo package where is 1 GB/1CPU and 30 GB SSD. In this example you can select whatever you like anyway because we are only doing beginners installation without any databases and stuff.
Select your datacenter. I chose Frankfurt because it is quite close to Finland so network speed should not be an issue. Not in other servers either, but closer the better unless you know what you want.
In the bottom of that page you see “Choose a hostname”. Just give whatever name you like which is valid. In this case I chose “mahserver”. In my real servers I have naming convention that I use female singer names like “elize”, “lissie” and “simone” but some people use their kids names, band etc. Or whatever like “jsafhjsd7-8njnk3-x”.
Press the huge green button on the bottom of the page to create your droplet. It should take about one minute or less to create that one.
When the creation is ready you will see “Let’s get to work!” text on your new droplet. You should soon get email from Digital Ocean where is your IP (seen on this list too), username (which is “root”) and password.
Connect to your brand new server
Open the terminal application. I am using Mac OSX so I launch the app called “Terminal”. If you are Windows user, download PuTTy and use that.
Connect to your server using command “ssh firstname.lastname@example.org.” where you of course replace 126.96.36.199 to your own server IP which you see on the email you got or directly on the list from the Digital Ocean.
SSH asks first time about the authenticity of the host. Just write “yes” and press enter. Then you have to give your password which you got in email. Just copy-and paste it so you don’t make mistake! Note that on Terminal if you are unsure which key combination works, just use menu item “Edit -> Paste”. You DO NOT see the password you are typing or any kind of clue how long text you are entering so just paste it and press enter.
Update the system
On digital ocean you must give new password for your server which is smart because you got password via email. Just select something you remember and write it. Also same password of course goes to next question where you must retype your password.
After that you are logged in your server! Not it is time to get hands dirty and start installing stuff.
First you should update your packages list and then install updates you have waiting. You don’t have to care what that means in this tutorial. Just write the command “apt update && apt upgrade” to do both steps. If you have updates just update those first.
Install the actual web server called Apache 2
After the updates you can install Apache 2 which is the actual web server which will host your web sites.
Just press the enter after the command, install all the packages it asks for (press Y and press enter) and then just wait until the installation is done.
After the installation you are back to command line. Your Apache web server should be now up and running. You can see if it is just going to your server with your web browser.
Of course you should change your URL to http://188.8.131.52 where 184.108.40.206 is the address you used when you connected to your server with ssh.
If you see the page like in the picture above, congratulations! You have now Apache web server up and running!
Change the web page content
Now we just move that ugly demonstration page away and create page which just says “Hello World” so you know where you should put your files.
In the picture above we were doing multiple tasks.
1) Move to the directory where your website is. After the installation in Ubuntu it is on /var/www/html
2) Move your old web page file to another name for backup, just in case
3) echo “Hello World” > index.html command will write text “Hello World” to your index.html which is the default page Apache loads
After those steps you can reload your web page within your web browser and see your brand new web site with “Hello World” text there.
I had a need for automatic screenshots in Mac OSX in every couple of hours. I wanted this because I am keen to see how value of cryptocurrencies I own had changed in Exodus wallet. I just leave this script running and leave Exodus on screen so I can easily see changes later by watching screenshots.
To generate screenshots automatically you can use simple BASH one-liner: OUTDIR="/Users/stargazers/Desktop/screenshots"; while true; do FN=$(date '+%Y-%m-%d-%H_%M_%S'); screencapture -x "$OUTDIR/$FN.jpg"; sleep 3600; done
In above we define OUTDIR where we are going to store screenshots, in FN we generate filename from current date and time and then we use OSX CLI tool called screencapture. In sleep part we define time we wait until we take the next screenshot. This value is given on seconds so 3600 is one screenshot per hour.
Script can be cancelled by pressing Ctrl + c on terminal. Of course another alternative for this is to run CLI tool screencapture as a cronjob, but in my case it is not what I want – I’d rather start this script manually when I need it and stop it when it is not in use anymore.
I recently had a task where I need to set Linux server which will send emails outside world. First I went to server with SSH and checked if there is anything listening on port 25 with netstat. Note that if you run with flag -p you might need root permissions to see which application is listening that port. If you don’t do it as a sudo/root then you just see no PID/Program name.
I noticed that there indeed was Exim4 already installed and up and running so I tried to send email to my mail address with CLI tool mail. mail email@example.com
After I had written my email and sent it I checked Exim4 log files from /var/log/exim4/mainlog. Mail log said like this:
2017-08-29 12:12:59 1dmdVz-0004sD-65 ** firstname.lastname@example.org R=nonlocal: Mailing to remote domains not supported
Gladly this was quick to fix. Just edit Exim4 configuration file (remember to take backups!) /etc/exim4/update-exim4.conf.conf.
and restart Exim (On Ubuntu and Debian servers service exim4 restart should work). After these changes I was able to send emails to world outside.
As many might know or guess I am using WordPress on this site. One very important aspect about keeping blogs is the backup. Also the backup files must be on an another machine than the actual blog so in case your server crash or something catastrophic is going to happen you don’t have to care about it – just take your database dumps and all the files and move to the next server.
There might be plugins for that but I prefer simple BASH-script I wrote. You can download it on GitHub.
The script goes to the path where WordPress site is, generates the database dump there, creates a .tar file and copy it to remote server using scp.
In this script I use only server name “simone” because I have added it on my git configuration file. I will write more about git configuration file some other day.
Today I decided that I should start a new blog, The Way of DevOps where I will write different nerd stuff.
I also write a blog in Finnish called Aleksin Blogi but there I don’t write much about Linux and nerd stuff unless it is related exactly to that blog itself. For example when I had issues on server I wrote about it in that blog.
As the name suggests you will find in future here about DevOps stuff, but this blog is not meant only for that. There will be posts about general Linux tips and other nerd stuff I find interesting. Time will show!
Anyway, welcome to the server side. May the source be with you!