Announcement

Collapse
No announcement yet.

Using sed to strip sftp from url

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by Xplorer4x4 View Post
    Ah I realized that the first part of that line was calling the script but the url is being passed from Dolphin so why would you call the url alongside the script? :s
    You wouldn't, unless you were testing the script in a shell instead of from dolphin...which is what I did.

    As for the additional question, it's probably doable (with modifications to the script), but for simplicity's sake it might make sense to make two scripts rather than combining the two options into one script. And use exec lines similar to:

    Exec=/path/to/mktorrent-1.sh %U
    Exec=/path/to/mktorrent-2.sh %U

    Comment


      #17
      Originally posted by kubicle View Post
      You wouldn't, unless you were testing the script in a shell instead of from dolphin...which is what I did.

      As for the additional question, it's probably doable (with modifications to the script), but for simplicity's sake it might make sense to make two scripts rather than combining the two options into one script. And use exec lines similar to:

      Exec=/path/to/mktorrent-1.sh %U
      Exec=/path/to/mktorrent-2.sh %U
      I didnt read it throughly and see you were inputting a path to a file. I thought it was just a log in.

      And the additionally question, actually I can confirm it is possible! I remebered that oen of the Root Actions Service Menus does it but they use perl script located in /usr/bin/. The actual script uses a format like:
      Code:
      sub dosomething{
      something
      to
      do
      }
      Not sure if this is simply due to the perl syntax as I have no experience with perl at all, So it may take some work like you said, and I dont mind having the bash files in the /usr/bin/ folder to keep the service menu folder more organized.
      OS: Kubuntu 12.10/Windows 8
      CPU: Intel Core i7 2600K
      Motherboard: Gigabyte GA-Z77X-UD5H
      Memory: 2x4GB Corsair Dominator
      Graphics Card: MSI R7770
      Monitor: Dell 2208WFP
      Mouse: Mionix NAOS 5000
      PSU: Corsair 520HX
      Case: Thermaltake Mozart TX
      Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
      Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

      Comment


        #18
        The perl syntax is different to bash, but it doesn't matter what language the files you execute are in as along as the top line points to the right executable: #!/bin/bash tells the system to use bash to execute them when they are called. However I would suggest either using /usr/local/bin or packaging up your scripts properly.

        /usr/bin generally contains binrary files that are managed by the package manager and /usr/local/bin contains custom binrary files that you have installed manually. This makes it easier to find and manage your scripts over the ones that the package manager installed.

        Comment


          #19
          Originally posted by Xplorer4x4 View Post
          And the additionally question, actually I can confirm it is possible! I remebered that oen of the Root Actions Service Menus does it but they use perl script located in /usr/bin/.
          I'm aware of that, I wrote the thing

          You can probably get it to work remembering that $1 would contain your subroutine and the url would be $2. I suggested separate scripts as that would be simpler, you can of course do it anyway you like.

          Comment


            #20
            Originally posted by james147 View Post
            The perl syntax is different to bash, but it doesn't matter what language the files you execute are in as along as the top line points to the right executable: #!/bin/bash tells the system to use bash to execute them when they are called. However I would suggest either using /usr/local/bin or packaging up your scripts properly.

            /usr/bin generally contains binrary files that are managed by the package manager and /usr/local/bin contains custom binrary files that you have installed manually. This makes it easier to find and manage your scripts over the ones that the package manager installed.
            Thanks for the tips. What do you mean packaging the scripts properly?

            Originally posted by kubicle View Post
            I'm aware of that, I wrote the thing

            You can probably get it to work remembering that $1 would contain your subroutine and the url would be $2. I suggested separate scripts as that would be simpler, you can of course do it anyway you like.
            I didn;t feel like looking it up but thanks for writing it! Very useful! How come you chose perl rather then bash?

            As for $1 and $2, could you elaborate?
            OS: Kubuntu 12.10/Windows 8
            CPU: Intel Core i7 2600K
            Motherboard: Gigabyte GA-Z77X-UD5H
            Memory: 2x4GB Corsair Dominator
            Graphics Card: MSI R7770
            Monitor: Dell 2208WFP
            Mouse: Mionix NAOS 5000
            PSU: Corsair 520HX
            Case: Thermaltake Mozart TX
            Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
            Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

            Comment


              #21
              Originally posted by Xplorer4x4 View Post
              Thanks for the tips. What do you mean packaging the scripts properly?
              I mean creating a package that can be installed by dpkg (ie a .deb) but this might might more effort then it is worth.

              Comment


                #22
                That's what I suspected, but I really see no point in making a deb for a shell script and service menu file unless I was distributing it.
                OS: Kubuntu 12.10/Windows 8
                CPU: Intel Core i7 2600K
                Motherboard: Gigabyte GA-Z77X-UD5H
                Memory: 2x4GB Corsair Dominator
                Graphics Card: MSI R7770
                Monitor: Dell 2208WFP
                Mouse: Mionix NAOS 5000
                PSU: Corsair 520HX
                Case: Thermaltake Mozart TX
                Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                Comment


                  #23
                  Originally posted by Xplorer4x4 View Post
                  How come you chose perl rather then bash?
                  There were a few reasons, but mostly because I knew I was going to use datastructures such as arrays, and perl IMO handles them much better. I also only had a vague idea of what the script needed to do, and what it might need to do in the future...and I was less likely to hit a snag with perl.

                  As for $1 and $2, could you elaborate?
                  Well...in your script you use
                  url=${1}
                  To set up the $url variable using the first argument of your command, but if you Exec= something like:
                  script mktorrent1 %U
                  then the url is going to be the second argument $2
                  (You can then use $1, which will be 'mktorrent1' to call the correct function in your script, for example...so you can have functions 'mktorrent1' and 'mktorrent2' and use the first argument ($1) to choose which function you want to execute...of course you don't need to do it with separate functions, you can just check the arguments and let the script behave accordingly with 'if' or 'case' statements, as in 'if the first argument $1 is this...do this' etc.)

                  Comment


                    #24
                    Re: Bash vs Perl, thanks for the answer. I was just curious. Always eager to soak up info.

                    As for $1 vs $2, maybe it's lack of sleep, maybe not but I am not sure I follow, so is this right..
                    Exec=maketorrent.sh mktorrent1 %U
                    Means %U is the second variable so I would use $2? However if I use:
                    Exec=maketorrent.sh %U
                    Means %U is the first variable so $1?

                    I was thinking, using 2 entire subrotunies is excessive as only the announce url will change. So if I nested the different announce urls in an if statement, this would mean the exec line needs to be:
                    Exec=maketorrent.sh $mktorrent $announce1 %U
                    Then url would become $3. Am I following you correctly or am I way off?

                    Sent from my DROID2 Global
                    OS: Kubuntu 12.10/Windows 8
                    CPU: Intel Core i7 2600K
                    Motherboard: Gigabyte GA-Z77X-UD5H
                    Memory: 2x4GB Corsair Dominator
                    Graphics Card: MSI R7770
                    Monitor: Dell 2208WFP
                    Mouse: Mionix NAOS 5000
                    PSU: Corsair 520HX
                    Case: Thermaltake Mozart TX
                    Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                    Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                    Comment


                      #25
                      Originally posted by Xplorer4x4 View Post
                      As for $1 vs $2, maybe it's lack of sleep, maybe not but I am not sure I follow, so is this right..
                      Exec=maketorrent.sh mktorrent1 %U
                      Means %U is the second variable so I would use $2? However if I use:
                      Exec=maketorrent.sh %U
                      Means %U is the first variable so $1?
                      That's correct

                      I was thinking, using 2 entire subrotunies is excessive as only the announce url will change. So if I nested the different announce urls in an if statement, this would mean the exec line needs to be:
                      Exec=maketorrent.sh $mktorrent $announce1 %U
                      Then url would become $3. Am I following you correctly or am I way off?
                      If the only thing that changes is the announceurl, you could provide it directly from the exec lines:

                      Exec=maketorrent.sh "http://site/key/announce" %U
                      Exec=maketorrent.sh "http://anothersite/key/announce" %U

                      And you wouldn't need any checks, you could just use $1 (which would contain the announce URL) in your script where you needed it, and the file url from dolphin (%U) would be in $2

                      Comment


                        #26
                        I tried that method, and it claims "not sftp, exiting" from the first echo debug line. I did what you said, in the service menu I used:
                        Exec=maketorrent.sh "http://site/key/announce" %U
                        Exec=maketorrent.sh "http://anothersite/key/announce" %U

                        In the script:
                        url=${2}
                        if ssh user@host "mktorrent -a '${1}' -p -l 21 '${stripedurl}'"; then
                        OS: Kubuntu 12.10/Windows 8
                        CPU: Intel Core i7 2600K
                        Motherboard: Gigabyte GA-Z77X-UD5H
                        Memory: 2x4GB Corsair Dominator
                        Graphics Card: MSI R7770
                        Monitor: Dell 2208WFP
                        Mouse: Mionix NAOS 5000
                        PSU: Corsair 520HX
                        Case: Thermaltake Mozart TX
                        Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                        Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                        Comment


                          #27
                          the problem now is that url${2} is inside the function, so that means the second argument passed to that function, in the forloop we used $@ to loop through all the arguments and pass them to the function, what you want to do is this:
                          Code:
                          anounce=${1}
                          shift # removes $1 and makes $2 become $1
                          for file in $@; do
                              mktorrent ${anounce} ${file}
                          done
                          This will get the first argument, store it in $anounce then shift all the arguments left one ($2 becomes $1, $3 becomes $2 etc) then loops over the remaining arguments and passes $anounce and one argument at a time to the mktorrent function.

                          Comment


                            #28
                            Good catch james...I knew I should have checked the whole script again rather than a few relevant lines, but of course I had one foot out-the-door already.

                            Comment


                              #29
                              Originally posted by kubicle View Post
                              @jlittle: people that think outside the box are unnerving
                              Yah, I saw that and I was like

                              Comment


                                #30
                                Originally posted by james147 View Post
                                the problem now is that url${2} is inside the function, so that means the second argument passed to that function, in the forloop we used $@ to loop through all the arguments and pass them to the function, what you want to do is this:
                                Code:
                                anounce=${1}
                                shift # removes $1 and makes $2 become $1
                                for file in $@; do
                                    mktorrent ${anounce} ${file}
                                done
                                This will get the first argument, store it in $anounce then shift all the arguments left one ($2 becomes $1, $3 becomes $2 etc) then loops over the remaining arguments and passes $anounce and one argument at a time to the mktorrent function.
                                Maybe I missed something but same error, script looks like:
                                Code:
                                #!/bin/bash
                                maketorrent() {
                                    url=${2}
                                
                                case $url in
                                  "sftp://"*) echo "$url is sftp";;
                                
                                  *) echo "not sftp, exiting"; return 1 ;;
                                esac
                                
                                
                                    stripedurl=`echo "${url}" | sed "s=^sftp://[^/]*=="`
                                
                                    if ssh user@host "mktorrent -a '${1}' -p -l 21 '${stripedurl}'"; then
                                	  kdialog --passivepopup "Completed making torrent for '$stripedurl" 60
                                    else
                                	  kdialog --passivepopup "Failed mktorrent" 60
                                       return 1 # Change to exit 1 to stop the script on first failure
                                    fi
                                
                                echo "Finished" # debug line
                                }
                                
                                if [ -z "${2}" ] ; then
                                echo "Not enough arguments, exiting"
                                    exit 1
                                fi
                                
                                anounce=${1}
                                shift
                                for file in $@ ; do
                                maketorrent ${file}
                                done
                                OS: Kubuntu 12.10/Windows 8
                                CPU: Intel Core i7 2600K
                                Motherboard: Gigabyte GA-Z77X-UD5H
                                Memory: 2x4GB Corsair Dominator
                                Graphics Card: MSI R7770
                                Monitor: Dell 2208WFP
                                Mouse: Mionix NAOS 5000
                                PSU: Corsair 520HX
                                Case: Thermaltake Mozart TX
                                Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                                Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                                Comment

                                Working...
                                X