Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Shell脚本创建带有密码的目录,并使其在系统启动时可运行_Bash_Shell_Ubuntu_Startup - Fatal编程技术网

Bash Shell脚本创建带有密码的目录,并使其在系统启动时可运行

Bash Shell脚本创建带有密码的目录,并使其在系统启动时可运行,bash,shell,ubuntu,startup,Bash,Shell,Ubuntu,Startup,我要做的是在启动时运行应用程序。所以我把它作为一种服务。ie作为/etc/init.d下的shell脚本。我正在使用Ubuntu。。问题是,如果/var/run目录不存在,我必须在该目录下创建一个文件夹。下面是我的代码 #!/bin/sh set -e start() { if [ -d "/var/run/bucardo" ]; then echo "Directory Exists" echo -n "Starting bucardo: " sudo buca

我要做的是在启动时运行应用程序。所以我把它作为一种服务。ie作为/etc/init.d下的shell脚本。我正在使用Ubuntu。。问题是,如果/var/run目录不存在,我必须在该目录下创建一个文件夹。下面是我的代码

#!/bin/sh
set -e

start() {


if [ -d "/var/run/bucardo" ]; then
    echo "Directory Exists" 
    echo -n "Starting bucardo: "
    sudo bucardo_ctl start 
    echo "done."
else
    echo "Creating Directory" 
    sudo mkdir /var/run/bucardo
    echo -n "Starting bucardo: "
    sudo bucardo_ctl start 
    echo "done."
fi
}

stop() {
echo -n "Shutting down bucardo: "
sudo bucardo_ctl stop
echo "done."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)

esac
exit 0
因此,要在/var/run下创建一个文件夹,它是应用程序的默认文件夹

如何在shell脚本中使用密码创建文件夹。这样我就可以检查文件夹并创建它

下面是我在启动时运行脚本时遇到的错误。我使用了下面的命令“chkconfig--level234 bocardo”

下面是错误

insserv: warning: script 'K01centrifyda' missing LSB tags and overrides
insserv: warning: script 'K01cups' missing LSB tags and overrides
insserv: warning: script 'K01acpi-support' missing LSB tags and overrides
insserv: warning: script 'bucardo' missing LSB tags and overrides
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'hwclock-save' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `hwclock-save'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `hwclock-save'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'ufw' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `ufw'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `ufw'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'lightdm' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `lightdm'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `lightdm'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'acpid' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `acpid'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `acpid'
insserv: warning: script 'centrifyda' missing LSB tags and overrides
insserv: warning: script 'adnisd' missing LSB tags and overrides
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'binfmt-support' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `binfmt-support'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `binfmt-support'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'plymouth-splash' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `plymouth-splash'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `plymouth-splash'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'network-interface' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `network-interface'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `network-interface'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'plymouth-log' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `plymouth-log'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `plymouth-log'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'alsa-restore' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `alsa-restore'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `alsa-restore'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'procps' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `procps'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `procps'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'udevtrigger' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `udevtrigger'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `udevtrigger'
insserv: warning: script 'cups' missing LSB tags and overrides
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'setvtrgb' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `setvtrgb'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `setvtrgb'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'udev' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `udev'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `udev'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
很长时间。。。请帮帮我。。 提前谢谢

根据彼特的建议。。
以下是使其成为Ubentu服务的链接

你没有说问题到底是什么。是不是
sudo mkdir
要求输入密码? Init脚本通常需要已经以root身份运行(并且在正常引导期间将以root身份运行),因此您根本不希望脚本中包含
sudo
。测试时,运行脚本时只需
sudo


还考虑折叠目录存在条件,只使用<代码> MKDIr -P<代码>,如果目录已经存在,则不会出错。

谢谢。实际上,我想在系统启动时运行脚本。那么,是否可以在系统启动时使用sudo运行脚本呢?正如我在回答中所说,init脚本在正常启动时以root运行。不需要sudo。当你自己运行sudo进行测试时,它只是模拟了它在启动时运行时的权限。。我的脚本没有在starup中执行..我键入了以下命令chkconfig--level 234 bocardo on以使服务作为启动。这给了我错误。是否有其他方法使bocardo服务在starup中启动。在Ubuntu?谢谢。。我应该使用什么命令来执行此操作。。我是ubuntu的新手。。我明天试试,让你知道。。再次感谢。@DilipRajkumar:您可能需要在脚本中添加一些必需的标题注释。请参阅
/etc/init.d
中的其他脚本以用作模型。这就是“LSB标签和覆盖”所指的。任何反对投票的人请告诉我原因,以便下次我可以更正。。。