Support

UNiTE, Remote CLI, eXtract Wizard

#3795 How to create windows 7 batch file to run Remote CLI commands

Posted in ‘UNiTE and Remote CLI’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

PHP version
n/a
Tool
UNiTE
Tool version
n/a

Latest post by nicholas on Thursday, 13 October 2011 16:27 CDT

user48370
Mandatory information about my setup:

Have I read the related troubleshooter articles above before posting (which pages?)? Y
Have I searched the forum before posting? y
Have I read the documentation before posting (which pages?)? y
Joomla! version: (unknown)
PHP version: (unknown)
MySQL version: (unknown)
Host: (optional, but it helps us help you) W7 Pro
Akeeba eXtract Wizard / Remote Control / SiteDiff version: (unknown)

EXTREMELY IMPORTANT: Please attach the Remote Control and Akeeba Backup log files if you are reporting an Akeeba Remote Control issue, othrewise we can not help you

Description of my issue:
I have installed PHP and remote.phar and I am able to run successfully various remote commands when I type them in to a command prompt.
When I add the commands to a .txt file and name it backup.bat (or backup.cmd) and from WITHIN THE COMMAND PROMPT invoke the bat or cmd file, all works successfully.
Howecer, I do not know how to automate this using task scheduler and identifying the backup.bat as the program to run. This .bat file needs to run from within a command prompt, and I do not know how to automate that. I am missing a step somehow. Can you assist me? I hope my problem description is clear.

nicholas
Akeeba Staff
Manager
Hi!

The only way I know of to schedule tasks on Windows 7 is using the Windows Task Scheduler, as per Microsoft's tutorial on scheduling tasks on Windows 7. If you follow this tutorial, on step 6 just browse to your .BAT file. I've tested this method on my own Win 7 laptop. Unfortunately, there is no point in me trying to produce a video tutorial on it, as my interface is in Greek and it will be hardly useful to non-Greek users :(

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

user48370
I am following the process precisely. I have a batch file "c:\users\Ted-64\desktop\backup.bat" which contains the following text:

REM The following line updates Akeeba Backup
c:\"Program Files (x86)"\PHP\php remote.phar --action=update --host=http:// --secret=
REM The following line takes and downloads a backup
c:\"Program Files (x86)"\PHP\php remote.phar --action=backup --host=http:// --secret= --download --dlmode=http --dlpath="E:\Users\Ted Levy\Documents\Clients\Hands on Homes\Akeeba backups" --delete

[obviously I am not showing the actual host and secret word]

These commands execute perfectly 1. if I copy them into a command prompt window or 2. If I copy into a command prompt windowthe following: c:\users\Ted-64\desktop\backup.bat

So there is no question of php cli or remote.phar or connectivity to the server or correct secret word or command syntax of remote CLI.

When I invoke the task scheduler I follow precisely the instructions in the link you sent me by creating a basic task which is to run a program, selecting the backup.bat batch file, and scheduling it. At the scheduled time, I am able to see a command prompt window flah open on the desktop, and then immediately it closes. The backup does not take place. Nothing happens. It is not possible to read the test in the command prompt as it closes the moment it opens, although there is clearly some text in it.

There is obviously a missing step of some kind here which I cannot perceive, in the invocation of this batch file. It only seems to work when it is invoked from within an open command window. I do not know how to use the task scheduler to create this condition.

Is my problem clear now? Please advise me if you are able to use the task scheduler as you have directed to make this work properly. I read your documentation thoroughly. In the section "Automating the whole lot" of the Walkthrough you state:

As for the batch/script file, all you have to do is to include the commands above in a .BAT (Windows) or .sh (Linux, Mac OS X) file. For example, a Windows batch file (backup.php) looks like that...

I do not understand the reference to "backup.php" as the file must have a .bat (or .cmd) extension as you indicate above.

AFter the failed scheduled task executes, the task scheduler identifies the last run result as (0x1) which is evidently some sort of error code.

I have attached the backup.bat with the actual commands for you to see.

Thanks for any additional help you can provide.

nicholas
Akeeba Staff
Manager
Hi,

There is an issue with PHAR archives running on Windows. You need to change to the directory they are stored in in order to run at all. So, your batch file should look like this:

@ECHO OFF
CD c:\users\Ted-64\desktop
REM The following line updates Akeeba Backup
c:\"Program Files (x86)"\PHP\php remote.phar --action=update --host=http://<hostname> --secret=<secret word>
REM The following line takes and downloads a backup
c:\"Program Files (x86)"\PHP\php remote.phar --action=backup --host=http://<hostname> --secret=<secret word> --download --dlmode=http --dlpath="E:\Users\Ted Levy\Documents\Clients\Hands on Homes\Akeeba backups" --delete


Note that I added two lines on top. The first one simply turns off echoing the commands, the second one is the one which makes the difference. It changes the current directory to c:\users\Ted-64\desktop which I understand is the directory where remote.phar is stored.

For testing purposes, you might want to keep the command prompt window open after the execution of the batch file to make sure that you got no errors. It's easy to do so! at the end of the batch file just add one line:
PAUSE
This instructs Windows' command prompt to display a "Press any key to continue..." message and wait for you to press a key before closing the window.

I have checked the validity of the aforementioned instructions by creating a scheduled job on my Windows 7 laptop to schedule the backup of my test site. Well, the execution just finished and it's working fine :)

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

user48370
Thank you for your excellent response. Concurrently (last night EDT) I spent several hours researching this and found a three-year long thread with many posts in social.technet,microsoft.com/forums titled "scheduled task won't run .bat file" (http://tinyurl.com/5wnv92l). There are a number of related issues and solutions proposed (perhaps 100 or more posts, mostly by frustrated systems administrators), but a great many of the problems were solved by "clarifying" to Task Scheduler in one way or another the task's context, either by making the path explicit, or specifying it in various other ways (ip or url vs. drive mapping, use of "start in" field, etc.), none of which would APPEAR to be required since the .bat (or .cmd) file was properly structured and would run "by hand" from within a command prompt.
The joys of working in an MS Windows environment!
Again, thanks for your assistance. Your support is first rate and well worth the cost.

nicholas
Akeeba Staff
Manager
Wow, I kinda feel lucky that I've never run into this kind of odd situation with Windows! Yeah, that's the infinite joys of using an MS server environment (sorry, I cringe whenever I have to put MS and server in the same sentence). I'm glad it's working now!

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!