Archive for the ‘Shell’ Category

Using exec on php/Windows

Saturday, September 13th, 2008

I tried to run a program with exec() but it just didn’t run. It was a program with several parameters, each parameter escaped with escapeshellarg().

It didn’t do anything, had no return value and no output. After putting a pair of extra quotes around the whole command it worked:

  1. $arg1 = escapeshellarg("first argument");
  2. $arg2 = escapeshellarg("second argument");
  3. $cmd = "C:\\do-something.bat $arg1 $arg2";
  4. exec("\"$cmd\"");

In the German php documentation I found the hint that exec() executes cmd /c with exec’s first parameter as argument. Therefore the whole command has to be quoted.

Automatic Upgrade for Multiple WordPress Instances

Thursday, August 7th, 2008

Upgrading WordPress manually is boring. But there’s a cool plugin called Instant Upgrade, you can download it on the author’s homepage zirona.com.
This is a very convenient way to upgrade wordpress with two clicks.
Update: For WordPress 2.7 this is no longer necessary, a one-click update is built in.

But I administer several WordPress installations – all on the same host. Now I have written a small script that upgrades all instances by one command. In order to work the installation must be done via svn (or moved to svn).
(more…)

Automated scp without keyfiles

Thursday, July 26th, 2007

If you need to transfer files regularly via scp and you can’t use shared keys, expect can be your solution.
Expect can control interactive programs. Just look at this easy example:

  1. #!/usr/bin/expect -f
  2. send_user "Start\r\n"
  3. spawn scp /tmp/lsgworldmap.xml user@host:/path/to/file
  4. expect password:
  5. send "secretPassword\r"
  6. expect >
  7. send_user "Ende\r\n"
  8. exit

send_user just generates a message. spawn starts a program.
expect lets expect wait for a specific output of this program, send specifies the reaction of expect. expect needs the end of the output to be correct, so in this example the triggering output could be “Please enter password:” or “Your password:”. It’s crucial that you don’t forget any whitespace characters at the end of this string.

Oh and by the way: It’s not possible to just pipe a password to scp, because it’s not read from stdin but the input is generated by scp.

Page optimized by WP Minify WordPress Plugin