Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Making a small script

  1. #11
    Join Date
    May 2005
    Location
    Oslo, Norway
    Beans
    467
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Making a small script

    Thanks for this!

    I now have:

    Code:
    #!/bin/sh
    
    {
    # Start with an introductory message, in case user started by mistake.
    if $(zenity --question --text="Du har startet et EasyPMP-skript.\nVil du oppdatere spilleren din?" --title="Bekreft")
    then
    
    # Enter the player directory
    cd /media/E10
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        exit echo $(zenity --error --text="/media/E10 finnes ikke.\nSjekk at spilleren er tilkoblet eller snakk med Ketil." --title="Feil")
    fi
    
    # Update player using pmplib and the "create" option. "Update"-function segfaults for some reason.
    easypmp -c
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ];then 
        exit echo $(zenity --error --text="Kommandoen easypmp -u feilet.\nAvslutter!" --title="Feil!")
    fi
    
    # Exit to home-folder. (The player will not unmount if you stay in its dir)
    cd ~
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        exit echo $(zenity --error --text="Kan ikke navigere til hjemmemappe.\nDette kan umulig stemme..." --title="Umulig feil")
    fi
    
    # Unmount the player, making it ready to unplug
    eject /media/E10
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        exit echo $(zenity --error --text="Kan ikke avmontere spilleren.\nDu må slå av maskinen før du plugger ut spilleren." --title="Feil")
    fi
    
    # Bye-message
    zenity 	--info --title "Oppdatering utført" --text "Spilleren din er nå oppdatert og klar til bruk!"
    
    fi
    }
    But when it exits, I get:
    Code:
    $ e10update2 
    cd: 40: can't cd to /media/E10
    exit: 40: Illegal number: echo
    It appears to work, although I only tried without the player, and once after
    mkdir /media/E10 to see if it got past that point (which it did).
    I'm assuming that the script is still not OK, so how do I easily output the zenity commands?

    - Ketil

    ########################################

    EDIT: See script in post #14 for the correct syntax!

    #######################################
    Last edited by kwaanens; March 14th, 2007 at 05:41 PM. Reason: Update/warning
    || My blog ||

  2. #12
    Join Date
    May 2005
    Location
    Oslo, Norway
    Beans
    467
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Making a small script

    It now works

    Here it is, if someone needs it:

    Code:
    #!/bin/sh
    
    {
    # Start with an introductory message, in case user started by mistake.
    if $(zenity --question --text="Du har startet et EasyPMP-skript.\nVil du oppdatere din iRiver E10?" --title="Bekreft")
    then
    
    # Enter the player directory
    cd /media/E10
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        exit echo $(zenity --error --text="/media/E10 finnes ikke.\nSjekk at spilleren er tilkoblet eller snakk med Ketil." --title="Feil")
    fi
    
    # Update player using pmplib and the "create" option. "Update"-function segfaults for some reason.
    easypmp -c | zenity --progress --pulsate --auto-close --title="Oppdaterer" --text="Oppdaterer iRiver E10...\nVennligst vent til operasjonen er ferdig."
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ];then 
        exit echo $(zenity --error --text="Kommandoen easypmp -u feilet.\nAvslutter!" --title="Feil!")
    fi
    
    # Exit to home-folder. (The player will not unmount if you stay in its dir)
    cd ~
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        exit echo $(zenity --error --text="Kan ikke navigere til hjemmemappe.\nDette kan umulig stemme..." --title="Umulig feil")
    fi
    
    # Unmount the player, making it ready to unplug
    eject /media/E10
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        exit echo $(zenity --error --text="Kan ikke avmontere spilleren.\nDu må slå av maskinen før du plugger ut spilleren." --title="Feil")
    fi
    
    # Bye-message
    zenity 	--info --title "Oppdatering utført" --text "Spilleren din er nå oppdatert og klar til bruk!"
    
    fi
    }
    - Ketil



    ########################################

    EDIT: Use correct syntaxed script in post #14.

    ########################################
    Last edited by kwaanens; March 14th, 2007 at 05:43 PM.
    || My blog ||

  3. #13
    Join Date
    Feb 2006
    Beans
    238
    Distro
    Ubuntu 6.10 Edgy

    Re: Making a small script

    I am surprised that code works. I think your if loops should look like this (for example):
    Code:
    cd /media/E10
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        echo $(zenity --error --text="/media/E10 finnes ikke.\nSjekk at spilleren er tilkoblet eller snakk med Ketil." --title="Feil")
        exit 1
    fi
    echo first, then exit 1 on the next line

  4. #14
    Join Date
    May 2005
    Location
    Oslo, Norway
    Beans
    467
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Making a small script

    Well, what can I say
    Thanks for the corretion!

    Here it is in all its "glory" (still, if anyone wants to use it):

    Code:
    #!/bin/sh
    
    {
    # Start with an introductory message, in case user started by mistake.
    if $(zenity --question --text="Du har startet et EasyPMP-skript\n\nVil du oppdatere din iRiver E10?" --title="Bekreft")
    then
    
    # Enter the player directory
    cd /media/E10
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        echo $(zenity --error --text="/media/E10 finnes ikke!\n\nSjekk at spilleren er tilkoblet eller snakk med Ketil" --title="Feil")
        exit 1
    fi
    
    # Update player using pmplib and the "create" option. "Update"-function segfaults for some reason.
    easypmp -c | zenity --progress --pulsate --auto-close --title="Oppdaterer" --text="Oppdaterer iRiver E10...\n\nVennligst vent til operasjonen er ferdig"
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ];then 
        echo $(zenity --error --text="Kommandoen easypmp -u feilet\n\nAvslutter!" --title="Feil!")
        exit 1
    fi
    
    # Exit to home-folder. (The player will not unmount if you stay in its dir)
    cd ~
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        echo $(zenity --error --text="Kan ikke navigere til hjemmemappe\n\nDette kan umulig stemme..." --title="Umulig feil")
        exit 1
    fi
    
    # Unmount the player, making it ready to unplug
    eject /media/E10
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ]; then
        echo $(zenity --error --text="Kan ikke avmontere spilleren\n\nDu må slå av maskinen før du plugger ut spilleren" --title="Feil")
        exit 1
    fi
    
    # Bye-message
    zenity 	--info --title "Oppdatering utført" --text "Spilleren din er nå oppdatert og klar til bruk!"
    
    fi
    }
    Save script as /usr/bin/e10update
    $ sudo chmod +x /usr/bin/e10update

    Make a shortcut anywhere you'd like, and you're good to go.

    Thanks for all help!

    - Ketil
    || My blog ||

  5. #15
    Join Date
    May 2005
    Location
    Oslo, Norway
    Beans
    467
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Making a small script

    Sorry to be bugging you all with this...
    Still, I have a problem, in this part:

    Code:
    # Update player using pmplib and the "create" option. "Update"-function segfaults for some reason.
    easypmp -c | zenity --progress --pulsate --auto-close --title="Oppdaterer" --text="Oppdaterer iRiver E10...\n\nVennligst vent til operasjonen er ferdig"
    EASY_EXIT=$?
    if [ $EASY_EXIT != 0 ];then 
        echo $(zenity --error --text="Kommandoen easypmp -u feilet\n\nAvslutter!" --title="Feil!")
        exit 1
    fi
    It appears that EASY_EXIT=$? here refers to the Zenity progress-command, and that of course never fails. How do I define "easypmp -c" as the successful-or-not--process in this script?

    - Ketil
    || My blog ||

  6. #16
    Join Date
    Feb 2006
    Beans
    238
    Distro
    Ubuntu 6.10 Edgy

    Re: Making a small script

    Following the suggestion from post 10:
    Code:
    if [[ $(easypmp -c)$? != 0 ]]; then
        echo $(zenity --error --text="Kommandoen easypmp -u feilet\n\nAvslutter!" --title="Feil!")
        exit 1
    fi
    I am not sure if this will run easypmp -c twice, though.

  7. #17
    Join Date
    May 2005
    Location
    Oslo, Norway
    Beans
    467
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Making a small script

    Quote Originally Posted by LotsOfPhil View Post
    Following the suggestion from post 10:
    Code:
    if [[ $(easypmp -c)$? != 0 ]]; then
        echo $(zenity --error --text="Kommandoen easypmp -u feilet\n\nAvslutter!" --title="Feil!")
        exit 1
    fi
    I am not sure if this will run easypmp -c twice, though.
    Yes, it did (attempt to) run it twice.
    And it didn't return the error message it should either...
    Back to the drawing board. Thanks though!

    - Ketil
    || My blog ||

  8. #18
    Join Date
    Nov 2004
    Location
    Brooklyn, NY
    Beans
    210

    Re: Making a small script

    Quote Originally Posted by LotsOfPhil View Post
    I don't think the example that has been posted is "right."
    Oops, sorry, I tacked the exit on without thinking. What I usually do is define a die function and use it like so:

    Code:
    #!/bin/sh
    
    die() {
        echo ${1}
        exit 1
    }
    
    someprog || die "Couldn't execute someprog"

  9. #19
    Join Date
    May 2005
    Location
    Oslo, Norway
    Beans
    467
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Making a small script

    I finally made the script do what it's supposed to do. Ignore the former posts, it's here: http://anotherugly.wordpress.com/200...ipt-for-linux/

    Thanks for your help!

    - Ketil
    || My blog ||

Page 2 of 2 FirstFirst 12

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
  •