Ubuntu 创建下自启动脚本

来源:互联网 发布:数据库原理经典书籍 编辑:程序博客网 时间:2024/06/07 14:05
color: #00000a; text-align: left; orphans: 0; direction: ltr; color: #00000a; line-height: 120%; text-align: left; orphans: 0; font-size: 12pt; font-size: 12pt; font-size: 12pt; so-language: hi-IN };
1.编写启动脚本start.sh

#!/bin/sh cd /home/Software/./test1 &

/home/Software为编译好的可执行文件的路径;
./test1为可执行文件 切记最后的 “& 表示可以后台运行2.将此脚本加到系统启动文件 ~/.porfile编写~/.proflie文件 ,编写完成后:

# ~/.profile: executed by the command interpreter for login shells.# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login# exists.# see /usr/share/doc/bash/examples/startup-files for examples.# the files are located in the bash-doc package.# the default umask is set in /etc/profile; for setting the umask# for ssh logins, install and configure the libpam-umask package.#umask 022# if running bashif [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then. "$HOME/.bashrc" fifibash /home/Software/start.sh & # set PATH so it includes user's private bin if it existsif [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH"fi

其中:/home/Software为文件start.sh的路径;切记最后的 “& 不能省略,否则开机后切换不了界面,系统只运行你写的程序;
    在重启机子之前最好先验证一下脚本是否有效,验证的方法是:把bash /home/Software/start.sh,粘到终端里看能否
正确运行脚本里如果出顼有路径,最好用绝对路径
原创粉丝点击