Community discussions

MikroTik App
 
bokad
Member Candidate
Member Candidate
Topic Author
Posts: 152
Joined: Tue Oct 18, 2005 7:34 pm

Script to email configuration backup

Thu Feb 18, 2010 8:38 am

I have a script that exports the current config and then e-mails it to me. This script is called from the scheduler. In v3.13 everything worked fine. In v3.28 this stopped working. The script still works when run manually but no longer works when called from the scheduler. I see from that run count that the scheduler is in fact calling the scipt but for some reason the script never creates the backup file when called from the scheduler. Any ideas?

/system scheduler
add comment="" disabled=no interval=5m name="conf exp test" on-event=\
"/system script run \"Config Export\"" policy=\
reboot,read,write,policy,test,password,sniff,sensitive start-date=\
jan/01/1970 start-time=03:00:00

In brief:
/system script run "Config Export"


/system script
add name="Config Export" policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source="\
/export file=daily_export\r\
\n/tool e-mail send to=\"me@here.org\" subject=([/system iden\
tity get name] . \" \" . [/system clock get time] . \" \" . [/system clock\
\_get date] . \" Export\") file=daily_export.rsc\r\
\n\r\
\n"

In brief:
/export file=daily_export
/tool e-mail send to="me@here.org" subject=([/system identity get name] . " " . [/system clock get time] . " " . [/system clock get date] . " Export") file=daily_export.rsc
 
bokad
Member Candidate
Member Candidate
Topic Author
Posts: 152
Joined: Tue Oct 18, 2005 7:34 pm

Re: Script to email configuration backup

Sun Feb 21, 2010 8:06 am

I'm willing to pay a consultant for help if someone has the answer...
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: Script to email configuration backup

Sun Feb 21, 2010 1:22 pm

Does it send the email if run by the scheduler? Or does it fail completely.
In the scheduler, I use just the script name in the on-event entry. Like "on-event=ConfigExport". The system scheduler knows to run it with the script interpreter.
 
User avatar
nest
Forum Veteran
Forum Veteran
Posts: 823
Joined: Tue Feb 27, 2007 1:52 am
Location: UK
Contact:

Re: Script to email configuration backup

Tue Mar 09, 2010 11:05 pm

maybe because the email is being sent before the exported file has been closed, therefore it does not send it? Try changing it two scheduled scripts, one minute apart, one to create the export, one to send it. See if it then works?
 
Rattlehead
just joined
Posts: 20
Joined: Mon Mar 01, 2010 2:09 pm

Re: Script to email configuration backup

Wed Mar 10, 2010 12:37 am

I know this is a stupid question, but does it have to be written via the CLI?
I had a huge amount of problem running and getting mine to work, but I ended using winbox and the scheduler and scripts in there, it worked pertectly
 
User avatar
nest
Forum Veteran
Forum Veteran
Posts: 823
Joined: Tue Feb 27, 2007 1:52 am
Location: UK
Contact:

Re: Script to email configuration backup

Wed Mar 10, 2010 7:16 pm

Rattlehead; I don't see anywhere here where it says you have to do this via the CLI. So of course, you can use winbox to create schedules and scripts.
 
Rattlehead
just joined
Posts: 20
Joined: Mon Mar 01, 2010 2:09 pm

Re: Script to email configuration backup

Thu Mar 11, 2010 5:10 pm

OK
Well look into Winbox
CREATE THE FILE BACKUP
System>Scripts>Add.
Call Script : "backupscript"
Policy: Choose All
in the sourcebox type :
/system backup save name=xxxxx
// This of course can be anything you want it to be
Click Apply

Click Add again
CREATE THE MAIL SCRIPT
Call Script : "mailscript"
Policy: Choose All
in the sourcebox type :
/tool e-mail send file=xxxxx.backup to=xxxx@xxxxxx.ie subject=[/system identity get name]
Click Apply

There you have your two scripts so now you need to make a schedule of these.

Again in Winbox
CREATE THE SCHEDULE TO RUN THESE ABOVE SCRIPTS
System>Scheduler>Add
Name this one "Backup&MailScript"
The time and all that you can set yourself
In the OnEvents filed type
/system script run backupscript
/system script run mailscript
Set the Policies on that to all options and apply.

There you go, mine is currently sending me backups on a daily basics at 07:30 to my work mail account. I hope this helps

Who is online

Users browsing this forum: No registered users and 11 guests