A script to add and remove a character in a line at a given time
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
A script to add and remove a character in a line at a given time
Hello,
I have a configuration file and I want a line from this configuration file to be converted to a comment (#) at a specified time, and then reset the service, and again at a specified time, that line is removed from comment mode and reset the service again. Is this possible with a script?
yes
you need to create a crontab entry to run your script which will do that modification and reset/restart/reload the service again.
To change a line you can use a lot of tools, for example awk, sed, perl, python or even shell. Or you can just store the two versions and copy them at the given time.
yes
you need to create a crontab entry to run your script which will do that modification and reset/restart/reload the service again.
To change a line you can use a lot of tools, for example awk, sed, perl, python or even shell. Or you can just store the two versions and copy them at the given time.
Hello,
Thank you so much for your reply.
Can you help me write this script? I want a # sign to be placed at the beginning of line 214 of the /etc/tor/torrc file at 12:00 AM and then the systemctl restart tor command will be executed, then tomorrow at the same time the # sign will be removed and the service will be restarted.
As mentioned in #3 above, you can make two extra copies of the torrc file. Then at the designated times you can have some scripts do two things: First copy one of the copies to the official torrc file. Second restart the service / reload the configuration file.
You can do that with two shell scripts (one for each file) and trigger it via a cron job.
If you are amenable to that approach, please give it a try.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.