Results 1 to 9 of 9

Thread: Need Help with a Bash/Perl Script

  1. #1
    Join Date
    Jun 2005
    Beans
    203
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Need Help with a Bash/Perl Script

    I basically need to write a script that will execute the following:
    metacity --replace
    wine "myprogram"
    on exit compiz --replace


    I have no problem doing the first two steps, but I'm not sure how to get it to execute the compiz --replace on exit. Any suggestions?

    -bt
    Lenovo s10 Netbook: Jaunty
    Desktop: Jaunty amd64

  2. #2
    Join Date
    Jun 2007
    Location
    England
    Beans
    760
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Need Help with a Bash/Perl Script

    Just try this:
    Code:
    #!/bin/bash
    
    metacity --replace
    wine "my program"
    compiz --replace
    When "my program" exits it will execute the next line, which is 'compiz --replace'

    Hope that helps you,
    dje

  3. #3
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Need Help with a Bash/Perl Script

    Quote Originally Posted by dje View Post
    Just try this:
    Code:
    #!/bin/bash
    
    metacity --replace
    wine "my program"
    compiz --replace
    When "my program" exits it will execute the next line, which is 'compiz --replace'

    Hope that helps you,
    dje
    that is not always the case as 'my program' could be a launcher which will then run the real application.
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  4. #4
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Need Help with a Bash/Perl Script

    I'm no expert at scripting, but I think this works. HIH.

    Code:
    #!/bin/bash
    function procnumber () {
        echo `ps ax | awk -v var=$1 '{if($1==var){printf("%d", $1)}}'`
    }
    
    metacity --replace
    wine "my program"
    PID=$!
    
    while [ "$PID" != "" ]; do
        PID=`procnumber $PID` 
        sleep 2
    done
    
    compiz --replace

  5. #5
    Join Date
    Jun 2007
    Location
    England
    Beans
    760
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Need Help with a Bash/Perl Script

    @slavik
    Yes you are correct on that although the OP did not specify what "my program" was, it may or may not work for him

    dje

  6. #6
    Join Date
    Jun 2005
    Beans
    203
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Need Help with a Bash/Perl Script

    Thanks guys. I should have played with the actual script a bit more before I posted... Turns out running wine and then replace --compiz works perfectly, but having it change over to metacity first is an issue.

    The problem is that the metacity process never ends so my wine instruction can't start. Somehow I need to run the metacity --replace independently of the other commands so that they are not waiting for the process to end before they execute.

    The reason I have to do this is because I have a game I'm running through wine that doesn't like compiz. If I just kill compiz and don't load metacity my keyboard stops working 50% of the time, but the game seems to otherwise work fine.

    unutbu, I'll try your suggestion when I get home later today.

    -bt
    Lenovo s10 Netbook: Jaunty
    Desktop: Jaunty amd64

  7. #7
    Join Date
    Jun 2007
    Location
    England
    Beans
    760
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Need Help with a Bash/Perl Script

    Try this:
    Code:
    #!/bin/bash
    
    metacity --replace &
    wine "my program"
    compiz --replace
    glad you're getting there
    dje

  8. #8
    Join Date
    Jun 2005
    Beans
    203
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Need Help with a Bash/Perl Script

    dje, that worked perfectly. Thanks again.

    -bt
    Lenovo s10 Netbook: Jaunty
    Desktop: Jaunty amd64

  9. #9
    Join Date
    Jun 2007
    Location
    England
    Beans
    760
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Need Help with a Bash/Perl Script

    No problem
    Glad you got it working

    dje

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •