Thursday, January 29, 2009

.netrc how to ?

Increase productivity with FTP autologin and macros

Posted By LinuxTitli On February 28, 2006 @ 1:24 am In Automation, Backup, CentOS, Debian Linux, Howto, Linux, RedHat/Fedora Linux, Ubuntu Linux, programming | 1 Comment
[1]

You may use many macros under office packages. However, your ftp client also supports macros. You can use ~/.netrc - user configuration file. The .netrc file contains login and initialization information used by the auto-login process and stores macros information. It resides in the user's home directory.
Turn on FTP client auto login

You need to add username and password to file ~/.netrc. Open config file using a text editor such as vi:
$ vi ~/.netrc
Append or add following lines to it:
machine ftp.myserver.com login USERNAME password PASSWORD
Save file and exit to shell prompt. Make sure, only owner can read the file:
$ chmod 0600 ~/.netrc
To connect type command:
$ ftp ftp.myserver.com
FTP Macros

Now let us say every time you connected to ftp server you would like to switch to binary mode and turn off prompt as well as go to directory /pub/data/backup/rdbms/dump/. You can create a macro to automate all these three steps:

i) Open ~/.netrc ftp configuration file:
$ vi ~/.netrc
ii) Define a macro
You need to use the following syntax:

macdef macro-name1
command1
command2

macdef macro-name2
command1
command2

Please note that each macro definition ends with a null line (consecutive new line characters in a file or carriage returns from the terminal). There is a limit of 16 macros and 4096 total characters in all defined macros. Macros remain defined until a close command is executed.

Append following text to .netrc file:

macdef FOO
bin
prom
cd /pub/data/backup/rdbms/dump/
ls

Save and close the file. Now connect to ftp server:
$ ftp ftp.myserver.com
Output:

Connected to ftp.myserver.com
220 ftp.myserver.com NcFTPd Server (licensed copy) ready.
Remote system type is UNIX.
Using binary mode to transfer files.

To execute a macro FOO type the command:

ftp> $ FOO

Output:

bin
200 Type okay.
prom
Interactive mode off.
cd /pub/data/backup/rdbms/dump/
250 "/pub/data/backup/rdbms/dump/" is new cwd.
ftp> ls

Further readings:

=> ftp command man page

Article printed from nixCraft: http://www.cyberciti.biz/tips

URL to article: http://www.cyberciti.biz/tips/increase-productivity-with-ftp-autologin-and-macros.html

URLs in this post:

[1] Image: http://www.cyberciti.biz/tips/category/linux

ubuntu administrative tools



tested on ubuntu 8.04.1

Wednesday, January 28, 2009

Linux Dictionary

http://www.tldp.org/LDP/Linux-Dictionary/html

services-admin

GNOME’s services-admin tool lets you turn services on or off as well as specify runlevels
and the actions to take. It provides a GUI on GNOME, usually accessible by choosing System
| Administration | Services. In the Services Settings window every service displays a check box that, when checked, will cause the service to start at boot time; those unchecked will not run. To turn on a service, scroll to its entry and click the check box next to it to add a check mark. To turn off a service, click its check box to remove the check mark.


NB : tested on ubuntu 8.04

update-rc.d

the update-rc.d tool is a lower tool that can install or remove run level links. it is usually used when installing service packages to create default run level links.you can use it to configure your own run levels for a service.

The update-rc.d tool does not affect links that are already installed. It works only on links that are not already present in the runlevel directories. In this respect, it cannot turn a
service on or off directly as can sysv-rc-conf. To turn off a service, you would first have to
remove all runlevel links in all the rcn.d directories using the remove option and then add
in the services you want with the start or stop options. This makes turning services on
and off using the update-rc.d tool much more complicated.


You use start and stop options along with the runlevel to set the runlevels at which to start or stop a service. You will need to provide a link number for ordering the sequence in which it will be run. Enter the runlevel followed by a period. You can specify more than one runlevel. The following line will start the web server on runlevel 5. The order number used for the link name is 91. The link name will be S91apache. Be sure to include the sudo command.

sudo update-rc.d apache start 91 5 .

The stop number is always 100 minus the start number. So the stop number for a service with a start number of 91 would be 09:

sudo update-rc.d apache stop 09 6 .

The start and stop options can be combined, like so:

update-rc.d apache 99 start 5 . stop 09 6 .

A defaults option will start and stop the service at a predetermined runlevel. This option can be used to set standard start and stop links for all runlevels. Startup links will be set in runlevels 2, 3, 4, and 5. Stop entries are set in runlevels 0, 1, and 6.

update-rc.d apache defaults

The following command performs the same operation using the stop and start options:

update-rc.d apache 99 start 2 3 4 5 . stop 09 0 1 6 .

The multiuser options will start entries at 2, 3, 4 ,5 and stop them at 1:

update-rc.d apache multiuser


To remove a service you use the remove option. The links will not be removed if the
service script is still present in the init.d directory. Use the -f option to force removal of the
links without having to remove the service script. The following removes all web service
startup and shutdown entries from all runlevels:

update-rc.d –f apache remove

To turn off a service at a given runlevel that is already turned on, you would first have to remove all its runlevel links and the add in the links you want. So, to turn off the Apache
server at runlevel 3, but still have it turned on at runlevels 2, 4, and 5, you would use the
following commands:

update-rc.d –f apache remove
update-rc.d apache 99 start 2 4 5 . stop 09 0 1 3 6 .

Keep in mind that the remove option removes all stop links as well as start ones. So you have to restore the stop links for 0, 1, and 6.


TIP: On Debian and Ubuntu you can use file-rc instead of sysv-rc. The file-rc tool uses a single configuration file instead of links in separate runlevel directories.

rcconf

see: http://www.debianadmin.com/manage-linux-init-or-startup-scripts.html

Tuesday, January 27, 2009

Sticky bit permissions

Sticky Bit Permissions

Another special permission provides for greater security on directories. Originally, the sticky
bit was used to keep a program in memory after it finished execution to increase efficiency.
Current Linux systems ignore this feature. Instead, it is used for directories to protect files
within them. Files in a directory with the sticky bit set can be deleted or renamed only by the
root user or the owner of the directory.

Using Symbols

The sticky bit permission symbol is t. The sticky bit shows up as a t in the execute position of
the other permissions. A program with read and execute permissions with the sticky bit has
its permissions displayed as r-t.
Here’s an example:

# chmod +t /home/dylan/myreports
# ls -l /home/dylan/myreports
-rwxr-xr-t 1 root root 4096 /home/dylan/myreports


Using the Binary Method

As with ownership, for sticky bit permissions, you add another octal number to the beginning
of the octal digits. The octal digit for the sticky bit is 1 (001). The following example sets the
sticky bit for the myreports directory:
# chmod 1755 /home/dylan/myreports

The next example sets both the sticky bit and the User ID permission on the newprogs directory.
The permission 5755 has the binary equivalent of 101 111 101 101:
# chmod 5755 /usr/bin/newprogs
# ls -l /usr/bin/newprogs
drwsr-xr-t 1 root root 4096 /usr/bin/newprogs