Answer the question
In order to leave comments, you need to log in
What could be wrong with the script?
Good day.
There is a task to automate Mikrotik backups. I found a script on the net that should help me with this task.
#/bin/bash
routers=( 192.168.0.1 )
backupdir="/root/mikrotik/"
privatekey="/root/.ssh/id_dsa"
login="admin"
DATE="`date '+%Y-%m-%d'`"
for r in ${routers[@]}; do
cmd_backup="/system backup save name=${r}.backup"
ssh ${login}@$r -i $privatekey "${cmd_backup}" > /dev/null
sleep 2
cmd_backup="/export file=${r}"
ssh ${login}@$r -i $privatekey "${cmd_backup}" > /dev/null
sleep 5
scp -i $privatekey ${login}@${r}:${r}.backup ${backupdir}$r-$DATE.backup
scp -i $privatekey ${login}@${r}:${r}.rsc ${backupdir}$r-$DATE.rsc
ssh ${login}@$r -i $privatekey "/file remove \"${r}.backup\""
ssh ${login}@$r -i $privatekey "/file remove \"${r}.rsc\""
done
find $backupdir* -mtime +3 -exec rm {} \;
[[email protected] ~]# ./backup_mikrotik
'/backup_mikrotik: line 7: syntax error near unexpected token `do
'/backup_mikrotik: line 7: `for r in ${routers[@]}; do
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question