<HTML>
<HEAD>
<!-- this stylesheet will later on be added by lfparser automatically: -->
<style type="text/css">
<!--
  pre { font-family:monospace,Courier }
  p.code { width:80%; alignment:center; background-color:#aedbe8; 
        border-style:none; border-width:medium; border-color:#aedbe8; 
        padding:0.1cm ; text-align:left }
-->
</style>
</HEAD>
<BODY>

<H1>������������� ���������� ����������������� � ������� ssh � scp</H1>
<H4>ArticleCategory: [Choose a category, translators: do not translate
this, see list below for available categories]</H4>
SystemAdministration
<H4>AuthorImage:[Here we need a little image from you]</H4>
<IMG SRC="../../common/images/erdalmutlu.gif" ALT="[Photo of the Author]" WIDTH=107 HEIGHT=139>

<H4>TranslationInfo:[Author + translation history. mailto: or http://homepage]</H4>
<P>original in en <A HREF="mailto:erdal(at)linuxfocus.org">Erdal Mutlu</A>&nbsp; </P>
<p>en to ru <a href="nospam:caspar(at)pisem.net">Eugene S. Saenko</a><p>

<H4>AboutTheAuthor:[A small biography about the author]</H4>
<P>Erdal - ���� �� �������� ���������� LF. 
� ��������� ����� �� �������� ��������� ��������������� � 
<a href=http://www.linotype.com>Linotype Library</a>.
������ ������� ������� Linux � ��������������� ���, �� ����� �������� � ���������� 
������������ � ���� �����. 
</P>

<H4>Abstract:[Here you write a little summary]</H4>
���� ��� ���������� ���������������� ������� ���������� Linux/Unix ������, ��� ��������� 
����� ������� ��� ������������� ��������� ���������. � �������� ������������ ������ �� 
������ ���� ��������, ��� ��� ���������� ��������� ���� � �� ��, ��� ������� �������� �� 
������ �������. �������� �� ������������ � �������� ������������� ���� ���������. ��� 
�������� ����� ��� ������������ �������� ���������� ��������� ������������������  Linux/Unix 
������. � ���� ������ � ������, ��� ��� ����� ������� � ������� ������ ssh.
<H4>ArticleIllustration:[One image that will end up at the top of the
article]</H4>
<img src="../../common/images/illustration278.gif" width="320" height="95"
alt="[Illustration]" HSPACE=10>

<H4>ArticleBody:[The main part of the article]</H4>

<h2>��������</H2>
���� � ���, ����� ����� ������ ����������� ��������� ����� � ������� �������, ����� ������� 
� ���� � ��������� ������ �� ��������� ������� ������� ��� ��������, � ����� ��������� �� 
���� ������� ��������� ������� ����� ��������� rpm ������� ��� ��������� ��������� 
�������� �������. ������ ��� ���� ������� ��������� �� ���� ������� ��������� �������, � 
����� �������� ����� - ��������� ���������� ���� ������.    
<p>
����� ��������������� ���� ������� ���������� ��������� ����� ���������������� � ��������. 
���������� � ���������������� � �������� ��. � ������ ���� � ����� ����� (Katja and Guido 
Socher) � LinuxFocus <a href=../September2001/article216.shtml>Shell Programming</a>. 
���, �����, ����������� ������ ������ ssh, ����� ��� ssh-keygen, ssh-add, ssh, scp ���
sftp. ������� ��������� ���������� ��������� SSH ��� Linux:
<a href="http://www.openssh.org">OpenSSH</a>, 
���������� ��� ��� �����������. ������� � �������� ����������� (man pages). </p>  

<h2>������ ssh?</H2>
�������� �� ������: � ������ ���? ����� ������������ rsh-rcp ��� telnet-ftp, �� ��� �� 
�������� ��� ������������ �����, �����, ��� ��������, �, ��������, � ��������. Ssh 
������������ ���������� ����������� ����� ���� ����������� � ������������ ����. � �� 
��������� ��������� ������� ������������ ��� ������������� ���� ������������. �������� 
������ ������� ��������� (Georges Tarbouriech) 
<a href="../May2001/article202.shtml">Through the tunnel (������ �������)</a>. <br>
� ���������������� �, � �������, ����������� ������� �� ������ 
telnet/ftp.

<h2>����������� ������ � ��������� � ������� scp</h2>
����� ����������� ���� ���� �� ���������� �������� �� ��������� ��������� ����� 
��������������� ��������:
<p class="code">scp /path/to/the/file/file1 user@remote_host:/remotedir/newfile</p>
� ���� ������� ���� file1 ���������� �� ���������� �������� �� ��������� ��������� 
(remote_host ����� ���� ��� IP ��� ��� ���������� ����������) � ������� /remotedir ��� 
����� ������ newfile. �������� ����������� � �������������� ��� ������ 'user'. � ������ 
������� �������������� � ���� ������������ ����� ��������������� �����, ���� ����� 
����������. ����� �� �������� ����� ��� �����. � ���� ������ ���� ����� ���������� ��� 
������ ������. ������, ��� ��������, ��� ��� ����������� ���� ����� �������������. <br>
�������� �������� ���� ��������: ����� ����������� ���� � ���������� ���������� � 
��������� �������:
<p class="code">scp user@remote_host:/remotedir/file /path/to/local/folder/newfile</p>
�������, �����, ����� ������� ������� ������� scp. ������ ���� '-r' �� ������ ���������� 
�������� ����������. 
<p class="code">scp -r user@remote_host:/remotedir .</p>
��� ������� �������� ������� 'remotedir' � ��� ��� ����������� � ����� � ���������� 
���������� � ������� ������� ������� ��� ��� �� ������. 
<p>
<b>����������:</b> ��������������, ��� �� ��������� ���������� ����������� ����� sshd.  
</p>

<h2>��������� ����������� � ������� ssh</h2>
������ rlogin ��� telnet ����� ��������������� ����� ���������� �������� - ssh:
<p class="code">ssh erdal@helvetica.fonts.de</p>
� ����������� �� ������������ ����� ������� ��� �������� ������ ��� ������, ��� ��������� �����. � ���� ������� �� ������������ � ���������� helvetica.fonts.de ��� ������ ���������� 
������������ erdal. ������� ssh ����� ��������� �����, ������� ����� ������������ � ������������ � ������ �������������. ����������� �������� ����������� ssh.

<h2>���������� ������ � ssh</h2>
������� ����������� � ������� ssh ��������� �� ��������� ���������� �������:
<p class="code">ssh erdal@helvetica.fonts.de df -H</p>
��� ����� ������ �� ��������� ��������� �����������. �������� ���������� ����� ����� 
����������. �������� ������� (� ���� ������� 'df -H') ��� ���������� �� ��������� ����������. 
����� ������� ����� ��������� �� ����� ���������. 

<h2>����������� � ���������� ���������� ��� ������</H2>
������ ������������� �������������� �� ������ ����� ������������ ���� ������ 
(���������/�������). ��� ���� ������������� ���� ������. ���� ������� ssh-keygen, ������� 
����� ������������ ��� ��������� ������ ��� ssh:
<p class="code">ssh-keygen -b 1024 -t dsa</p>
� ��� ����� ��������� ��� ���������� �����. ��� ���������� ����� ������ �� ��, ��� � 
���������� ����� � �������� '.pub'. ����� '-b 1024' ��� ���������� ��� ������������ �����. 
���� ��� �������� �� �������, ����� ������������ �������� �� ���������. '-t dsa' ������ ��� 
������������ �����. ��������� ��������: 'rsa1' ��� ��������� ������ 1 � 'rsa' ��� 'dsa' ��� 
��������� ������ 2. � �� ������������ ������������� ������ 2 ��������� SSH. �� ���� � ��� 
���� ������ �������, �������������� ������ �������� ������ 1, ��� ���� ������� '-t rsa1' ��� 
�������� ������ ���� ������. ������ '-1' ��� '-2' �� ������ ��������� ssh �������� ������ 1 
��� 2 ��������������.
<p>
����� ��������������� ������, ��� ���� ���������� ���� ��������� ���� �� ��������� ���������. 
���������� ����� ���������� ����� ������ ���� ����������� ��� ��������� � ���� 
<br>$HOME/.ssh/authorized_keys ��� $HOME/.ssh/authorized_keys2. ������ ����������� � �� 
���������� ����� ��� ��������� ������ ���������. ��� ��������� ������ 1 ������������ 
authorized_keys, � ��� ��������� ������ 2 ������������ authorized_keys2. ���� �� ��������� 
���������� ���� ��������� ����, � ������ �� ���, ����� �� ������������ � ����� ����������, 
����� ��������� ���� ��������� ����� (passphrase), � � ������ ������, ����� �������� ������ 
���������� ������������. �� ������ ���������� ����������� � ����� ������� ������ 
�������������� �������������� �� ���������� �����, �������������� ���������������� ���� sshd. 
��� ����� <br>/etc/ssh/sshd_config � ������������ ���������, ������� ��� ���� �������� 
'PasswordAuthentication'. �������� ���� �������� �� no (PasswordAuthentication no) � ������������� sshd.</p>  
<p>
�� ����� ������� ��� ������. � ��� ���� ���������� ������ ����������� � ���������� ������ �� 
��������� ��������. �� ������������� ��������� ������ �� �� ������ ������� �� �������, �� 
��������� ����. ����� �� ������ �� ������ ����������������. ������� ����� ���� �� ������� � 
������ ������ ��������� ������, �� ��� �� ����� ������� ����. ����� �������� ������ ������ 
(key-agent) ����� �� ���� ������ � ����� ��������� ������. ssh-agent - ��� ���������, 
��������������� ��� �������� ��������� ������, ������������ ��� �������������� �� ���������� 
�����. ���� ��������� ����� ������:
<p class="code">ssh-agent $BASH</p>
� �������� ���� ��������� �����, ������� ������� ������������ 
<p class="code">ssh-add .ssh/id_dsa</p>
��� 
<p class="code">ssh-add .ssh/identity</p>
id_dsa - ��� ���� ���������� ����� DSA, � identity - ���� ���������� ����� RSA1. ��� - ����� 
������ �� ���������, ������ ��� ��������� ������ � ������� 
ssh-keygen. �������, � ��� ����� ��������� ��������� �����, ������ ��� ssh-add ������� ��� 
���� � ������ ������. ������ ����������� ������ ����� �������� � ������� �������:
<p class="code">ssh-add -l</p>  
</p>

<p>
������ ��� ����������� � �������, �������� ��� ���� � �������������� �����, ��� �� �������� 
������� ������ ������! � �������� �������������� ����������� ssh-agent. 
</p>

<p>
��� ������������� ssh-agent ��������� ���� ��������, �� ����� ������������ ������ � 
���������, � ������� �� ��� �������. ����� ������������ ssh-agent � ������ ������������ ���� 
��������� �������� ����������� ������� ������. � ������� ����� ��������� ������ ��� ������� 
������:
</p>

<pre>
#!/bin/sh
#
# Erdal mutlu
#
# ������ ssh-agent ��� ������������� � �������� ��������.

agent_info_file=~/.ssh/agent_info

if [ -f $agent_info_file ]; then
 echo "Agent info file : $agent_info_file exists."
 echo "make sure that no ssh-agent is running and then delete this file."
 exit 1
fi
                         
ssh-agent | head -2 &gt; $agent_info_file
chmod 600 $agent_info_file
exit 0
</pre>
<br><br>

<p>
����������� ���� ������ ��������� ������� ����� agent_info � �������� �������� ������������, 
� ������� ������ ����������� ssh ����� ������������. � ����� ������ ��� ������� '.ssh/'. ���� 
���� ����������, ������������ �������� �������������� � ������������� ����� � ������� 
���������� � ���, ��� ����� �����������. ���� � ������������ �� ������� ssh-agent, �� ������ 
������� ���� agent_info � ������������� ������. ������ ��������� ssh-agent � �������� ������ 
��� ������ � ���� agent_info. ��� ����������, � ����������, ����� �������������� ��������� 
ssh. ��������� ������ ������������ ��� ��������� ���� ������� � ����� ����� �������, ��� 
������ �������� ����� ����� ������ ��� � ������ � ����.   
</p>

<p>
���� ����� ������� � ����������� �� ������ ��������� � ���� ���� �����. �� ����� ���� �� 
������ ��������� ���� agent_info, ����� ������� ssh �����, ��� ���������� ��� �����:
</p>
<p class="code">source ~/.ssh/agent_info ��� . ~/.ssh/agent_info</p>
<p>� �������� ���� ����� � ������� ssh-add. ����� �������� � ���� .bashrc ��������� ����� 
���, ����� ������ ��� ��� �������� ������ ��������� ���������� ���� agent_info: 
</p>

<pre>
if [ -f .ssh/agent_info ]; then
. .ssh/agent_info
fi
</pre>

<p>
<b>��������:</b> �� ������ ����������� ���������, �� ������� ����������� ssh-agent � ������ 
�������������, ������� � ����� �����. �����, ���� ���-������ ������� ������ � ����� ������� 
������, �� ������� ������ �� ���� ��������, � �������� �� ��������� � ������� ������ 
ssh. �� ��� ���������� �������!
</p>

<h2>������</H2>
<p>
������ ���� ���������, ��� �� ���������� ���������������� ��������� �� ����� ���������� 
��������������. ���� ������� � ���, ����� ��������� ��������� ��������� ������ �� 
������������ ��������� ������ � ����������� ��������� ����� �� ��� � ���� ������. ��� ��, ��� 
����� ���������� ���������� ��������� ���������������. ��� ���� ������:
</p>

<pre>
#!/bin/sh

# ��������� � �������������� Secure SHELL � ������ SSH
# Erdal MUTLU
# 11.03.2001


##################################################################
#                     �������
##################################################################
### ����������� ������ � ������ ���������� �� ������
copy_files()
{
 if [ $files_file != "files_empty.txt" ];then
  cat $files_file | grep -v "#" | while read -r line
  do 
   direction=`echo ${line} | cut -d " " -f 1`
   file1=`echo ${line}     | cut -d " " -f 2`
   file2=`echo ${line}     | cut -d " " -f 3`
   
   case ${direction} in
      "l2r") :	### � ���������� ���������� �� ���������
          echo "$file1  --&gt; ${host}:${file2}"
          scp $file1 root@${host}:${file2}
      ;;
      "r2l") :	### � ���������� ���������� �� ���������
          echo "${host}:${file2}  --&gt; localhost:${file2}"
          scp root@${host}:${file1} ${file2}
      ;;
      *)
          echo "���������� ����������� ����������� : ${direction}"
          echo "������ ���� local ��� remote."
      ;;
   esac
  done
 fi
}

### ���������� ������ �� ��������� �����������
execute_commands()
{
 if [ $commands_file != "commands_empty.txt" ];then
  cat $commands_file | grep -v "#" |  while read -r line 
  do
   command_str="${line}"
   echo "�������� $command_str ..."
   ssh -x -a root@${host}  ${command_str} &amp; 
   wait $!
   echo "��������� $command_str OK."
  done
 fi
}

### �������-�������� (wrapper function) ��� ������� execute_commands � copy_files
doit()
{
 cat $host_file | grep -v "#" | while read -r host
 do
  echo "host=$host processing..."
  case "${mode}" in
	"1")
		copy_files
		execute_commands 
		;;
	"2")
		execute_commands 
		copy_files
		;;
	*)
		echo "$0 : ����������� ����� : ${mode}"
		;;
  esac	
  echo "host=$host ok."
  echo "------------------------------------------------------------------"
 done
}

##################################################################
### ��������� ���������� �����
##################################################################

if [ $# -ne 4 ]; then
 echo "������������� : $0 mode host_file files_file commands_file"
 echo ""
 echo "����� 1 ��� 2 "
 echo "    1 : ������� ���������� �����, ����� ��������� �������."
 echo "    2 : ������� ��������� �������, ����� ���������� �����."
 echo "���� ���� files.txt ���������� files_empty.txt �� �� �� ��������������." 
 echo "���� ���� commands.txt ���������� commands_empty.txt �� �� �� ��������������." 
 exit
fi


mode=$1
host_file=$2
files_file=$3
commands_file=$4

agent_info_file=~/.ssh/agent_info
if [ -f $agent_info_file ]; then
 . $agent_info_file
fi

if [ ! -f $host_file ]; then 
 echo "���� ������ : $host_file �� ����������!"
 exit 1
fi
 
if [ $files_file != "files_empty.txt" -a ! -f $files_file ]; then
  echo  "���� ������ : $files_file �� ����������!"
  exit 1
fi

if [ $commands_file != "commands_empty.txt" -a ! -f $commands_file ]; then
 echo  "���� ������ : $commands_file �� ����������!"
 exit 1
fi

#### ��� ����������� �����
doit
</pre>


<p>
������� ������� ������ ainstal.sh (automated installation -- ������������������ ���������) 
� ���������� ��������� ��� ��� ����������. �� ������� ���������: 
</p>
<p class="code">./ainstall.sh</p>

<table border=0 bgcolor="#aedbe8"><tr><td>
<pre>
������������� : ./ainstall.sh mode host_file files_file commands_file

����� 1 ��� 2 
      1 : ������� ���������� �����, ����� ��������� �������.
      2 : ������� ��������� �������, ����� ���������� �����.
���� ���� files.txt ���������� files_empty.txt �� �� �� ��������������.
���� ���� commands.txt ���������� commands_empty.txt �� �� �� ��������������.
</pre>
</td></tr></table>

<p>
� ������������ � ���� ����������, ���� �� �� ������ ��������� �������, ����� ��������� 
commands.txt ��� commands_empty.txt, � ���� �� ������ ���������� ������� ������, ����� 
��������� files_file ��� files_empty.txt. ������, ����, ����� ������ ��������� ��������� 
������, � � ������ ������� ������ ��������� ��������� ������.  
</p>

<p>
����� ���, ��� ���� ���������� ���������� �������, ����� ������ ��� �������������: 
�����������, �� �������� � ���� ��������� DNS ������ � ������ �� �������� ��� � ���� 
/etc/resolv.conf. ��� �������� �����������, ��� �� ���� ����� ����������� ���������� 
���� resolv.conf. � ���� ������ ������������, ��� ��� ���� �������, ��� ����������� ����� 
���� resolv.conf �� ��� ����������.<br>
������, ��� ��� ����������� - ��� ������ ������. ������� �� ��� � ���� hosts.txt. ������ 
����� ����� �����, ��� ������ ������ �������� ��� ��� IP ������ ������ �����. ��� ������:
</p>

<table border=0 bgcolor="#aedbe8"><tr><td>
<pre>
#############################################################################
#### ������ ������ �������� ���� ��� ��� IP ����� �����. ������, 
#### ������������ �� ����� # ��� ��� ���������� ������������.
#############################################################################
helvetica.fonts.de
optima.fonts.de
zaphino
vectora
#10.10.10.162
10.10.10.106
193.103.125.43
10.53.103.120
</pre>
</td></tr></table>

<p>
��� ����� �� �������, ����� ��������� ��������� ����������������� ����� ��� ������ 
�����, ������������ ��� ����������. ����� ����, ��� ����������� ����, � ������� ����� 
�������� ����� ������, ������� ���� ��������. �������� ��� ���� ��������: 
</p>

<ul>
<li>� ���������� ����� �� �����, ������������� � �����  hosts.txt. ��� ��� ��� 
��������, ������� ��� �����.</li>
<li>
� ������� �� ������, ������������� � ����� hosts.txt �� ��������� ����. ��� � ��� ������, 
����� ��� ���� �������� ��������� ����� � ������� �� ������. ��������, ��� ������������� 
�������� ������� ���������� �����������, ������� � ����� ���� � ���� ������.</li>
</ul>
<p>
�����, ������� ���� ��������, ����������� � ������ �����. ������� ������� ���� ���� 
files_file.txt. ������ files_file.txt �����: ������ ������ �������� ���������� � ����������� 
������ ������ �����. �������� ��� ����������� �����������: l2r (local to remote - � 
���������� �� ���������) � r2l (remote to local - � ���������� �� ���������). l2r - ��� ����� 
���� ���������� � ���������� ����� �� ���������. r2l - ����� ���� � ���������� ����� 
���������� �� ���������. ����� ��������� ����� ����������� ������� ��� ����� �����. ���� 
����������� ��������� ��� �����������. ������ ���� ���������� �� ������ � ������������ � 
�������� ������ �����������. ��� ����� ��� ���������� ����� ������ ���� ��������� 
�����������������, ����� ���� ����� ���������� � �������� ������� ������������ root. ��� ��� 
files_file.txt : 
</p>
<table border=0 bgcolor="#aedbe8"><tr><td>
<pre>
############################################################################
# ��������� ����� ������ : 
# - �������� ����� : l2r (localhost to remote - � ���������� ����� �� ���������) 
# � r2l (remote computer to local - � ���������� ���������� �� ���������). 
#       r2l  file1   file2 
#         �������� ����������� ����� file1 � ���������� (����� ����������� � 
#         ����� hosts.txt) ���������� �� ��������� ��� ������ file2. 
#       l2r     file1   file2 
#         �������� ����������� ����� file1 � ���������� ����� �� 
#         ��������� (����� ����������� � ����� hosts.txt) ��������� ���
#         ������ file2 
#         file1 � file2 - ��� ����� �� ��������������� ������.
#
#       ����������: ������� �������� local � remote ��������� ����������� 
#       �������� �����������.
############################################################################
l2r     resolv.conf     /etc/resolv.conf
</pre>
</td></tr></table>

<p>
��� ������, � ������� � ���� �������� ��� ���������. ������ � ������� ��� �������� � 
������ ���� files_file.txt, ������� ���������. ��� �������, �� ������� ������� ��� 
����������������. � ���� ������� �� ����� ����������� ���� resolv.conf �� ��������� 
��������� ��� ������ /etc/resolv.conf. � ���������������� ����� ����� ����������� ����� 
�� ������� ���������� � ������� ������� ����� ��������� � ������ ����� � ����������� 
����������� /etc/resolv.conf. �������, ������� ���� ���������, ���������� � ��������� ����. 
������� ������� ��� commands_file.txt. ��� ��� ���� commands_file.txt:
</p>

<table border=0 bgcolor="#aedbe8"><tr><td>
<pre>
###########################################################################
# ��������� ����� ����� : ������ ������ �������� �������, ������� ���� 
# ���������. ������ ������� ��������������� ��������.
###########################################################################
chown root.root /etc/resolv.conf
chmod 644 /etc/resolv.conf
cat /etc/resolv.conf
</pre>
</td></tr></table>

<p>
���� ������ �������� �������, ������� ������ ���� ��������� �� ������ ����������, 
������������� � ����� hosts.txt. ������� ����������� ���������������, ��� ������, ��� 
������� ����������� ������ �������, ����� ������ � ��� �����. 
</p>

<p>
������, ������ � ��� ���� ��� �����, ����������� ��� ����� �������� �������. ������������, 
��� ��������, ��� ������� �����, ������� ����������, ����� �� ���� ������: 
commands_file.txt ��� files_file.txt ������ �������������� � ������ �������. ����� �������� 
�����, ������������� � ����� files_file.txt file, � ����� ��������� ��� ������� �� ������� 
����������, ��� ����� 1. ��� ��������, ��������� �������, � ����� �������� �����, ��� ����� 
2. ������ ����� ��������� ������ � ������������ �����������, ��� ���:
</p>
<p class="code">./ainstall.sh 1 hosts.txt files_file.txt commands_file.txt</p>

<p>
��������� �����: ������ ��� ����� files.txt � ������� � files_ � �������� �������� 
������������ ���, ��������, files_resolvconf.txt. �������� �� ������� � ������� hosts.txt 
� commands.txt. 
</p>

<p>
������ ������ ����� ���������� ��������� � ����� �������. ��� ������� ��������� ��������� 
���������� ���������� �, ���� ��� �� ����� �������, ������ ��������� �� �������������. ��� 
���������� ���������� ���������� �� �������� ������������� ��������������� ����������. 
�����, ���� ���������� ���� '~/.ssh/agent_info', �� �����������. ���� ���� �������� 
���������� � ���������� � ��� ������ ssh. ���� �� �� ����������� �������, ��� �������� 
������ ������ ��� ��������� ����� �������, ��� �������� ������� ����������:). ����� ������ 
���� (hosts, files � commands) ����������� �� �������������. ����, �����, ����������� 
�������� �� files_empty.txt � commands_empty.txt. ���� �� ������� ����� ���, �� �������� �� 
������������� �� �����. � ������� ��� ����� ������� ��� ��������� ���� ������. ������ ���� 
������:
</p>

<pre>
if [ -f $host_file -a -f $files_file -a -f $commands_file ]; then
 echo "$host_file $files_file $commands_file"
 doit
else
 echo "$host_file ��� $files_file ��� $commands_file �� ����������"
 exit
fi
</pre>

<p>
� ���� ������ � ���� ������ ���� ���� ����� � �������: files_empty.txt � commands_empty.txt. 
�� � ���� �� ���� �������, ��������� � ������ ������� ������ � ����� ��������.<br>
� ����� ������������ ����� ������� 'doit'. ��� ������� ��������� ����. � ���� ������� ������� 
���� � ��������� 'cat' � 'while', ������� ��� ������� �� ������, ������������� � 
'$hosts_file', ��������, � ������������ � 'mode', ������� copy_files � execute_commands. 
����� ������� �������������� ������ ���� � �������. ���������� 'host' �������� ��� ��� IP 
����� �������� �����. <br>
������� ���������� ������� copy_files. ��� ������� ������� ���������, ����� �� ���� 
������ ��� 'files_empty.txt'. ���� ��, �� ������ �� ��������. ���� ���, �� � ������ ������  
'$files_file' ���������� 'direction', 'file1'  � 'file2' �������� ����������� �����������, 
����� ������� � ������� �����, ��������������. ����������� ������������ � ������� scp � 
������������ � ���������� 'direction'. <br>
�, �������, ������� ���������, ��� �������� ������� execute_commands. ��� ������� ������� 
���������, ����� �� ���� ������ ��� 'commands_empty.txt'. ���� ��, �� ������ �� ��������. 
���� ���, �� ������ �� ������ � '$commands_file' ����������� � ������� ssh �� ��������� 
���������� � ������� ������. ����� ������ ������� ssh ���������� ������� wait � ���������� 
'$!'. ��� ������� ������������ ��, ��� ��� ������� ����������� ������ ���� �� ������. 
������ ��������� '$!' ������������� ������������� �������� ��������� �������, ����������� � 
������� ������. <br>
��� ���-��. ������, �� ������ ��?
<p/>

<H2>������� �������������� ���������������� ������</H2>
<p>
����� ������������ ����� ������� ������������� ����� �������. ���� ������� � ���, ����� 
������� ��������� ����� ���������������� ������ ���� ����� ����������� ��� ��������. � ���� 
����� � ������� ��������� ������, ������������ ainstall.sh :
</p>

<pre>
#!/bin/sh
 
server_dir=${HOME}/erdal/sh/ServerBackups
  
if [ ! -d $server_dir ]; then
 echo "������� : $server_dir �� ����������."
 exit 1
fi
     
cd $server_dir
      
servers=ll_servers.txt
prog=${HOME}/erdal/sh/einstall_sa.sh
       
cat $servers | grep -v "#" | while read -r host
do
  echo $host &gt; host.txt
  $prog 1 host.txt files_empty.txt
  servers/${host}/commands_make_backup.txt
  $prog 1 host.txt files_getbackup.txt commands_empty.txt
  mv -f backup.tgz servers/${host}/backup/`date +%Y%m%d`.tgz
  rm -f host.txt
done
             
exit 0
</pre>
<p>
� ��� ������ ���� ������ ����������� ������� ��� ������ servers. � ���� �������� ������ 
���� ��� �����: files_getbackup.txt � ll_servers.txt. ��� ���� 
'files_getbackup.txt' :
</p>
<p class="code">
r2l /root/backup.tgz backup.tgz
</p>

<p>
'll_servers.txt' �������� ����� ��� IP ������, ������� ���������� �������������. ������� 
�����, �������������� � ����� 'll_servers.txt', ������ ��������������� ������� � ����� �� 
������, � ������� ������ ���� ���� commands_make_backups.txt, ���������� ������� ��� 
�������� ������ /root/backup.tgz �� ���������������� ������ ����� �����. � ������� ��� ������ 
backup. ��� ��������� ����� ����� ����� ����� ��������� � ���� ��������. ���� ll_servers.txt 
��������:
</p>
<table border=0 bgcolor="#aedbe8"><tr><td>
<pre>
fileserver
dbserver
10.10.10.1
appserver
</pre>
</td></tr></table>

<p>
��������� ������������ �������� '$servers' ������ ���� �����:
</p>
<table border=0 bgcolor="#aedbe8"><tr><td>
<pre>
servers
|-- files_getbackup.txt
|-- ll_servers.txt
|-- make_server_backups.sh
|-- 10.10.10.1
|   |-- backup
|   `-- commands_make_backup.txt
|-- appserver
|   |-- backup
|   `-- commands_make_backup.txt
|-- dbserver
|   |-- backup
|   `-- commands_make_backup.txt
|-- fileserver 
    |-- backup
    `-- commands_make_backup.txt
</pre>
</td></tr></table>
<p>
� ��� ��������� �������� ������ commands_make_backups.txt:
</p>

<p class="code">
tar cfz /root/backup.tgz /etc/samba /etc/atalk /etc/named.conf /var/named/zones 
</p>
<p>���� ���� commands_make_backup.txt ������������ ��� �������������� ���������������� 
������ samba, atalk � nameserver � ������ ���.</p>
<p class="code">
tar cfz /root/backup.tgz /etc/httpd /usr/local/apache
</p>
<p>���� ���� commands_make_backup.txt ������������ ��� �������������� ������������ � ������ 
������� apache.</p>
<p class="code">
tar cfz /root/backup.tgz /etc/squid /etc/named.conf
</p>
<p>���� ���� commands_make_backup.txt ������������ ��� �������������� ������������  
������-������� squid � ���������� ������� DNS.</p>
<p>
� ������� ����� ������� �� ������, ����������� ����� commands_make_backup.txt � ����� 
�����������, ������ ��������� ����� ������������ ����� ��������.
</p>

<h2>����������</H2>
������ ainstall.sh ��������� ��� ���������������� ��������� ������ ���������� 
�����������������. �� ������� �� ������� ������������� ������ ssh (ssh tools). �� ������� 
���� ������, ���� � ��� ������� ������� ���������� ���������� ������.
<H2>������</H2>
<ul>
<li>SSH, The Secure Shell: The Definitive Guide, by Daniel J. Barrett and
Richard Silverman.</li>
<li><a href="../May2001/article202.shtml">Through the tunnel</a>, by
Georges Tarbouriech.</li>
<li><a href=../September2001/article216.shtml>Shell Programming</a>,
by Katja and Guido Socher.</li>
</ul>
</BODY>
</HTML>
<!-- vim: set sw=2 ts=2 et tw=74: -->