Re: shell expansion (globbing) from inside php cli script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brian V Bonini wrote:
I tried that too. I get '/{a,s,d,f\}' in the string if I use it that way.
Are you saying that you were able to do a succesful transfer using the
above? I can output a string that SHOULD work, e.g. "scp
joe@xxxxxxxxxx:/dir/{file1,file2,file3} /dir/." but when run from within a
php script it does not expand the stuff inside the braces. Instead it's
looking for a file literally named '{file1,file2,file3}' rather than
/dir/file1, /dir/file2, /dir/file3, etc. If you just echo the string it
will appear well formed, but try to actually use it and it will not work,
at least not for me.

-Brian

Brian,

The script works for me, I should have included the screen input/output, which now follows:

[root@bmw ~ 1]# ls -l /tmp/file*     ## Location of original files
-rwxrwxrwx  1 root root 5 Jun 28 22:15 /tmp/file_A
-rwxrwxrwx  1 root root 5 Jun 28 22:15 /tmp/file_B
-rwxrwxrwx  1 root root 5 Jun 28 22:15 /tmp/file_C
[root@bmw ~ 2]#
[root@bmw ~ 2]# ls -l /tmp/test/    ## Location of copied files
total 0
[root@bmw ~ 3]#
[root@bmw ~ 3]# /var/www/html/test_script01.php ## Executing my test script
root@xxxxxxx's password:
string: scp root@xxxxxxx:/tmp/{file_A,file_B,file_C\}  /tmp/test
status:0
Array
(
)
[root@bmw ~ 4]#
[root@bmw ~ 4]# ls -l /tmp/test/    ## Files have been copied
total 12
-rwxr-xr-x  1 root root 5 Jun 29 09:36 file_A
-rwxr-xr-x  1 root root 5 Jun 29 09:36 file_B
-rwxr-xr-x  1 root root 5 Jun 29 09:36 file_C
[root@bmw ~ 5]#
[root@bmw ~ 5]# php -v              ##  My PHP version
PHP 4.3.11 (cli) (built: May 31 2005 11:29:57)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
[root@bmw ~ 6]#

Also I am running on Fedora Core 1.

While running my tests I found that any whitespace within the brackets would cause a failure. If you run your script with "scp -v " you can see each file being copied (or not copied). Here's my output, NOTICE THAT THE $cmd STRING ECHOED BY THE COMMAND LINE SHELL IS DIFFERENT FROM THE PHP SCRIPT'S ECHO!!!! Hope there is something here that helps you.
-- Bob

[root@bmw ~ 6]# /var/www/html/test_script01.php  ## With scp -v flag
Executing: program /usr/local/bin/ssh host bmw.com, user root, command scp -v -f /tmp/{file_A,file_B,file_C}
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
debug1: Reading configuration data /usr/local/etc/ssh_config
debug1: Applying options for *
debug1: Connecting to bmw.com [127.0.0.1] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Remote protocol version 1.99, remote software version OpenSSH_3.9p1
debug1: match: OpenSSH_3.9p1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_3.9p1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'bmw.com' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:17
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
root@xxxxxxx's password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending command: scp -v -f /tmp/{file_A,file_B,file_C}
Sending file modes: C0777 5 file_A
Sink: C0777 5 file_A
Sending file modes: C0777 5 file_B
Sink: C0777 5 file_B
Sending file modes: C0777 5 file_C
Sink: C0777 5 file_C
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.3 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0
string: scp -v root@xxxxxxx:/tmp/{file_A,file_B,file_C\}  /tmp/test
status:0
Array
(
)
[root@bmw ~ 7]#

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux