- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: updating file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2008 12:36 AM
тАО04-14-2008 12:36 AM
updating file
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.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2008 03:52 AM
тАО04-14-2008 03:52 AM
Re: updating file
# 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...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2008 01:15 AM
тАО04-15-2008 01:15 AM
Re: updating file
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2008 01:21 AM
тАО04-15-2008 01:21 AM
Re: updating file
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2008 01:34 AM
тАО04-15-2008 01:34 AM
Re: updating file
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2008 01:34 AM
тАО04-15-2008 01:34 AM
Re: updating file
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2008 01:40 AM
тАО04-15-2008 01:40 AM
Re: updating file
...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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2008 02:07 AM
тАО04-15-2008 02:07 AM
Re: updating file
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