Ubuntu write boot from shell script

Source: Internet
Author: User
Tags chmod
1. First, write a simple shell script
Vimtest.sh (Nano is not used to use VIM)
Enter Vim and press the I key, then enter (#!/bin/sh symbol #! to tell the system that its subsequent parameters are the program used to execute the file.) )
#!/bin/bash 
echo "helloworld!"

Filename= ' Date ' +%y%m%d ' 
echo$filename
Then ESC shift+z two more times (save)
At the command line, enter: chmod +x test.sh(Give execution permission)
Run: ./test.sh

To view the path of a command: Whichls (Suppose you view the path to the LS command)
#后面的内容表示注释, to develop a good habit of writing notes

more shell programming knowledge shell Programming Introduction


2, set the script to boot from start
Programme I:
Edit the/etc/init.d/rc.local file and add your script at the end.
For example: I've written a script apk.sh, stored under/home/apk/
In Ubuntu terminal input: sudo nano/etc/init.d/rc.localAt the end of the join: sh/home/apk/shell.shCan load script automatically on boot

Programme II:

1 Copy your startup script to the/ETC/INIT.D directory
sudo cp test.sh/etc/init.d/

2 Execute the following command to place the script in the startup script:
CD/ETC/INIT.D
sudo chmod 755/etc/init.d/test.sh
sudo update-rc.d test.sh defaults95

Note: The number 95 is the sequence number of the script to start, according to their own needs to modify accordingly. You know how this number works when you have multiple startup scripts, and there are dependent dependencies that start between them. The output information for this command is referenced as follows:
        Update-rc.d:warning:/etc/init.d/test Missing LSB information
Update-rc.d:see
To uninstall the startup script:
Cd/etc/init.d
sudo update-rc.d-f test.shremove


Precautions:

I started by using the Forever command to write a script, as follows:
#!/usr/local/bin/forever
Forever Start/home/apk/apkanalysis/app.js

But no matter what method I use it does not start up, and later found that it has less than a sudo permission:
#!/usr/local/bin/forever
sudo forever start/home/apk/apkanalysis/app.js

So when configuring the boot up, be sure to pay attention to the use of sudo.

To view system-initiated logs: Cat/var/log/boot.log
The beginning is always not up, read the next log, found that the file does not exist; Log in to see the file exists, probably when you execute the startup script the user directory has not been mount

The project is then placed under the SRV directory to boot from the startup. Change the permissions . sudo chmod 775/srv/
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.