Hello everyone I am using Mint since a couple of month and I have some experience with bash scripting.
As you may know, /etc/rc.local ends with "exit 0". My challenge is to use a script that read rc.local and find where is "exit 0", then create a new line over it and put the code I want to be executed, saves the file and continue my script.
Do you think it is possible to create a script that would do this? How to do it?
Thanks for your help!
/st0de
Automated edition of /etc/rc.local [ SOLVED ]
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
Automated edition of /etc/rc.local [ SOLVED ]
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Automated edition of /etc/rc.local
Usually the exit 0 line is the last line in the script. So you can do:
If the exit 0 is not the last line, this gets a little bit more complicated. Let me know if that is needed, and I'll rework the above to handle exit 0 at any point in the file.
Code: Select all
# Store all but the last line of /etc/rc.local in /tmp/rc.local
head -n -1 /etc/rc.local > /tmp/rc.local
# Add your line of text
echo "your line to add before exit 0" >> /tmp/rc.local
# Add the last line of /etc/rc.local
tail -n 1 /etc/rc.local >> /tmp/rc.local
# Backup /etc/rc.local
sudo mv /etc/rc.local /etc/rc.local.old
# Put the new rc.local in place, with your added line
sudo mv /tmp/rc.local /etc