Trouble in passing variable to flash

I want to pass the current login username from php to flash. So I have written the following code.
PHP Code:
<?php
    require_once('C:\xampp\htdocs\moodle\config.php');
    $r=$USER->username;
   echo "val=$r";
?>
Actionscript code
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
var myRequest:URLRequest=new URLRequest("http://localhost/moodle/identity.php");
myLoader.load(myRequest);
myLoader.addEventListener(Event.COMPLETE,onCompleteHandler);
var myValue: String;
function onCompleteHandler(e:Event):void{
          var myvariable: URLVariables = new URLVariables(e.target.data);
          myValue = myvariable.val;
               trace(myValue);
There is no error message from both php and actionscript. But I can't see the variable myValue in actionscript. Then I type localhost/moodle/identity.php and I can retrieve the correct login username.But it cannot be passed to flash.
why is that?

Most probably there are spaces before val in PHP - trim spaces either in PHP or once you load them.
To trim spaces in AS3 use:
var data:String = String(e.target.data).replace(/\s/g, "");
var myvariable:URLVariables = new URLVariables(data);

Similar Messages

  • AS3.0 External Interface: Pass variables to flash using javascript

    Hello all,
    I am looking for a simple and straightfoward example of how I can pass the value of a variable into flash using javascript.
    Specifically, I'd like to use javascript to pass the filename of an external video file that I would like to load into my flash movie.
    I'd also like to call a function in the SWF that plays the movie once the filename as been passed to the flash movie.
    External Inferface looks like the way to go.
    I've found a few decent AS2.0 examples, but converting them to AS3.0 has proven difficult and many of the examples are much too complex for what I am trying to do.
    If you have any code samples or tutorials showing the HTML/Javascript and the associated actionscript I'd really appreciate it!
    Thanks!
    Tim

    if you create a swf (eiTest.swf) and html:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
        <head>
            <title>eiTest</title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <script language="JavaScript">
             function thisMovie(movieName) {
             if (navigator.appName.indexOf("Microsoft") != -1) {
                 return window[movieName];
             } else {
                 return document[movieName];
         function f1(value) {
             thisMovie("eiTest").jsF(value);
    </script>
        </head>
             <body onload="f1('yourfilename.ext');">
         <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
                 id="eiTest" width="550" height="400"
                 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
             <param name="movie" value="eiTest.swf" />
             <param name="quality" value="high" />
             <param name="bgcolor" value="#869ca7" />
             <param name="allowScriptAccess" value="sameDomain" />
             <embed src="eiTest.swf" quality="high" bgcolor="#869ca7"
                 width="550" height="400" name="eiTest" align="middle"
                 play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
                 type="application/x-shockwave-flash"
                 pluginspage="http://www.macromedia.com/go/getflashplayer">
             </embed>
         </object>
        </body>
    </html>
    you can use:
    import flash.external.ExternalInterface;
    ExternalInterface.addCallback("jsF", asF);
    function asF(fileS:String):void{
    trace(fileS);

  • Can Captivate pass variables to Flash?

    I have a Captivate 4 quiz embedded in a .FLA (AS2).  Can this quiz pass user-defined and/or system variables to the .FLA?  If so, can someone give me an example code of how this would work?  Let's say I have a user-defined variable in Captivate, varTest with initial value of 0.  On the last slide of the quiz I assign varTest a value of 1.  How do I pass this variable to Flash and how will Flash listen for this value change?  I'm looking for something similar to the following code, but I can't seem to get all of it:
    //code that loads movie here; I have this piece working fine.
    //code that listens for varTest1 value in Captivate
    myListener = function():Void
         var myFlashVar = this.mc_Container.varTest //I load my captivate SWF into mc_Container
         if(myFlashVar == 1)
              trace("myFlash Var = 1")
    some listener code here...
    Thanks.

    samprakash,
    You are going into difficult territory.
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=464&threadid=1325387
    There is no solution other than a custom solution, likely
    involving many days and hours of work. If you must do this, you can
    begin by analyzing the swf files for variables while in-use (loop
    through the Captivate swf mc object).

  • CF pass variables to Flash

    Hello:
    Basically I want Coldfusion to pass the server date to Flash.
    But I get '#theDt#' instead of the value of 'theDt' please see the
    code below:
    Thank you in advance.
    theDate.cfm
    <cfsetting enableCFoutputOnly="Yes">
    <cfset theDt = dateFormat(now(), 'mm-dd-yyyy')>
    <cfoutput>
    &serverDate=#theDt#
    </cfoutput>
    var my_lv:LoadVars = new LoadVars();
    my_lv.onLoad = function(success:Boolean) {
    if(success) {
    theDate.text = my_lv.serverDate;
    //theDate.text = this['serverDate'];
    //theDate.text = this.serverDate;
    } else {
    var localDate:Date = new Date();
    theDate.text =
    (localDate.getMonth()+1)+"/"+localDate.getDate()+"/"+localDate.getFullYear();
    my_lv.load("C:\\CFusionMX7\\wwwroot\\OC\\theDate.cfm");
    ***************************************************************

    my_lv.load("C:\\CFusionMX7\\wwwroot\\OC\\theDate.cfm");
    You are not "executing" a CF page, just reading the content.
    The route should be something like (if you are testing in
    your machine) :
    my_lv.load("
    http://127.0.0.1//OC//theDate.cfm");
    or the URL corresponding (and the webserver must be configured to
    execute CF pages)
    Regards

  • Pass Variables into Flash from URL

    I have a real simple request for some reason cannot pull it
    off. I have a url that looks like this:
    http://mywebserver/directory1/directory2/webpage.html?name=Mark
    I am trying to pull the variable "mark" into a swf. The URL
    will change depedning on the user and I plan on adding additional
    variables as well (lastname, state, age, etc).
    Easy answer to this? If so, please excuse my ignorance. I use
    actionscript 2 but would consider myelf a novice as I am more into
    design.

    Using FlashVars would work, as would SWFObject - which is
    what I'd use. Glad
    yout got it though.
    Dave -
    www.offroadfire.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • Passing variables from php to flash and the opposite

    Hi guys, im trying weeks now to solve this problem but nothing yet
    If someone could just tell me how to pass variables from flash to php and the opposite i would be thankful!!! Please help!

    I have recently had to learn this, so this may not be the best way but it worked for me
    I suggest looking at the code below stripping out everything you don't need (e.g. the databse stuff) and just get a simple string going back and forward
    have a go and post any problems here and I'll try and help
    in flash i have
    private function getBalanceAndXP():void
              var request:URLRequest = new URLRequest("utils.php");
              request.method = URLRequestMethod.POST;
              var variables:URLVariables = new URLVariables();
              variables.func = "getBalance";
              variables.fbid = userID;
              request.data = variables;
              var loader:URLLoader = new URLLoader();
              loader.dataFormat = URLLoaderDataFormat.VARIABLES;
              loader.addEventListener(Event.COMPLETE, onBalanceComplete);
              loader.load(request);
    private function onBalanceComplete(e:Event):void
              var loader:URLLoader = e.target as URLLoader;
              loader.removeEventListener(Event.COMPLETE, onBalanceComplete);
              var variables:URLVariables = new URLVariables(loader.data);
              _balance = parseInt(variables.balance); // class variable
              _experience = parseInt(variables.experience); // class variable
    public function setBalanceAndXP(balance:int, experience:int):void
                _balance = balance;
              _experience = experience;
              var request:URLRequest = new URLRequest("utils.php");
              request.method = URLRequestMethod.POST;
              var variables:URLVariables = new URLVariables();
              variables.func = "setBalance";
              variables.fbid = userID;
              variables.balance = _balance;
              variables.experience = _experience;
              request.data = variables;
              var loader:URLLoader = new URLLoader();
              loader.dataFormat = URLLoaderDataFormat.VARIABLES;
              loader.load(request);
    and then I have my php file
    <?php
    $func = $_POST["func"];
    $fbid = $_POST["fbid"];
    $balance = $_POST["balance"];
    $experience = $_POST["experience"];
    $numVariables = 0;
    $link = mysql_connect("localhost","username","password");
    mysql_select_db("databaseName");
    if ($func == "getBalance")
              getBalance($fbid);
    else if ($func == "setBalance")
              setBalance($fbid, $balance, $experience);
    mysql_close($link);
    function getBalance($fbid)
              $query = "SELECT balance, experience FROM tableName WHERE fbid = '".$fbid."'";
              $result = mysql_query($query);
              $row = mysql_fetch_row($result);
              writeVariable("balance", $row[0]);
              writeVariable("experience", $row[1]);
    function setBalance($fbid, $balance, $experience)
              $query = "UPDATE tableName SET balance = ".$balance.", experience = ".$experience." WHERE fbid ='".$fbid."'";
              mysql_query($query);
    function writeVariable( $name, $value )
              global $numVariables;
              if ( $numVariables > 0 )
                        echo "&";
              echo $name . "=" . urlencode($value);
              $numVariables++;
    ?>

  • Passing variables from AS3 to PHP

    Hi there
    I am having some trouble in passing variables from AS3 to PHP. I am using flash and php both in the same file [try.php].
    I've stuck with this for two days.. Here's what I have done. Please help!!!
    header.fla [Actionscript in the timeline]
    stop();
    import flash.events.Event;
    import flash.display.Sprite;
    import flash.net.*;
    var url:String = "http://localhost/0000/try.php";
    var req:URLRequest = new URLRequest(url);
    var loader:URLLoader = new URLLoader();
    var variables:URLVariables = new URLVariables();
    send_btn.addEventListener(MouseEvent.CLICK, sendForm);
    function sendForm(evt:MouseEvent):void
        // add the variables to our URLVariables
        variables.asd = "value";
        // send data via post
        req.method = URLRequestMethod.POST;
        req.data = variables;
        loader.dataFormat = URLLoaderDataFormat.TEXT;
        // add listener
        loader.addEventListener(Event.COMPLETE, onLoaded);
        loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        //send data
        loader.load(req);
    function onLoaded(evt:Event):void
        var result_data:String = String(loader.data);
        if (result_data)
            trace(result_data);
        else if (!result_data)
            trace("error");
    function ioErrorHandler(event:IOErrorEvent):void
        trace("ioErrorHandler: " + event);
    try.php
    <body>
    <object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="563" height="280">
      <param name="movie" value="header.swf" />
      <param name="quality" value="high" />
      <param name="wmode" value="opaque" />
      <param name="swfversion" value="6.0.65.0" />
      <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
      <param name="expressinstall" value="../Scripts/expressInstall.swf" />
      <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="header.swf" width="563" height="280">
        <!--<![endif]-->
        <param name="quality" value="high" />
        <param name="wmode" value="opaque" />
        <param name="swfversion" value="6.0.65.0" />
        <param name="expressinstall" value="../Scripts/expressInstall.swf" />
        <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
        <div>
          <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
          <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
        </div>
        <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
    <?php
    if($_POST['asd'])
    echo "value of var1 is <b>".$_POST['asd']."</b>";
    else
    echo "bad luck";
    ?>
    </body>
    BIG THANKS!!

    the problem is nothing your showed.   did you see a security warning that you ignored?
    to test, if that's the problem go here and adjust your security settings:  http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.ht ml
    if that fails, upload your files to a server and confirm everything works.  then start working on your local configuration.

  • Cannot pass variables from PHP to actionscript 3.0

    I am using CS3 and I write the following code as to pass variable to flash from PHP
    Actionscript
    var myLoader:URLLoader = new URLLoader();
    myLoader.dataFormat = URLLoaderDataFormat.TEXT;
    var myRequest:URLRequest=new URLRequest("http://localhost/moodle/value.php");
    myLoader.load(myRequest);
    myLoader.addEventListener(Event.COMPLETE,onCompleteHandler);
    var myValue: String;
    function onCompleteHandler(e:Event):void{
              var myvariable: URLVariables = new URLVariables(e.target.data);
              myValue = myvariable.values;
                      trace(myValue);
    PHP file
    <?php
       echo ('values = 8');
    ?>
    But I always get the error and cannot get the values by using trace();
    Before i try to use "myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;" I still get the same error.
    Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs
              at Error$/throwError()
              at flash.net::URLVariables/decode()
              at flash.net::URLVariables$iinit()
              at flash.net::URLLoader/flash.net:URLLoader::onComplete()
    Can anyone help me?

    The error is fixed.The new version is like that
    Actionscript
    var myLoader:URLLoader = new URLLoader();
    myLoader.dataFormat = URLLoaderDataFormat.TEXT;
    var myRequest:URLRequest=new URLRequest("http://localhost/moodle/value.php");
    myLoader.load(myRequest);
    myLoader.addEventListener(Event.COMPLETE,onCompleteHandler);
    var myValue: String;
    function onCompleteHandler(e:Event):void{
              var myvariable: URLVariables = new URLVariables(e.target.data);
              myValue = myvariable.values;
                      trace(myValue);
    php file
    <?php
       echo "values=8";
    ?>
    The output finally is "null" in flash file. Why does it happen? It should give me 8 when I input trace(myValue);

  • LoadVars-using send to pass a variable from flash to php

    For the life of me, I've tried everything:
    I've researched LoadVars on Adobe forum, used David Powers'
    books, googled 'flash to php', LoadVars, etc. and tried
    sendAndLoad, send, and using $_POST, $_GET, $_REQUEST.
    $HTTP_POSTVARS but I keep getting this same error. any advice
    please?
    I have a Unix server running Apache/PHP 4 - LoadVars worked
    to load name-value pairs into an array -see thread)
    My goal with this simple app is to prototype being able to
    pass a variable from flash to a variable in php.
    Parse error: syntax error, unexpected T_VARIABLE in
    flash_to_SQL.php on line 5
    Actionscript 2.0 code:
    var c :LoadVars = new LoadVars();
    c.testing = "123FOUR";
    c.send ("
    http://127.0.0.1/flash_to_SQL.php","_self","POST");
    php code: (I also tried $_POST, $_GET, $_REQUEST.
    $HTTP_POSTVARS)
    <?php
    //mysql 4.1.2, php 4 , NO mysqli
    ecbo $_REQUEST ['testing'];
    /?>

    var formData:LoadVars = new LoadVars();
    formData.fname = "Name";
    formData.send("
    http://www.website.com/flash_php.php",
    formData, "POST");
    <?php
    $name = $_POST['fname'];
    echo $name;
    ?>

  • Passing variable threw the url to flash

    Is it possible to pass variables to a flash obect threw the
    url and how would the url look?
    something like this?
    http://critcore.wisc-online.org/cri...ml?Objectid=183
    then I would request the objectid in flash using send and
    load? Or how would I retrieve that?
    Thanks for your help I appreciate it

    it would look like:
    http://www.yoursite.com?theVariable1=var1&theVariable2=var2
    in flash you just access it with _level0 ie:
    trace(_level0.theVariable1);
    trace(_level0.theVariable2);

  • Passing variable from php into flash, help please

    Here are what I'm having:
    <?PHP
    $testVal = "This is a test";
    $test = urlencode($testVal);
    $out = "test=". $testVal;
    echo $out;
    ?>
    // and this is my flash file
    function getData() {
    // Prepare request
    var urlReq:URLRequest=new URLRequest("http://localhost/test.php");
    urlReq.method=URLRequestMethod.GET;
    var loader:URLLoader = new URLLoader();
    loader.dataFormat=URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, completeHandler);
    loader.load(urlReq);
    function completeHandler(evt:Event) {
    var vars:URLVariables = URLVariables(evt.target.data);
    trace(" TEST = ", vars.test);
    trace(" TEST = ", unescape(vars.toString()));
    // and below is the ouput
    TEST = undefined
    TEST = test=This is a test
    I've tried with several different ways to get ONLY the value of the variable - that means I only want to have "This is a test" returned, but I either got "undefined" or the whole thing "test=This is a test", instead.
    I'm new to Flash and PHP. Please help.
    Thanks

    There's no need to write any fake variables out, Flash does not need that. OK, here's a simple PHP script like yours - I called it test.php
    <?PHP
         $testVal = "This is a test";
         $out = "test=". $testVal;
         echo $out;
    ?>
    And the AS to call it:
    var myLoader:URLLoader = new URLLoader();
    myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
    myLoader.load(new URLRequest("http://www.mydomain.com/test.php"));
    myLoader.addEventListener(Event.COMPLETE, dataLoaded, false, 0, true);
    function dataLoaded(e:Event){  
        trace( e.target.data.test);
    You will see 'This is a test' traced to the output window.
    HTH

  • Passing variable trouble

    I have created a few arrays in a frame and am trying to pass
    a variable from the main array to choose a second array by passing
    a variable using a function after a button is clicked. I use this
    code to select the name of the new array:
    _root.m1[name].menuTwoID = homeMenu
    [0];
    from this array
    var homeMenu:Array = [["residential", "resMenu"],
    ["commercial", "comSubMenu"],.....
    That should produce a passed variable "resMenu" correct?
    It doesn't work later later in a new function when I put it
    into:
    _root.m2[name].main_text.text = menuTwoID[count-1][0];
    to get the names from the second array.
    If I put "resMenu" directly in the code (below) it works
    fine.
    _root.m1[name].menuTwoID = resMenu;
    Any ideas of what I'm doing wrong?
    Thanks

    Here's an example of the idea:
    I create a menu and when it's clicked try to use the
    menuTwoID to pass the name of the new array to create a new sub
    menu. But that doesn't work. Is it that's it's a string and not an
    array?
    var AllColors:Array = [["reds", "colorsOne"], ["blues",
    "colorsTwo"]];
    var colorsOne:Array = [["Fire Engine", "colors1a"],
    ["Sunset", "colors1b"]];
    var colorsTwo:Array = [["Sky Blue", "colors2a"], ["Cyan",
    "colors1b"]];
    function buildAllColors() {
    var spacing:Number = 20;
    for (var i = 0; i < 2; ++i) {
    var name:String = "flipper" + i + "_mc";
    var y:Number = i * spacing;
    _root.m1.attachMovie("flipper", name, i);
    _root.m1[name]._x = 0;
    _root.m1[name]._y = y;
    _root.m1[name].main_text.text = AllColors
    [0];
    _root.m1[name].menuTwoID = AllColors[1];
    _root.m1[name].item_btn.onPress = function () {
    itemClicked (this._parent.menuTwoID);
    for (var i = 0; i < 2; ++i) {
    _root.m1["flipper" + i + "_mc"].flipper_bg._alpha = 50;
    this._parent.flipper_bg._alpha = 100;
    buildAllColors();
    function itemClicked (menuTwoID:String){
    var spacing:Number = 20;
    for (i=0; i<2; i++){
    var y:Number = i * spacing;
    var name:String = "flipper" + i + "_mc";
    _root.m2.attachMovie("flipper", name, i);
    _root.m2[name]._x = 0;
    _root.m2[name]._y = y;
    _root.m2.attachMovie("flipper", name, i);
    _root.m2[name].main_text.text = menuTwoID
    [1];
    stop();

  • Still having trouble passing variables

    So, I read some on the MVC as my problem in my previous post
    was trying to pass variables between classes in the same package.
    I've got three classes, ListLoader, SectionPanel and TagWidget...
    MVC respectively. Or at least I think I've set them up that way.
    ListLoader is responsible for querying the db via PHP when
    TagWidget asks it to and then supplies a string variable. I'm
    trying to get TagWidget to pass that variable to the
    viewer/SectionPanel to display in a textfield but can't seem to get
    ListLoader to reflect that. Now, the problem is in how I've
    formatted ListLoader, I believe so I'll only show that class and
    just know that TagWidget is calling the variable using
    "trace(loadFTPList.fulllist);" where loadFTPList is the instance
    name of ListLoader. What am I doing wrong?
    Here is my class in question:

    You want to dispatch the event after fulllist is ready.
    If you do this:
    this.dispatchEvent(event.clone());
    fulllist = record;
    the event is dispatch before fulllist can be properly read,
    so your listener
    (whatever that may be) will find and empty/null/undefined
    list.
    but if you do this:
    fulllist = record;
    this.dispatchEvent(event.clone());
    then in your listener
    myListLoader.addEventListener(Event.COMPLETE, myListHandler);
    function myListHandler(evt:Event){
    if(evt.type == Event.COMPLETE)
    // the list is ready
    trace(ListLoader(event.target).fulllist);

  • How? Flex pass variables or call function in SWF

    Dear All:
    I am new in Flex.
    But I stuck with a problem for weeks.
    I wish to communication between Flex and Flash(swf).
    I tried to pass variable from Flex to Swf. (Call function in Swf also pass variables)
    I did some tourital on google by using SWFLoader, which works fine.
    BUT the AS code in SWF must in MAIN FRAME.
    I need put my AS code by using DOCUMENT CLASS.
    BUT when I using Document class, the method is not working.
    The flex cannot find function in Flash.
    PS.I already set main.as class as public
    Hope some one can give some hint.
    I really get a huge headache.
    Many thanks,
    Henry

    myIP wrote:
    > or perhaps more ideal;
    >
    > for(var sVar in flashVars)
    > {
    > i++;
    > //var mcName = sVar.substr(0,3);
    >
    > // create the MCs:
    > duplicateMovieClip(_root.testBut,"medium"+sVar,i);
    > _root["medium"+sVar].testText.text=sVar;
    > _root["medium"+sVar].mcName = sVar.substr(0,3);
    >
    >
    > // assign the function to each created MC:
    > _root["medium"+sVar].onRelease = function()
    > {
    > trace(this.mcName)
    > _root[mcName]._x=0;
    > }
    > }
    >
    thanks but this does not work.
    I think that the problem is that the variables defined in the
    for loop do not exist in the scope of
    the function.
    when the MC is clicked, and the onRelease function says:
    _root[mcName]._x=0;
    the variable "mcName" is empty.
    seb ( [email protected])
    http://webtrans1.com | high-end web
    design
    An Ingenious WebSite Builder:
    http://sitelander.com

  • How to pass variable to SQLPLUS in a ksh script?

    Hi,
    I am writing a ksh script which will use sqlplus to run a sql and pass 2 variables as the SQL request. In the ksh script, I have 2 variables which are $min_snap and $max_snap holding 2 different numbers.
    Inside the same script, I am using SQLPLUS to run an Oracle SQL script, which request to enter 2 set of numbers, one at a time. Normally running situation, I can enter the number from the keyboard, but since I am writing a script, I want to pass those numbers by passing variables in the script? How can I do it?
    Please help!
    here is my ksh script,
    #!/bin/ksh
    if [ "$1" = "" ]
    then
    echo "Usage : delete_snapshot.sh <db_name>"
    exit
    fi
    export ORACLE_BASE=/oracle1/app/oracle
    export ORACLE_PATH=.:/oracle1/app/oracle/product/8.1.7/tune
    export ORACLE_HOME=/oracle1/app/oracle/product/8.1.7
    export ORACLE_RDBMS=$ORACLE_HOME/rdbms/admin
    export ORACLE_SID=$1
    curr_time=`date +"%m/%d/%y %H:%M:%S"`
    log_file=/home/mdbtuner/stats/sppurge/log/{$ORACLE_SID}_`date +"%Y%m%d"`.log
    #echo $log_file
    echo "****** Delete Snapshot for $ORACLE_SID at $curr_time ******" >> $log_file
    #echo "****** Delete Snapshot for $ORACLE_SID at $curr_time ******"
    #echo $ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID
    cd /home/mdbtuner/stats/sppurge
    $ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID << EOF > $min_snap
    @min_snapid.sql
    exit;
    EOF
    $ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID << EOF > $max_snap
    @max_snapid.sql
    exit;
    EOF
    echo $min_snap $max_snap
    cd $ORACLE_RDBMS
    #$ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID << EOF >> $log_file
    $ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID << !
    @sppurge
    $min_snap
    $max_snap
    exit;
    #EOF
    Thanks in advance!
    Robert
    Message was edited by:
    user168

    Thank you for response, Paul.
    Have you ever used statspack? or sppurge.sql?
    When you run $ORACLE_HOME/rdbms/admin/sppurge.sql, it waits for user to enter losnapid and hisnapid manually from the keyboard.
    My trouble is to have a script to delete old snapshot which are 3 weeks old. So I create min_snapid.sql and max_snapid.sql to hold two variables.
    Based on your solution, I tried it but it doesn't work.
    It returns the error messages as following....
    Warning
    ~~~~~~~
    sppurge.sql deletes all snapshots ranging between the lower and
    upper bound Snapshot Id's specified, for the database instance
    you are connected to.
    You may wish to export this data before continuing.
    Specify the Lo Snap Id and Hi Snap Id range to purge
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Enter value for losnapid: Using exit; for lower bound.
    Enter value for hisnapid:
    User requested Interrupt or EOF detected.
    Enter value for hisnapid:
    User requested Interrupt or EOF detected.
    WARNING: LoSnapId or HiSnapId specified does not exist in STATS$SNAPSHOT
    Enter value for hisnapid:
    User requested Interrupt or EOF detected.
    Purge of specified Snapshot range complete. If you wish to ROLLBACK
    the purge, it is still possible to do so. Exitting from SQL*Plus will
    automatically commit the purge.
    -------------------------------------------

Maybe you are looking for