我需要运行一个只能运行特定用户和组的脚本。 命令的格式就像
$PROGRAM_HOME/bin/installService.sh [USER [GROUP]]
我试着运行脚本
$PROGRAM_HOME/bin/installService.sh root root
但是我得到以下错误
** ERROR: Only root user can install artifactory as a service
当我用sudo运行它时,我得到另一个错误
** ERROR: Could not change values in /etc/init.d/artifactory
这是确切的错误
** INFO: Please edit the files in /etc/opt/jfrog/artifactory to set the correct environment Especially /etc/opt/jfrog/artifactory/default that defines ARTIFACTORY_HOME, JAVA_HOME and JAVA_OPTIONS cp: /etc/init.d/artifactory: No such file or directory chmod: /etc/init.d/artifactory: No such file or directory sed: illegal option -- - usage: sed script [-Ealn] [-i extension] [file ...] sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...] ** ERROR: Could not change values in /etc/init.d/artifactory Whats the correct syntax to run it as a root?
我遵循的一些步骤进行debugging
我在版本4.11.1这是我特别感兴趣的版本
我正在按照文档中的步骤https://www.jfrog.com/confluence/display/RTF/Installing+on+Linux+Solaris+or+Mac+OS
我在Mac OSX EI Capitan 10.11.5上
出错后,我修复了/ opt / jfrog / artifactory / default中的ARTIFACTORY_HOME位置
我用sudo -s作为root运行了安装脚本,但得到了相同的确切错误。
我也尝试过另一个版本,看看这个版本的脚本是否有问题,但是得到相同的错误
我的猜测是脚本的这部分失败
installService() { serviceName=$(basename $artServiceFile) serviceFiles=$artBinDir/../misc/service if [ -e "$artServiceFile" ]; then cp -f $artServiceFile $serviceFiles/$serviceName.init.backup fi cp -f $serviceFiles/artifactory $artServiceFile chmod a+x $artServiceFile
并以debugging模式运行脚本的输出
root# bash -x ./installService.sh + checkRoot + curUser= + '[' -x /usr/xpg4/bin/id ']' ++ id -nu + curUser=root + '[' root '!=' root ']' + '[' ./installService.sh = . ']' + '[' ./installService.sh = source ']' +++ dirname ./installService.sh ++ cd . ++ pwd + artBinDir=/opt/artifactory-pro-4.11.1/bin +++ dirname /opt/artifactory-pro-4.11.1/bin ++ cd /opt/artifactory-pro-4.11.1 ++ pwd + artExtractDir=/opt/artifactory-pro-4.11.1 + ARTIFACTORY_HOME=/opt/artifactory-pro-4.11.1 + '[' -n '' ']' + artEtcDir=/etc/opt/jfrog/artifactory + TOMCAT_HOME=/opt/artifactory-pro-4.11.1/tomcat + artLogDir=/opt/artifactory-pro-4.11.1/logs + artRunDir=/opt/artifactory-pro-4.11.1/run + '[' -n '' ']' + artServiceFile=/etc/init.d/artifactory + artDefaultFile=/etc/opt/jfrog/artifactory/default + getArtUser '' + '[' -n '' ']' + '[' -z '' ']' + ARTIFACTORY_USER=artifactory + getArtGroup '' + '[' -n '' ']' + echo + echo 'Installing artifactory as a Unix service that will run as user artifactory' Installing artifactory as a Unix service that will run as user artifactory + echo 'Installing artifactory with home /opt/artifactory-pro-4.11.1' Installing artifactory with home /opt/artifactory-pro-4.11.1 + createArtUser + echo -n 'Creating user artifactory...' Creating user artifactory...++ getent passwd artifactory ++ awk -F: '{print $1}' ./installService.sh: line 40: getent: command not found + artifactoryUsername= + '[' '' = artifactory ']' + echo -n creating... creating...++ which bash + useradd -m -s /usr/local/bin/bash artifactory ./installService.sh: line 45: useradd: command not found + '[' '!' 127 ']' + echo ' DONE' DONE + createArtGroup + '[' '' == '' ']' + return 0 + createArtEtc + echo + echo -n 'Checking configuration link and files in /etc/opt/jfrog/artifactory...' Checking configuration link and files in /etc/opt/jfrog/artifactory...+ '[' -L /opt/artifactory-pro-4.11.1/etc ']' + echo -n 'already exists, no change...' already exists, no change...+ echo -e ' DONE' DONE + createArtDefault + echo -n 'Creating environment file /etc/opt/jfrog/artifactory/default...' Creating environment file /etc/opt/jfrog/artifactory/default...+ '[' -e /etc/opt/jfrog/artifactory/default ']' + echo -n 'already exists, no change...' already exists, no change...+ echo -e ' DONE' DONE + echo -e '\033[33m** INFO: Please edit the files in /etc/opt/jfrog/artifactory to set the correct environment\033[0m' ** INFO: Please edit the files in /etc/opt/jfrog/artifactory to set the correct environment + echo -e '\033[33mEspecially /etc/opt/jfrog/artifactory/default that defines ARTIFACTORY_HOME, JAVA_HOME and JAVA_OPTIONS\033[0m' Especially /etc/opt/jfrog/artifactory/default that defines ARTIFACTORY_HOME, JAVA_HOME and JAVA_OPTIONS + createArtRun + '[' '!' -d /opt/artifactory-pro-4.11.1/run ']' + installService ++ basename /etc/init.d/artifactory + serviceName=artifactory + serviceFiles=/opt/artifactory-pro-4.11.1/bin/../misc/service + '[' -e /etc/init.d/artifactory ']' + cp -f /opt/artifactory-pro-4.11.1/bin/../misc/service/artifactory /etc/init.d/artifactory cp: /etc/init.d/artifactory: No such file or directory + chmod a+x /etc/init.d/artifactory chmod: /etc/init.d/artifactory: No such file or directory + sed --in-place -e ' /processname:/ s%artifactory%artifactory%g; /Provides:/ s%artifactory%artifactory%g; s%# pidfile: .*%# pidfile: /opt/artifactory-pro-4.11.1/run/artifactory.pid%g; s%/etc/opt/jfrog/artifactory/default%/etc/opt/jfrog/artifactory/default%g; ' /etc/init.d/artifactory sed: illegal option -- - usage: sed script [-Ealn] [-i extension] [file ...] sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...] + errorArtHome 'Could not change values in /etc/init.d/artifactory' + echo + echo -e '\033[31m** ERROR: Could not change values in /etc/init.d/artifactory\033[0m' ** ERROR: Could not change values in /etc/init.d/artifactory + echo + exit 1
不幸的是有时这些事情发生 也许脚本是旧的或为不同的操作系统写的,或者你缺less它需要的软件包,或者只是太烂了。 有办法来处理它。
你是从shell脚本的angular度来问这个问题的,所以我就是这样回答的。 此外,我不知道你的操作系统是什么(或版本),你得到的是什么软件(和它的版本),以及你如何达到这一点,以及你正在做什么。
你有没有按照说明在/etc/opt/jfrog/artifactory定义设置的警告?
你正在使用这个软件/脚本的最新版本 ?
您的脚本在失败时正在修改/访问(或创build?)初始化脚本 :
/etc/init.d/artifactory
debugging/修复的东西
在不知道脚本正在执行的所有步骤的情况下,很难说出为什么要获取这些消息。
首先,获得一个根壳,只是为了它的。 sudo -s , sudo su -或者su -应该可以帮到你。
那么 – /etc/init.d存在? /etc/init.d/artifactory是否存在?
您可以打开脚本并通读它,查找问题。 或者你可以运行一步一步的debugging输出为:
bash -x <script> <args>
如果事实如此,只需使用bash运行脚本,有时候可能会有所帮助,因为有些shell脚本在顶部包含#!/bin/sh ,而至less可以在Ubuntu系统上调用dash 。 短划线可能导致一些bash脚本失败。
bash <script> <args>
当你发现问题(用脚本或你的系统)修复它并重新运行脚本。 如果事情没有解决,请回来,用有用的信息更新你的问题。