How to add a line into rc.local with shell

missingcat92 picture missingcat92 · Jul 12, 2013 · Viewed 15.9k times · Source

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?

Answer

sigmalha picture sigmalha · Jul 12, 2013

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