DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Change the text of a file remotely

Thu Jan 16, 2020 4:16 pm

Hello ,
I'm new to programming , i want to know if there is anyway if i could change a text in a file remotley in a distance , the file format is shell and the file it is /etc/profile what have inside it is :

Code: Select all

 omxplayer rtmp://www.example/live:13587.com 
and i need to change this source everytime i want to watch something else.
change it remotely by creating a server and a DB or something like this please i'm waiting for your replies.
Thank God

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25368
Joined: Sat Jul 30, 2011 7:41 pm

Re: CHANGE THE TEXT OF A FILE REMOTELY

Thu Jan 16, 2020 5:17 pm

Can you please avoid using all capitals in your thread titles please. It make them too shouty. I've fixed this one for you.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: Change the text of a file remotely

Thu Jan 16, 2020 5:26 pm

Haha
Actually i'm sorry for that

that what happens when you're on a project and you got stuck .. you are desprate.
Thank God

jahboater
Posts: 5172
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Change the text of a file remotely

Thu Jan 16, 2020 6:02 pm

You can execute remote commands with ssh.

ssh pi@host 'command list'

The commands may be anything, including in your case "sed", or a home written program to change the text.
As usual separate multiple commands with ';'.

ssh will ask for Pi's password, however that can be avoided simply enough (ssh-keygen and ssh-copy-id).

User avatar
topguy
Posts: 6269
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Change the text of a file remotely

Fri Jan 17, 2020 9:09 am

You should proably put the name of the file you want to watch in a separate file and read that file from "/etc/profile".

example:

Code: Select all

movie=$(cat /home/pi/movie.txt)
omxplayer $movie
Now you only have to overwrite the whole file movie.txt instead of editing a more critical system file like "/etc/profile".
And you can use "echo" in the ssh command instead of a more complex "sed" command.

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: Change the text of a file remotely

Fri Jan 17, 2020 9:53 am

topguy wrote:
Fri Jan 17, 2020 9:09 am
You should proably put the name of the file you want to watch in a separate file and read that file from "/etc/profile".

example:

Code: Select all

movie=$(cat /home/pi/movie.txt)
omxplayer $movie
Now you only have to overwrite the whole file movie.txt instead of editing a more critical system file like "/etc/profile".
And you can use "echo" in the ssh command instead of a more complex "sed" command.
Hello ,

Yeah Actually that what i was looking for thanks :) , but how can i acces to movie.txt file from a distance like my raspberry pi it is in my home and i'm at work and i can change the file move.txt content ... or just replace it by another one .
Thank God

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: Change the text of a file remotely

Fri Jan 17, 2020 9:55 am

jahboater wrote:
Thu Jan 16, 2020 6:02 pm
You can execute remote commands with ssh.

ssh pi@host 'command list'

The commands may be anything, including in your case "sed", or a home written program to change the text.
As usual separate multiple commands with ';'.

ssh will ask for Pi's password, however that can be avoided simply enough (ssh-keygen and ssh-copy-id).
Hi ,

Can you please explain a little more . i think the ssh way can only work if you're and the raspebrry pi connected to the same network.

thanks for the password trick ;)
Thank God

User avatar
topguy
Posts: 6269
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Change the text of a file remotely

Fri Jan 17, 2020 10:04 am

Can you please explain a little more . i think the ssh way can only work if you're and the raspebrry pi connected to the same network.
You didnt originally specify exactly what you meant by remotely so read this...
https://www.raspberrypi.org/documentati ... /README.md

What is not mentioned on that page is remote desktop with RealVNC which also has cloud connection.
https://www.raspberrypi.org/documentati ... /README.md

If you are up for a bit of programming/scripting you could also just put the movie-name on the internet somewhere and create a service on the Pi that checks that place every 5 minutes and updates the file if it changes.
Last edited by topguy on Fri Jan 17, 2020 10:09 am, edited 2 times in total.

User avatar
rpdom
Posts: 16311
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Change the text of a file remotely

Fri Jan 17, 2020 10:07 am

DEXTER_STARK wrote:
Fri Jan 17, 2020 9:55 am
i think the ssh way can only work if you're and the raspebrry pi connected to the same network.
All ways will only work if you are on the same network or have remote access to it either via a VPN or if there is port forwarding in place.

It doesn't matter if it is SSH, VNC or any other method. You still need to be able to access the network from wherever you are.

I use a VPN for my remote access. I can ssh or whatever in to my Pis from anywhere that I can get full internet access.

GlowInTheDark
Posts: 390
Joined: Sat Nov 09, 2019 12:14 pm

Re: Change the text of a file remotely

Fri Jan 17, 2020 10:16 am

If you are up for a bit of programming/scripting you could also just put the movie-name on the internet somewhere and create a service on the Pi that checks that place every 5 minutes and updates the file if it changes.
I think this is the best idea presented so far. It does not require tearing down any firewalls. Of course, it leaves open the question of where that "somewhere on the internet" would be.

Also note that editing (in one form or another) /etc/profile is probably nowhere near being the best way to approach this problem. In particular, if I understand your overall system design correctly, it will only have effect on boot (*), so you will need to reboot the remote system in order for it to take effect.

(*) Yes, yes, I know, actually you would just have to re-start some instance of the shell, but in practice, that's likely to end up being a reboot.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

jahboater
Posts: 5172
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Change the text of a file remotely

Fri Jan 17, 2020 10:50 am

DEXTER_STARK wrote:
Fri Jan 17, 2020 9:55 am
Can you please explain a little more . i think the ssh way can only work if you're and the raspebrry pi connected to the same network.
I'm not an expert but I would expect ssh (and scp) to work to any host that you can address (can ping) that has ssh enabled. There must not be a firewall blocking port 22 of course.
By the way, this includes your own Pi (localhost) so you can practice on that!

ssh 127.0.0.1

scp is useful for copying files around and has syntax similar to the usual "cp" command so its nicer (and more secure) than FTP.

scp file pi@host:

copies "file" to the home directory for user pi on host.

The password thing is called public/private key authentication. It is far more secure than simple user text passwords and once set up with "ssh-copy-id pi@host" you no longer have to provide a password every time you ssh or scp.

You enable ssh in raspi-config, or for the first connection to a headless Pi, place a file called ssh in the FAT32 boot partition.

For GUI access to the desktop, use VNC as noted above.

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: Change the text of a file remotely

Fri Jan 17, 2020 1:01 pm

GlowInTheDark wrote:
Fri Jan 17, 2020 10:16 am
If you are up for a bit of programming/scripting you could also just put the movie-name on the internet somewhere and create a service on the Pi that checks that place every 5 minutes and updates the file if it changes.
I think this is the best idea presented so far. It does not require tearing down any firewalls. Of course, it leaves open the question of where that "somewhere on the internet" would be.

Also note that editing (in one form or another) /etc/profile is probably nowhere near being the best way to approach this problem. In particular, if I understand your overall system design correctly, it will only have effect on boot (*), so you will need to reboot the remote system in order for it to take effect.

(*) Yes, yes, I know, actually you would just have to re-start some instance of the shell, but in practice, that's likely to end up being a reboot.
Thanks. that gave me an idea of what i'm going to do. ;)
Thank God

DEXTER_STARK
Posts: 17
Joined: Tue Jan 14, 2020 5:05 pm
Location: Paris, France

Re: Change the text of a file remotely

Fri Jan 17, 2020 1:02 pm

jahboater wrote:
Fri Jan 17, 2020 10:50 am
DEXTER_STARK wrote:
Fri Jan 17, 2020 9:55 am
Can you please explain a little more . i think the ssh way can only work if you're and the raspebrry pi connected to the same network.
I'm not an expert but I would expect ssh (and scp) to work to any host that you can address (can ping) that has ssh enabled. There must not be a firewall blocking port 22 of course.
By the way, this includes your own Pi (localhost) so you can practice on that!

ssh 127.0.0.1

scp is useful for copying files around and has syntax similar to the usual "cp" command so its nicer (and more secure) than FTP.

scp file pi@host:

copies "file" to the home directory for user pi on host.

The password thing is called public/private key authentication. It is far more secure than simple user text passwords and once set up with "ssh-copy-id pi@host" you no longer have to provide a password every time you ssh or scp.

You enable ssh in raspi-config, or for the first connection to a headless Pi, place a file called ssh in the FAT32 boot partition.

For GUI access to the desktop, use VNC as noted above.
Thanks. Actually that was very helpful.
Thank God

Return to “Networking and servers”