Unix tips 2 (from wikipal)

Edit a simple text file

Without windows, you can use:

vi myFile.txt

With X-Windows you can use:

gedit myFile.txt

Editing Software

There are several possible editor to use:

* vim: is a simple editor that can be interesting because it does not use any windowing system. The difficulty is to learn the commands because there is no menu, of course. If you learn some command it is in fact a powerful editor with syntax highlighting.

* gedit: is a simple editor from gnome but it can recognize the syntax of most languages.

* kedit: is the editor of the KDE environment. It is less interesting than gedit for software because ther is no syntax highlighting.

You can also use integrated environment:

  • kate: seems a nice environment
  • kdevelop: the environment from KDE
  • eclipse: initially developed for Java. Now work with C and C++. Seems well integrated and advanced.

UML diagrams can also be created and edited:

  • umbrello: seems to be a nice software for UML diagram edition.

Cut and Paste under X-Windows

Selecting is equivalent to copy. To paste use the middle button.

Login to a Unix machine enabling X-Windows

The usual command for connecting to a unix machine is ssh. Example:

ssh ipal-server2

If you need to login in with a different default name just put it before the machine name. Example:

ssh user@ipal-server2

If you need a graphical environment for your remote program, you need an X-Windows server to be up and runing. It depends on the system you are using:

  • Unix: an X server is up by defaut. Nothing special needed.
  • MacOs: an X server is available but must be manually lauched (X11).
  • Windows: no X server are available by default. One must download the software X-WIN32 from core web site.

Once your X windows server is up and running you can add the ”-X” option to the ssh login command so to have access to windowed software. Be careful: display are thought the network and hence are slower than on the server screen. Example:

ssh -X ipal-server2

Then you can lauche a gnome program like:

gnome-system-monitor&

NB: the character ”&” is used to put this program on the background of your shell.

Copy between two Unix machines

The command to use is normally:

scp

This means “secure copy”. For copying directories uses the option ”-r”. See manual for more details. Important: one must have the right to read the source and to write the destination. Example: copy the whole SHARE directory from one machine to location /home/ipal on ipal-server2 machine, under the user name “chevalet”.

scp -r SHARE chevalet@ipal-server2:/home/ipal

WARNING: progress meter is display for each file and can slowdown the transfer of a lot of small files.

An automatic backup

Backing up a server is mandatory for a safety usage. Nowadays as disks are not expensive, using external disk is a simple backup solution. This external disk should have the exact size of the disk to be backup.

In a Unix system on need two command:

  1. an incremental copy command to save the changed files.
  2. an daemon that execute the backup automatically.

The command to use for the incremental copy is “rsync”. The deamon that execute any script is called “cron”.

This is a simple example of script that do a backup. This script should be put in an accessible location like ”/root/bin”.

#/bin/sh

# This is the path where the backup disk should be mounted
dest=/media/usbdisk1
# email adress to send in case of error
email="chevalet"
# Check if the disk is mounted
mounted=`df -a|grep $dest`
if [ "$mounted" ]
then
# Do the backup
/usr/bin/rsync -a --delete /home/ipal/ $dest/ipal/
else
# Disk not mounted: send an email
now=`date`
/bin/mail -s "Cannot do backup" $email <<-EOF Message from $0
The disk $dest is not mounted in $HOSTNAME.
Backup not done at $now.
EOF
fi

Then to activate this script, use the command:

crontab -e

Then one can add the automatic launch of the script every day at 1AM using the line below, providing the script is named “backup.sh” and is located at ”/root/bin”.

00 01 * * * /root/bin/backup.sh>>/var/log/backup.log

The output is automatically added to the log file backup.log.

Change the system hostname

The hostname is managed by the network administrator. It enable to automatically associate the name of the machine to an IP address and alleviates the necessity to remember the IP number. On the machine the hostname has to be changed manually by modifiying the file /etc/hosts.

See also : http://www.cpqlinux.com/hostname.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: