1753868 Members
7351 Online
108809 Solutions
New Discussion юеВ

Re: updating file

 
OFC_EDM
Respected Contributor

updating file

arrhhhgh...I'm having a brain blank this morning.

Want a simple command I can use via ssh to update files across systems.

One example is
sed -e 's/DISABLETIME=[0-9][0-9]/DISABLETIME=60/1' < ./login > ./login

The problem with this is obviously it will 0 out the file when it writes back.

How could I lookup up DISABLETIME=20 (or any 2 digit value after the =) and replace it with DISABLETIME=60?

This has to plug into an ssh command so I don't want to keep the command as simple as possible to avoid SSH issues.
The Devil is in the detail.
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor

Re: updating file

Hi:

# perl -pi.old -e 's/\bDISABLETIME=\d\d\b/DISABLETIME=60/' ./login

...will perform an inplace update of the file passed leaving a backup copy as "*.old".

The '\b' bound the match so that you don't get something like DISABLETIME=200 changed to DISABLETIME=600. The '\d' is a digit.

Regards!

...JRF...
OFC_EDM
Respected Contributor

Re: updating file

Thanks James I'll try that out today.

I'd still be interested in a basic way without perl.

Not that I don't appreciate perl. They just don't use it here and I want to create a method to leave with the admins here utilizing simple shell and ssh commands.

Cheers
The Devil is in the detail.
OFC_EDM
Respected Contributor

Re: updating file

Now that I've had some sleep. I've solved this via process instead of a command. Clarity comes with sleep and good coffee.

Going to scp the file to be modified from my target system to my local system.

Create a backup copy on my local sytem
Modify file on my local system.
scp modified file back to target system.
Verify file permissions.

So if I mess up I have an easy way out :)

DOH!!
The Devil is in the detail.
Dennis Handly
Acclaimed Contributor

Re: updating file

>I want to create a method to leave with the admins here utilizing simple shell and ssh commands.

Well you can use sed but you need to write the output to another file and then move back in place:
sed -e 's/DISABLETIME=[0-9][0-9]/DISABLETIME=60/' login > login.new; mv login.new login

With a possible check to make sure you don't lose the whole file.
OFC_EDM
Respected Contributor

Re: updating file

James,

How could you get your perl statement to read a list of server names?

I want to put all my server names into a text file.

Loop through the text file.
Retrieve the login file and rename it login.servername. (via scp)

Then run the "perl" command against the file login.servername.

Then I'll end up with 2 files
1) login.servername with the new settings
2) login.servername.old which is a orig copy

Have a good day!!
The Devil is in the detail.
OFC_EDM
Respected Contributor

Re: updating file

Never mind :)
...i'm just not thinking today

I'll just use a variable in your perl string. The rest of the stuff is just easy loops around your command.

Cheers
The Devil is in the detail.
OFC_EDM
Respected Contributor

Re: updating file

I ended up using James solution with a while loop etc.

Sorry James I assigned you 7 points before I realized I was going to use your solution.

wanted to give you 10 but couldn't go back and modify.

Thanks for the help
The Devil is in the detail.