Skip to content

2015

Compare the output of two commands

..without creating a temporary file:

diff -y <(ls First_directory) <(ls Second_directory)

The -y is just to show a side-by-side comparison. Very handy! And the result?

[jorge@j-laptop temp]$ diff -y <(ls First_directory) <(ls Second_directory)
common.txt                          common.txt
first_file.txt                            | second_file.txt

Thanks to my colleague Ingvar for showing me this!

No Wi-Fi device found

I just reinstalled one of my machines with Fedora 21. The install went great, but when the machine was done rebooting, and I was trying to set up my access to a wireless network with nmcli (NetworkManager), I got the following error-message:

# nmcli dev
DEVICE   TYPE      STATE        CONNECTION 
enp0s25  ethernet  unavailable  --         
lo       loopback  unmanaged    --         
wlo1     wifi      unmanaged    --

..and:

# nmcli dev wifi rescan
Error: No Wi-Fi device found.

Spending a lot of time finding what the problem was, I finally found the solution. It seems that Wi-Fi support in NetworkManager has been separated to a plugin. The package NetworkManager-wifi was missing. According to Pablo S. Torralba, who was kind enough to comment on this post, it should be enough to kill NetworkManager and launch it again as root. Should that fail, you can always try the old reboot-trick! Either way, it should hopefully be working.

Introduction to cron

cron is a time-based job scheduler. This piece of software utility is used when you need to have a program run repeatedly at set time.

The daemon that runs in the background is named crond, while the file that contains the jobs themselves is named crontab.

You have three main directories:

  • /etc/crontab is the main system crontab file.
  • /var/spool/cron/ a directory for storing crontabs defined by users.
  • /etc/cron.d/ a directory for storing system crontabs.

Creating

Creating a crontab-file for your user is easy. Usage depends on what you need to do.

Edit

crontab -e

This command will allow you to edit the current user’s crontab. If a crontab doesn’t already exist, it will create a new one once you have saved your changes.

Edit another user’s crontab

crontab -u jorge -e

You can also edit another user’s crontab, but only if you have the correct permissions in place to do so.

List

crontab -l

or

crontab -u jorge -l

..to list another user’s crontab.

These are the most common usages of the command crontab. For a couple of more options, see man crontab.

Syntax

The syntax of a crontab-file looks like this:

* * * * * /path/to/program

Each asterisk represents a field. Starting from left to right, the fields are as follows:

  • Minute (0 – 59)
  • Hour (0 – 23)
  • Day of month (1 – 31)
  • Month (1 – 12)
  • Day of week (0 – 7, where 0 and 7 is Sunday)

On the fields Month and Day of the week, you can also use names instead of numeric values.

Operators

There are various operators that you can use with cron. Here’s the list:

Asterisk (*)

An asterisk (*) is used to indicate that every instance (i.e. every hour, every weekday, etc.) of the particular time period will be used. So if you use an asterisk in the field Hour, it means that it will run every hour.

Comma (,)

With this operator you can specify a list of values. If you use 1,5 in the field Day of week, this would mean Monday and Friday.

Dash (-)

While comma specifies a list of values, dash specifies a range. 1-5 in the field Day of week would mean Monday to Friday.

Forward slash (/)

Forward slash specifies a step value. If you’d like to execute a command every other hour, you could use 0-23/. You can also use steps after an asterisk, so if you want the command to run every two hours instead, use */2.

Examples

First

45 14 1 * * /home/jorge/backup.sh

In this example the script backup.sh runs at 14:45, the first day of the month, every month.

Second

30 04 1,15 * 5 /home/jorge/list_files.sh

This line runs the command list_files.sh at 04:30 on the 1st and 15th of each month, plus every Friday.

Third

00 08 * * 1-5 /home/jorge/wake_up.sh

The line above runs the command wake_up.sh at 08:00, Monday to Friday.

Fourth

*/5 * * * * * /home/jorge/annoy_wife.sh

..and this line would run the program annoy_wife.sh every five minutes, every day.

As always, if you want to know more about cron, check out the command man cron.

Have fun!

Split and merge PDFs – part 2

A while ago I wrote a post named Split and merge PDFs with pdftk. Unfortunately, pdftk seems no longer to be maintained for Fedora 21. So we have to use another alternative – poppler-utils:

Install the package with:

yum install poppler-utils

..and you can use them to both split and merge files. poppler-utils contains a list of tools that you can use to manipulate PDFs:

  • pdfdetach — lists or extracts embedded files (attachments)
  • pdffonts — font analyzer
  • pdfimages — image extractor
  • pdfinfo — document information
  • pdfseparate — page extraction tool
  • pdftocairo — pdf to png/jpeg/pdf/ps/eps/svg converter using cairo
  • pdftohtml — pdf to html converter
  • pdftoppm — pdf to ppm/png/jpeg image converter
  • pdftops — pdf to postscript (ps) converter
  • pdftotext — text extraction
  • pdfunite — document merging tool

So, we move on to merging and splitting:

Merge

pdfunite first_page.pdf second_page.pdf end_document.pdf

Split

pdfseparate -f 1 end_document.pdf %d.pdf

Check out man pdfseparate for more information about the tool.