Thursday, May 15, 2008

tasks

change system editor from vim to nano

Scripting

#!/bin/bash        
echo Hello World

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-2.html

Wednesday, May 14, 2008

Text Editors

For people coming from Windows a text editor is Notepad. In Linux you have many more choices, the top three I have run into are gedit, nano and vim. They are all three very different.

gedit is pretty close to Notepad in appearance. If you are not very comfortable operating in the terminal screen then this is the editor for you. It runs in a GUI and has menus to do everything you want. To launch it from the command line just type:

$gedit filename

nano does not run in a GUI but it does display your command choices at the bottom of the terminal window. It uses ^ to mean the Ctrl key on the keyboard. For example to save a file you would hit Ctrl+o (o is for "output"). To exit you hit Ctrl+x. To launch nano from the command line just type:

$nano
filename

vim is a favorite of old school Linux users. It is also what is used to edit crontab when you type $crontab -e and is used to display man pages. It does not display any command help so you have to know what you are doing. You can look at the man page for vim to get a lot of information, but to get started you will need to know how to open or create a file, how to edit the text, how to save and how to exit.

To open or create a file just type from the command line:

$vi
filename

If the file exists it will open it. If not it will create it. This actually works for all three editors.

To edit just start typing. In the lower left corner you will notice the word --INSERT-- appear. Hit the Insert key on the keyboard and it will change to --REPLACE--. Hit the Esc key and the corner will go blank. This is important because in order to save and exit that corner needs to be blank.

To save, make sure the corner is blank and type :w and hit enter. If the corner was blank this text will now appear in the corner. If not it will appear in the body of the text.

To exit, do the same as for saving except type :q and hit enter.
To exit without saving type :q! and hit enter.

Crazy. I don't use vim unless I absolutely have to. I typically use nano.

cron

Cron is the way you schedule tasks in Linux. It runs in the background and will execute the command you tell it to when you tell it to.

If this looks like I stole it from Linux Reality Episode 39, it is because I did. The show is great, but it is difficult to reference a podcast when you are trying to actually do something, so I have taken notes here.

Login as the user you want to run the cron job.
$crontab -e

If you want to use a different editor (nano) use the command
$EDITOR=nano crontab -e

The basic format for a crontab entry is as follows (separated by spaces)
minutes hours dayofmonth month dayofweek command
minutes range is 0-59
hours range is 0-23
dayofmonth range is 1-31
month range is 1-12
day of week range is 0-6, 0=Sunday
In order to for getmail to check mail every minute, add the following line:
* * * * * getmail
or, to check email every hour on the hour, add the following line
0 * * * * getmail
save and exit. See the section on text editors if you are not familiar with the vim text editor.

Wednesday, May 7, 2008

FTP***

http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch15_:_Linux_FTP_Server_Setup
http://winscp.net/eng/docs/introduction

NAS Backup

http://www.openmss.org/forum/viewtopic.php?f=10&t=1016#p4764

I bought a Maxtor Shared Storage II 1 TB network attached storage device. It runs a Linux operating system and comes setup with Samba which is really all you need to back up to the device.

Plug in the NAS and connect to your network. There is one predefined share on the NAS that will show up in Network Places in Windows.

The NAS will get an IP address from DHCP. In Windows open the My Network Places folder. You will be able to see the IP address of the NAS. Open a browser and type in the address. You will be looking at the configuration utility for the NAS.

Set up device name and password. I called mine maxtor1. The second one is called maxtor2.
Set up NTS
Set up TCP/IP. Assign a static IP address and add it to /etc/hosts on the DNS server.
Set up a user. You will use these credentials to connect from the server to the NAS.
Set up a share. I called mine "backup".


On the server edit /etc/samba/smbfstab to mount the network drive
Linux Reality Episode 25 had instructions on how to do this, but they didn't work exactly for me. Apparently for newer Linux kernels and versions of Samba, smbmount has been replaced by cifs. The following instructions are what I had to do for openSUSE 10.3 with Linux kernel 2.6.22 and Samba 3.0.26a.

//maxtor1/backup /home/backup cifs username=user,password=foobar -o rw

mount -t cifs \\\\maxtor1\\backup /home/backup

where
//maxtor1/backup is the share to be mounted
/home/backup is the folder to mount to
cifs is the vfstype. This can be either cifs or smbfs, but smbfs did not work for me
username and password are the username and password for the folder on the NAS
-o marks the beginning of the options section
rw makes the mount read write

IMPORTANT: smbfstab has 0600 permissions, meaning only root can read it. fstab has 0644 permissions meaning anyone can read it. This means it is OK to put the username and password in smbfstab, but if you are using fstab you will want to use the credentials option. This is well discussed in Linux Reality Episode 25.

Then either reboot or type
#mount -a

You should now have access to maxtor1 through the folder /home/backup. If you were to create a folder on the share on maxtor1 called pictures you would see it as /home/backup/pictures.

I copy data to an external drive using rsync. The rsync command line I use is

#rsync -av --delete /home/documents/ /home/backup/

-a is the archive flag and it invokes a bunch of flags that are good for archiving.
v is the verbose flag. One v will output the files that are changed, added or deleted.
--delete will delete files out of the backup set if they have been deleted from the primary data set.
type "$man rsync" for more info.


Things to do
Add rsync to cron (as root)