Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a line into rc.local with shell

I am working on a Ubuntu 12.04 and writing a environment-auto-build shell. In the shell I need to change something in rc.local.

This is my rc.local now.

#!/bin/sh -e
#......

exit 0

I want to modify it like this:

#!/bin/sh -e
#......

nohup sh /bocommjava/socket.sh &

exit 0

Now I use nano to modify it, is there any command that can insert the line into rc.local?

like image 915
missingcat92 Avatar asked Jul 12 '13 02:07

missingcat92


People also ask

How do you add a line to a shell script?

Using '>>' with 'echo' command appends a line to a file. Another way is to use 'echo,' pipe(|), and 'tee' commands to add content to a file.

How do I enable rc local service?

It is possible to add support for the old rc. local file by enabling the service with the command, systemctl enable rc-local . The commands in the rc. local file will run at the next boot.


1 Answers

Use Sed

For Test

sed -e '$i \nohup sh /bocommjava/socket.sh &\n' rc.local

Really Modify

sed -i -e '$i \nohup sh /bocommjava/socket.sh &\n' rc.local
like image 156
sigmalha Avatar answered Oct 02 '22 01:10

sigmalha