help for script
-
hello, I would create a script for change the permission in some files to replace all by ftp in one ( by example change permission to es_systems.cfg, es_systems.cfg.bak , for uplaode my filedhcpcd.conf. wpasupplicant.con fto replace them in one time) and if it's possible edit cmdlinnes by the same script.
I try to create a script.sh with all commande but it's not working how can I do it and where I do place it ?I hope you understand me and sorry for my english I'm french ^^
-
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. ;)
-
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 )
-
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.
-
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 ? -
@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. -
@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 ?
- connect a keyboard to your Pi
- press
F4
in Emulation Station to exit to Retropie's command shell - enter
sudo nano /etc/ssh/sshd_config
to edit that file - make your changes
- press
Ctrl+x
to exit, answery
for YES to save your changes, and pressEnter
to confirm the filename - enter
sudo systemctl reload sshd.service
to reload the new sshd configuration - 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. -
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 ?
-
@wsamael
sudo ./test.sh
means "run the filetest.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 wheretest.sh
is located?If you are, then please show us the output of
ls -la
executed in the directory wheretest.sh
is located (thel
are littleL
).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?
- I don't understand the line
-
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
-
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
withPermitRootLogin yes
. But the for…do…done loop does that for a number of files. Why that if there's only onesshd_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 thattest.sh
is in. Please do so. -
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 mistakefor the a
the "test.sh" is in the directorythe 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
-
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, trysudo 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. -
ok sudo bash ./test.sh launch the script ( the probleme a it's solved ;) ) but it's not work ( the problem b still here ;) )
-
If it's still the same as in your post above, it can't work unless you fill the variables with content. 🧐
-
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 ?
-
@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++.
-
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
-
@mitu usually I use sublim text but not this time my mistake
-
@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 ;)
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.