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

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

 



On Mon, 2005-06-27 at 22:04, Bob Winter wrote:
> Brian,
> 
> Can you post more of the script?

Sure. I also tried {{$files}} and tried calling a shell exclusively like:

sh -s 'scp $user@xxxxxx'

Anyway, here's more for the code surrounding the area in question, it's a little hacked up ATM
but your get the picture. I can send the whole file to you if you think it will help. I basically
just want to be able to do '$ command {file,file1,file2}' from within a php cli script but the {} are
not expanding.

} else {
        if($argv[1] == $switches[0]) { 
                print("Do you want to push live from dev[d] or staging[s]?: ");
                $confirm = read_input();
                if(!$confirm) {
                        echo "You did not select a choice, exiting program\n";
                        exit;
                }
                if ($confirm == "s") {
                        if(!(mkdir($tmp_dir, 0777))) {
                                echo "Error: can not make temp dir for files. Please log into staging and push manually";
                                exit;
                        }
                }
                $live_servers = array("a", "b", "c");
                print("Which live servers (a=[all] b=[1-5] c=[6-13]): ");
                $which_servers = read_input();
                
                if(!in_array($which_servers, $live_servers)) {
                        echo "You must choose which live servers\n";
                        $err = true;
                        exit;
                } else {
                        switch($which_servers) {
                        case $live_servers[0]:
                                $i = 1;
                                $j = 13;
                                break;
                        case $live_servers[1]:
                                $i = 1;
                                $j = 5;
                                break;
                        case $live_servers[2]:
                                $i = 6;
                                $j = 13;
                                break;
                        default:
                                echo "An unrecoverable error has occured\n";
                                $err = true;
                                exit;
                        }
                        
                        $ii = $i; // store this so we can reset $i on each outer foreach
                        foreach($files as $directory => $file_array) {
                                $files = implode(",", $file_array);
                                if($confirm == "s") { //if staging suck the files down to temp local dir first
                                        $cmd = "scp $user@stagingcws.$tld:$directory/{{$files}} $tmp_dir/.";
                                        echo $cmd . "\n\n";
                                        exec($cmd, $output, $err);
                                        //shell_exec($cmd);
                                }
                                while (!$err && $i <= $j) {
                                        ($i < 10) ? $cname = "cwsweb0" : $cname = "cwsweb";
                                        $cmd = "scp $tmp_dir/" . '{' . $files . '}' . "$user@$cname$i.$tld:$directory/.";
                                        //echo $cmd . "\n";
                                        //exec($cmd, $output, $err);
                                        $i++;
                                }
                                $i = $ii; // reset $i to original value so loop continues
                        }
                        if(file_exists($tmp_dir)) rmdir($tmp_dir); // remove the temp dir
                        $err= true;
                }
        }



> 
> --Bob
> 
> Brian V Bonini wrote:
> > On Mon, 27 Jun 2005, [ISO-8859-1] Andr? Medeiros wrote:
> > 
> > 
> >>$cmd = 'scp ' . $user . '@stagingcws.' . $tld . ':' . $directory/{' .
> >>$files . '} ' . $tmp_dir . '/';
> >>
> >>That should work
> >>
> >>On 6/27/05, b-bonini@xxxxxxx <b-bonini@xxxxxxx> wrote:
> >>
> >>>Can not make this work inside a php script.
> >>>
> >>>Have tried several variations:
> >>>$cmd = "scp $user@stagingcws.$tld:$directory/\{$files} $tmp_dir/.";
> >>>
> >>>$cmd = "scp $user@stagingcws.$tld:$directory/" . '{' . $files . '} ' . "$tmp_dir/.";
> >>>
> >>>etc...
> >>>
> >>>I can echo out the command and get a well formed command, i.e. one that will execute from a command prompt, but when I try to exec() $cmd from within the script the globbing is taken literally.
> >>>
> > 
> > 
> > No, I already tried it that way too. I guess I should mention this is a
> > cli script if that matters.
-- 

s/:-[(/]/:-)/g


Brian        GnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu
======================================================================
gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
Key Info: http://gfx-design.com/keys
Linux Registered User #339825 at http://counter.li.org

-- 
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