RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    help for script

    Scheduled Pinned Locked Moved Help and Support
    scripts
    24 Posts 3 Posters 1.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ClydeC
      Clyde @wsamael
      last edited by Clyde

      @wsamael sudo ./test.sh means "run the file test.sh in the current directory with root permissions". But it says that it couldn't find such a file there. Do you run this command from the directory where test.sh is located?

      If you are, then please show us the output of ls -la executed in the directory where test.sh is located (the l are little L).

      my script is ok or not ?

      That depends on what you want it to do. Could you explain it, please?

      • I don't understand the line for /#/PermitRootLogin prohibit-password in /etc/ssh/sshd_config in your script. What is it supposed to do?
      • You are using the variables $file and $root_user without defining them first. Or do you do that before running the script?
      1 Reply Last reply Reply Quote 0
      • W
        wsamael
        last edited by wsamael

        yes i run this from the directory where i put test.sh

        i' ve follow this tuto and try to make my script

        #!/bin/bash
        for file in *.txt
        do
          echo "Traitement de $file ..."
          sed -i -e "s/chaine1/chaine2/g" "$file"
        done 
        

        i must do a mistake

        1 Reply Last reply Reply Quote 0
        • ClydeC
          Clyde
          last edited by

          We are talking about to problems here: a) the script itself (i.e. its contents) and b) how to run it from the command shell or from another script.

          You still didn't explain what you actually want the script to do. It's hard to say if your script is correct if I don't know what it is supposed to do. It's quite clear that you want to replace #PermitRootLogin prohibit-password with PermitRootLogin yes. But the for…do…done loop does that for a number of files. Why that if there's only one sshd_config? Which tutorial are you referring to? (link please)

          As for problem b), you also didn't give me the output of ls -la run from inside the same directory that test.sh is in. Please do so.

          W 1 Reply Last reply Reply Quote 0
          • W
            wsamael @Clyde
            last edited by wsamael

            so for the b ;)
            i just wanna replace "#PermitRootLogin prohibit-password" to "PermitRootLogin yes" in only one files "etc/ssh/sshd_config" i don't need a loop my mistake

            for the a
            Capture.JPG
            the "test.sh" is in the directory

            the tuto
            http : //www.tux-planet . fr/remplacer-un-chaine-de-caractere-avec-la-commande-sed/

            ps delete the space to / and . in the url I cant' post the link

            1 Reply Last reply Reply Quote 0
            • ClydeC
              Clyde
              last edited by

              Try type ./test.sh. If this also doesnt work, your filename may contain invisible characters that nevertheless count as part of the filename (creating the file in Windows may do that). See here for a more thorough explanation and solution approach.

              If, however, type does work, try sudo bash ./test.sh to execute the script in a new bash instance. Depending on your system's setup, sudo may not like to execute scripts directly.

              1 Reply Last reply Reply Quote 0
              • W
                wsamael
                last edited by

                ok sudo bash ./test.sh launch the script ( the probleme a it's solved ;) ) but it's not work ( the problem b still here ;) )

                1 Reply Last reply Reply Quote 0
                • ClydeC
                  Clyde
                  last edited by

                  If it's still the same as in your post above, it can't work unless you fill the variables with content. 🧐

                  1 Reply Last reply Reply Quote 0
                  • W
                    wsamael
                    last edited by

                    hello sorry for long silent, i've try many thing today

                    if i've type

                    sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
                    

                    it's work but if I make this in a script, it's don't work

                    #!/bin/bash
                    
                    sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
                    
                    echo "root activate"
                    

                    i' ve this message

                    pi@retropie:~ $ sudo bash ./root.sh
                    ./root.sh: line 2: $'\r': command not found
                    : No such file or directoryhd_config
                    ./root.sh: line 4: $'\r': command not found
                    
                    

                    someone have an idea ?

                    1 Reply Last reply Reply Quote 0
                    • mituM
                      mitu Global Moderator
                      last edited by

                      @wsamael said in help for script:

                      i' ve this message

                      Your script has Windows (DOS) line endings, make sure you edit the script with an editor that understands Unix line endings and set your editor to save your script correctly. When in doubt, use Notepad++.

                      W 1 Reply Last reply Reply Quote 1
                      • ClydeC
                        Clyde
                        last edited by Clyde

                        Or you could do it in Retropie's command line:

                        sed -i 's/\r$//' root.sh
                        

                        or

                        sudo apt install dos2unix  # only needed once to install dos2unix
                        dos2unix root.sh
                        

                        Both edit the file in place, so be sure to have a backup if anything goes wrong.

                        Source: https://askubuntu.com/questions/803162/how-to-change-windows-line-ending-to-unix-version

                        W 1 Reply Last reply Reply Quote 1
                        • W
                          wsamael @mitu
                          last edited by

                          @mitu usually I use sublim text but not this time my mistake

                          1 Reply Last reply Reply Quote 0
                          • W
                            wsamael @Clyde
                            last edited by wsamael

                            @Clyde the first solution it's for convert my script to unix script ? Good to know. I'll try this, but for my next script i would like to make them in unix language ;)

                            ClydeC 1 Reply Last reply Reply Quote 0
                            • ClydeC
                              Clyde @wsamael
                              last edited by

                              @wsamael said in help for script:

                              @Clyde the first solution it's for convert my script to unix script ?

                              Both are. The first doesn't require the installation of another tool, as sed is party of most Linux base installations; the second may be more easy to remember as something like 's/\r$//'. ;)

                              1 Reply Last reply Reply Quote 0
                              • W
                                wsamael
                                last edited by

                                I try

                                sed -i 's/\r$//' root.sh
                                

                                it's work but I see no difference beetwen my script, how did you see what 's wrong with my script ? (i would be understand ^^ )

                                ClydeC 1 Reply Last reply Reply Quote 0
                                • ClydeC
                                  Clyde @wsamael
                                  last edited by

                                  @wsamael Your error message said:

                                  '\r': command not found
                                  

                                  Windows ends a line in a text file with a carriage return (\r) and a line feed (\n), wheras unixoid systems only use \n. Thus Retropie's command shell bash rejected the \r in your file as an unknown command.

                                  1 Reply Last reply Reply Quote 0
                                  • W
                                    wsamael
                                    last edited by

                                    ok i understand thank you ;)

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post

                                    Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                    Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.