Tuesday, July 17, 2007

Changing the hostname to a Unix box

The following simple instructions can help you change your linux box / server hostname with ease , the first option is permanent , option number two will change the host name but changes wont be reflected after a reboot. Check it out
As described above, there are 2 ways to change the hostname of a linux box manually or by terminal ( real man do it by terminal )

This first option will save the changes even after a reboot:

Edit:

vi /etc/sysconfig/network

HOSTNAME=.

Second option:

vi /proc/sys/kernel/hostname

but that won't be saved when you reboot.

Using *nix bash to connect to an FTP

Have you been in the need of an automatic script that connects to a remote ftp server to copy some backups or something similar? There is no need to be a bash expert, the following simple example can give you the basics to have a fully functional ftp script on bash.
Yes, for any *nix user bash is definitely an usefull part of the operating system, the problem is not everybody has the proper programming basics to interact with bash and really exploit the great power you can find in unix based operating systems like linux or solaris.

The example below, is a simple script that will connect to server with ip address 192.168.2.191 and basically copy a dump file called myexample.dump into the remote location mentioned before as exampleremote.dump

Please notice you need to create a blank archive, lets call it ftpbash.ex

touch ftpbash.ex

Next use VI editor to edit the file:

vi ftpbash.ex

Now copy the following code:

#!/bin/sh
UPASSWD="myuser"
USER="mypass"
ftp -i -v -n 192.168.2.191 <
user $USER $UPASSWD
binary

send /myexample.dump /exampleremote.dump

bye

Next basically save the file ( CapsLock , then press Z twice)

Now to execute the script you need to give execution permissions to it, so type:

chmod a+x ftpbash.ex

To execute it just type ./ftpbash.ex

Please notice on the bash script we are sending both the user and password of the ftp server in order to complete the connection.You could use any valid ftp command on the script like in the example, the command send is a native ftp command, with this basic script im sure you could start a nice learning curve of the usefull features of bash, its a must know for any serious *nix programmer or administrator.