Linux Tips, Tricks, Apps & Hacks 19
Tips | Tricks | Hacks | Apps
Advanced Tip:
If you want to install and update software on
multiple systems on a network, you can save
a lot of bandwidth and time by creating a local
software repository.
On systems which use ZYpp/YUM, you can
create a local software repository using the
following steps:
Firstly, mirror your desired repo to a folder, eg
/var/www/ludsuserepo/rpms.
# sudo zypper install createrepo
# createrepo /var/ludsuserepo/rpms
At this point, all the required metadata will be added
to the folder to make it a valid repository. To add this
repository to the remote systems, you can use:
# zypper addrepo -t YUM http://<host>/
ludsuserepo/rpms local_repo
On Fedora/Red Hat you can use
Yellowdog Updater, Modifi ed (YUM):
# yum install <packagename>
Note: YUM can also be installed on other
distributions such as Ubuntu and openSUSE.
On Debian/Ubuntu you can use
Advanced Packaging Tool (Apt):
# apt-get install <packagename>
On openSUSE you can use ZYpp:
# zypper install <packageName>
Managing services
In Linux, a service is a crucial application (or
collection of applications) that runs in the
background. They handle everything from
booting the system to serving webpages. You
can use the command ‘service’ (an init script) to
manage services.
To get the status of all the services installed on
the system:
# service --status-all
To start a service:
# service <service name> start
To stop a service:
# service <service name> stop
To get the status of particular service:
# service <service name> status
Running scheduled tasks
If you are doing a repetitive task on your system, it
is better to automate. For example, you may want
to sync fi les between two systems at a regular
interval. Instead of doing it yourself manually, you
can create a scheduled task that automatically
runs at the confi gured intervals. In Linux (and
most UNIX environments) this is achieved through
cron. Cron is a time-based task scheduler.
To create a scheduled tasks using cron…
01 Run the following command to open the
current user’s crontab fi le:
$ crontab -e
If you want a task to be run using root privileges,
you should use the command:
$ sudo crontab -e
02 The crontab fi le will then open in the default
text editor.
The default text editor can be set up using the
EDITOR environment variable:
$ export EDITOR=nano
Crontab takes input in the following format:
minute(0-59) hour(0-23) day(1-31)
month(1-12) weekday(0-6) command
An asterisk ( * ) is used as wild card. For example,
using asterisk with month will cause the task to
run every month.
03 Let’s assume that you want to run /usr/bin/
myludapp every day at 12.30 AM. So we will need
to create the following line in it:
29 0 * * * /usr/bin/myludapp
Here, 29 is for the 30-minute mark and 0 for
12 am because the minute, hour and weekday
values start at 0. However, the day and month
values start at 1 instead of 0.
Managing backups
Backup is very crucial to any system, whether
running in isolation or a networked environment.
You can use rsync to create backups for your
system. Rsync is a fi le synchronisation utility. It
provides the following features which make it a
perfect tool for backups:
• Differential copy: This means it will only copy
the bits that have actually changed.
• On-the-fl y compression: This type of
compression makes the backups fast and
consumes less bandwidth.
• Security: You can user the Secure Shell
protocol (SSH) to do the backups, which makes
the process of backing up very secure.
• Easy to use: rsync is very easy to use, almost
like the cp command but with better features.
To do a local backup:
# rsync -azvv <foldertobackup>
<destinationfolder>
To do a remote backup over SSH (this
will require OpenSSH server to be installed
and started on the remote system):
# rsync --delete -azvv -e -ssh /source/folder
user@remotemachine:/destination/folder
Cron is not the only task scheduler out there. There
are a number of alternatives available. One we
really like is JobScheduler. It provides the following
advantages over cron:
• Provides a log fi le for running programs.
• The execution status of a program is checked
automatically and is reported to the administrator
automatically.
• You can start jobs in a sequence that is dependent
on the execution status of the jobs.
• You can use a centralised user interface to
manage, confi gure and monitor jobs.
QJobScheduler web interface
Advanced Tip:
“If you are doing a repetitive task on
your system, it is better to automate”
WorldMags.net
WorldMags.net