Difference between revisions of "Batch deployment of DSA key (SSH) and schedule backup with export"

From MikroTik Wiki
Jump to: navigation, search
Line 3: Line 3:
 
[[Use SSH to execute commands (DSA key login)]] shows you how to create a DSA key file.  
 
[[Use SSH to execute commands (DSA key login)]] shows you how to create a DSA key file.  
  
<pre>%ssh-keygen -t dsa</pre>
+
Make a file on your *nix host with the following content. Call the file "distr_key.sh"
 
 
This creates a DSA key pair that is compatible with Mikrotik.
 
 
 
Make a file on your *nix host with the following content. Call the fil
 
  
 
<pre>#!/bin/sh
 
<pre>#!/bin/sh
Line 18: Line 14:
 
$1 in this script is the first argument passed from command line with the script. It should be a hostname or a ip adresse.
 
$1 in this script is the first argument passed from command line with the script. It should be a hostname or a ip adresse.
  
<pre>sh distr_key.sh 192.168.10.1</pre> (make this file executible with "chmod 755 distr_key.sh" to avoid execute the shell with paramentre)
+
<pre>sh distr_key.sh 192.168.10.1</pre> (make this file executible with "chmod 755 distr_key.sh" to avoid execute the shell with parametre)
  
 
You will be prompted for the admin password twice, once for the file transfer and once for the import dsa-key command. When the script ends it will apply the hostname or ip adresse to a new file called "node_list". This file will be used later on for the backup/export script.
 
You will be prompted for the admin password twice, once for the file transfer and once for the import dsa-key command. When the script ends it will apply the hostname or ip adresse to a new file called "node_list". This file will be used later on for the backup/export script.
 +
 +
Now you create a new file on your *nix host with the following content. Call the file "backup.sh"
 +
 +
<pre>
 +
#!/bin/sh
 +
 +
dato=`date +%y%m%d`
 +
liste=`cat node_list`
 +
 +
echo Starting backup
 +
 +
for node in $liste ; do
 +
  echo Backing up $node
 +
  ssh admin@$node export > $dato\_$node
 +
done;
 +
 +
echo Finished
 +
 +
ls -l $dato*
 +
</pre>
 +
 +
Run the script file from command line with
 +
<pre>sh backup.sh</pre> or make the backup file executible with chmod like above.

Revision as of 21:56, 21 May 2008

UNDER DEVELOPMENT

Use SSH to execute commands (DSA key login) shows you how to create a DSA key file.

Make a file on your *nix host with the following content. Call the file "distr_key.sh"

#!/bin/sh

scp id_dsa.pub admin@$1:.
ssh admin@$1 "user ssh-keys import file=id_dsa.pub user=admin"
echo "$1 " >> node_list

$1 in this script is the first argument passed from command line with the script. It should be a hostname or a ip adresse.

sh distr_key.sh 192.168.10.1
(make this file executible with "chmod 755 distr_key.sh" to avoid execute the shell with parametre)

You will be prompted for the admin password twice, once for the file transfer and once for the import dsa-key command. When the script ends it will apply the hostname or ip adresse to a new file called "node_list". This file will be used later on for the backup/export script.

Now you create a new file on your *nix host with the following content. Call the file "backup.sh"

#!/bin/sh

dato=`date +%y%m%d`
liste=`cat node_list`

echo Starting backup

for node in $liste ; do
  echo Backing up $node
  ssh admin@$node export > $dato\_$node
done;

echo Finished

ls -l $dato*

Run the script file from command line with

sh backup.sh
or make the backup file executible with chmod like above.