标签: scripts

外壳检查失败

我的 shell 脚本和 shellcheck.net 有问题。下面的脚本就像一个魅力,但 shellcheck 告诉我必须引用变量,但在脚本中引用变量会阻止脚本工作(我需要分词)。

有人能帮助我吗?

apt-get $COMMAND -y -qq $PACKAGES >/dev/null &
        ^-- SC2086 (info): Double quote to prevent globbing and word splitting.
                        ^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Run Code Online (Sandbox Code Playgroud)

command-line bash scripts

1
推荐指数
1
解决办法
421
查看次数

用于在新服务器上创建用户并设置密码的脚本

我想创建 ubuntu 用户并自动设置密码。我想要脚本运行命令:

useradd -s /usr/sbin/nologin username

passwd username

并设置密码1234

请帮我

bash scripts 20.04

1
推荐指数
1
解决办法
153
查看次数

给新手的一些 Bash 问题

我正在学习 Bash,但有些东西在我的书中没有解释。首先我会发布一个脚本,然后我会通过脚本提出问题。

Bash 脚本:

$ cat sortmerg
#!/bin/bash
usage ()
{
if [ $# -ne 2 ]; then
echo "Usage: $0 file1 file2" 2>&1
exit 1
fi
}

# Default temporary directory
: ${TEMPDIR:=/tmp}

# Check argument count
usage "$@"

# Set up temporary files for sorting
file1=$TEMPDIR/$$.file1
file2=$TEMPDIR/$$.file2

# Sort
sort $1 > $file1
sort $2 > $file2

# Open $file1 and $file2 for reading. Use file descriptors 3 and 4.
exec 3<$file1
exec 4<$file2

# Read the first …
Run Code Online (Sandbox Code Playgroud)

gedit bash scripts

0
推荐指数
2
解决办法
306
查看次数

.sh 未运行且未出现错误

我尝试创建一个 .sh 文件来检查服务器是否正在运行以及是否启动它。我没有从这个脚本中得到任何回声或任何失败,但它没有运行。有人可以帮我解决这个问题或更好的方法来纠正它。我不是程序员,我只是编辑了一些其他脚本来获得它。

JAVA="java -Xms512M -Xmx3072M -XX:PermSize=128m -jar FTBServer.jar nogui"
DIR="/home/jon/FTB/FTBnew"

if [ "$1" = start ] ; then
    if ps -ef | grep FTBServer.jar | grep -v -q grep ; then
        echo "Minecraft is already running"
    else
        echo "Starting!" && cd $DIR && screen -dmS minecraft $JAVA
        sleep 7
        if ps -ef | grep minecraft_server.jar | grep -v -q grep ; then
            echo "Minecraft server started successfully"
        else
            echo "Minecraft server failed to start"
        fi
    fi
fi
Run Code Online (Sandbox Code Playgroud)

这就是我得到的,当我运行它时

root@FTB:/home/jon/FTB/FTBnew# …
Run Code Online (Sandbox Code Playgroud)

bash scripts .sh

0
推荐指数
1
解决办法
176
查看次数

有人可以解释一下这个 bash 脚本的工作原理吗?

我找到了以下我想运行的 bash 脚本,但我不完全确定它要做什么。有人可以解释以下 bash 脚本的工作原理吗?即它在做什么以及它是如何做到的?

echo - "Who are you looking for: "
read user

if [ -n "$user" ]
then
   list=`w | grep $user | cut -c19-30`

   if [ "$list" != "" ]
   then
     echo "The user $user is logged in from $list"
   else
     echo "The user $user is not logged in now"
   fi
fi
Run Code Online (Sandbox Code Playgroud)

command-line scripts

0
推荐指数
1
解决办法
219
查看次数

为什么同一个 .sh 不能与 2 个不同的用户一起执行?

我有两个用户 User1 和 User2。

我在 User2 主文件夹中有这个 script1.sh:

#!/bin/bash

cd /home/user1 && ./script2.sh
Run Code Online (Sandbox Code Playgroud)

调用script2.sh:

#!/bin/bash

if [ 2 > 1 ]; then
echo TRUE!.
else
echo NOT TRUE!
fi
Run Code Online (Sandbox Code Playgroud)

现在,当我使用 user1 执行 script1 时,一切正常。当我使用 user2 执行时,出现此错误:

./script2.sh: line 3: 1: Permission denied
Run Code Online (Sandbox Code Playgroud)

说我不能……如果?如果我在终端上写下所有内容,它也可以工作。所以我的权限:

-rwxrwxr-x 1 user2 group_with_both_users 149 Ago 19 02:41 script2.sh
-rwxr-xr-x 1 user2 group_with_both_users 60 Ago 19 01:38 script1.sh
Run Code Online (Sandbox Code Playgroud)

我真的不知道发生了什么。

command-line bash scripts users .sh

0
推荐指数
1
解决办法
60
查看次数

检查输入以查看它是“y”、“n”还是其他的 bash 脚本 - 不工作

我已经编写了这个 bash 脚本,它旨在检查您的输入以查看它是否是yn或其他内容(这将是更大项目的一部分):

#!/bin/bash

echo "Have you updated the PATH variable in your .bashrc file yet? [y/n]"
read response

        if [$response = "y"]; then
                echo "Checkpoint passed"
                set $checkpoint = "t"
        elif [$response = "n"]; then
                echo "Please set the PATH variable in your .bashrc file before running this script."
                set $checkpoint = "f"
        else            
                echo "Please only use 'y' and 'n'."
                set $checkpoint = "f"
        fi
Run Code Online (Sandbox Code Playgroud)

但是每次运行它时,无论我输入什么,都会收到与此类似的错误:

Have you updated the PATH variable in your …
Run Code Online (Sandbox Code Playgroud)

command-line bash scripts

0
推荐指数
1
解决办法
2573
查看次数

如何通过双击将正在执行的脚本从当前文件夹复制到另一个文件夹

我们应该如何将正在执行的脚本从一个文件夹复制到另一个文件夹?

脚本内容为:

#!/bin/sh

zenity --forms --title="Add Friend" \
    --text="Enter information about your friend." \
    --separator="," \
    --add-entry="First Name" \
    --add-entry="Family Name" \
    --add-entry="Email" \
    --add-calendar="Birthday" >> addr.csv

case $? in
    0)
        echo "Friend added.";;
    1)
        echo "No friend added."
    ;;
    -1)
        echo "An unexpected error has occurred."
    ;;
esac
Run Code Online (Sandbox Code Playgroud)

假设我已将上述脚本保存为test.shin home/user/Documents/sh/,当我通过双击执行test.sh 时,它应该将自身复制到meow文件夹中home/user/wow/meow/

command-line bash scripts

0
推荐指数
1
解决办法
3466
查看次数

如何使用预期脚本做更多事情,而不仅仅是登录

我有一个登录到我的 Beaglebone 的期望脚本:

    #!/usr/bin/expect -f
    spawn ssh debian@192.168.7.2
    expect "debian@192.168.7.2's password:"
    send "temppwd\r"
    interact &&
    mkdir emma &&
    cd emma
Run Code Online (Sandbox Code Playgroud)

这有效并且它登录到 debian 帐户。但是,它会在interact其他两个命令未执行后停止。我该怎么做才能做到这一点?

编辑

好的,谢谢 andy256 我想这interact是错误的,但是,我明白了

执行时无效的命令名称“mkdir”

如何将期望脚本与普通 shell 脚本结合起来?

提前致谢 !

bash scripts beagleboard expect

0
推荐指数
1
解决办法
6406
查看次数

请解释以下命令是什么意思:

awk -F'[ ()+:]+' '
Run Code Online (Sandbox Code Playgroud)

我在我的脚本中使用它。在这种情况下,我可以花时间在括号中,例如:

Fri Dec 18 11:13 - 11:15  (00:02)    
Fri Dec 18 09:11 - 19:42 (1+10:31)
Run Code Online (Sandbox Code Playgroud)

但它是如何工作的?有人可以解释我吗?

scripts awk

0
推荐指数
1
解决办法
106
查看次数

标签 统计

scripts ×10

bash ×8

command-line ×5

.sh ×2

20.04 ×1

awk ×1

beagleboard ×1

expect ×1

gedit ×1

users ×1