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.7k 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
      last edited by

      Care to share your script with us?

      I'm not really sure that I get what you want to do. Why change the permissions? Why ftp and not ssh? What do you mean by "edit cmdlinnes" (command lines?)

      Maybe I just don't get your English because I'm german. ;)

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

        i don't change permisions by ftp ;) I use ftp to transfert my files and folder but some files need to change permissions to be transfered. SO to do it i wanna change all permsision by one script. and if a can add some package it's really great to :)

        #!/bin/bash
        
        sudo chmod 777 /etc/emulationstation/es_systems.cfg
        
        sudo chmod 777 /etc/emulationstation/es_systems.cfg.bak
        
        sudo chmod 777 /etc/dhcpcd.conf
        
        sudo chmod 777 /etc/wpa_supplicant/wpa_supplicant.conf
        

        i've try this, i've to change permission to execute it but it's not ok

        my script.sh does'nt be good but where my mistake ( sorry i'm noob )

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

          What do you mean by "it's not ok"? Did the permissions change? Are there error messages? Then please show them, too.

          Do you want to change the permissions of these files to be able to overwrite their originals in /etc with new versions via ftp? Then you could transfer them first to a different location on your Pi and then copy them in Retropie's command shell with "sudo cp [source] [destination]" to their final destinations. You would not need to change their permissions beforehand, then. (If I understand your endeavor correctly. If not, please try to describe it more / differently.)

          And I'm very sorry, but I don't understand what you mean by "if a can add some package it's really great to". What kind of package do you want to add where?

          I have to go to sleep now. Until tomorrow, then.

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

            hello sorry for late, i looking for my problem, and I think it's better to activate root user by a script but how change " /etc/ssh/sshd_config " to to make" yes" in PermitRootLogin and activate the line ( remove the # ) in this files ?
            I' dont know how to do that. because i must edit files and change root password. Could I do that with a script ?

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

              @wsamael said in help for script:

              hello sorry for late, i looking for my problem, and I think it's better to activate root user by a script but how change " /etc/ssh/sshd_config " to to make" yes" in PermitRootLogin and activate the line ( remove the # ) in this files ?

              This shouldn't be needed. You may be better explaining how are you executing the script, activating the root account's password is not needed just to change some permissions.

              The instructions you've posted eariler on (chmod ..) are wrong - they make the corresponding configuration files writable by any user/account on the system, which is incorrect.

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

                @wsamael said in help for script:

                how change " /etc/ssh/sshd_config " to to make" yes" in PermitRootLogin and activate the line ( remove the # ) in this files ?

                1. connect a keyboard to your Pi
                2. press F4 in Emulation Station to exit to Retropie's command shell
                3. enter sudo nano /etc/ssh/sshd_configto edit that file
                4. make your changes
                5. press Ctrl+x to exit, answer y for YES to save your changes, and press Enter to confirm the filename
                6. enter sudo systemctl reload sshd.service to reload the new sshd configuration
                7. enter exit in the command line to get back to Emulation Station

                OR

                Instead of 3. to 5. in the above sequence, just execute sudo sed -i 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config to change any occurrences of #PermitRootLogin no to PermitRootLogin yes. Then proceed with 6.

                (See https://linuxize.com/post/how-to-use-sed-to-find-and-replace-string-in-files/ to learn the ancient art of sed-fu to search and replace strings in text files.)

                edit: Forgot the actual file to change in the sed command. 😇
                edit 2: Inserted sshd reload command as 6.

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

                  so i've test that but it's not ok

                  #!/bin/bash
                  for /#/PermitRootLogin prohibit-password in /etc/ssh/sshd_config
                  do
                    echo "Traitement de $file ..."
                    sed -i -e "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" "$root_user"
                  done 
                  
                  i launch with sudo ./test.sh but  "sudo: ./test.sh: command not found
                  " any idea ? my script is ok or not ? 
                  
                  ClydeC 1 Reply Last reply Reply Quote 0
                  • 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
                                            • 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.