标签: shell

在Linux Ubuntu上将jar文件作为Daemon运行

我想在我的Teamspeak3上安装一个bot,并在启动时将该bot作为守护进程运行.我编写了自己的脚本并将其复制到init.d,然后将其添加update-rc.d到默认值.

#!/bin/sh
#
# JTS3ServerBot Script
#
USER="ts"
NAME="jts3"
DIR="/home/ts/jts3/"
case $1 in
    start)
        echo "Starting ${NAME} ..."
        if [ ! -f $DIR/pid ]; then
            sudo -u $USER -c nohup java -jar $DIR/JTS3ServerMod.jar $DIR 2>> /dev/null >> /dev/null &
            echo $! > $DIR/pid
            echo "${NAME} started ..."
        else
            echo "${NAME} is already running ..."
        fi
    ;;
    stop)
        if [ -f $DIR/pid ]; then
            PID=$(cat $DIR/pid);
            echo "Stopping ${NAME} ..."
            kill $PID;
            echo "${NAME} stopped ..."
            rm $DIR/pid
        else …
Run Code Online (Sandbox Code Playgroud)

linux bash shell daemon jar

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

从SVN获取分支创建日期

我如何使用shell命令获取分支的创建日期。我只需要将在脚本中用作变量的完整日期(例如2010-06-20 13:05:57)。

谢谢

svn bash shell version-control

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

将逗号分隔的字符串拆分为shell脚本中的数组值?

我的数据集(data.txt)看起来像这样[imageID,sessionID,height1,height2,x,y,crop]:

1,0c66824bfbba50ee715658c4e1aeacf6fda7e7ff,1296,4234,194,1536,0
2,0c66824bfbba50ee715658c4e1aeacf6fda7e7ff,1296,4234,194,1536,0
3,0c66824bfbba50ee715658c4e1aeacf6fda7e7ff,1296,4234,194,1536,0
4,0c66824bfbba50ee715658c4e1aeacf6fda7e7ff,1296,4234,194,1536,950
Run Code Online (Sandbox Code Playgroud)

这些是我希望使用的一组值.我是shell脚本的新手:)我像这样逐行读取文件,

cat $FILENAME | while read LINE
do
string=($LINE)
# PROCESSING THE STRING
done
Run Code Online (Sandbox Code Playgroud)

现在,在上面的代码中,在获取字符串之后,我希望执行以下操作:1.将字符串拆分为逗号分隔值.2.将这些变量存储到像imageID [],sessionID []这样的数组中.

我需要使用imagemagick访问这些值以进行图像处理.但是,我无法正确执行上述步骤

unix arrays string shell awk

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

找到命令搜索模式

我有4个以下的文件

a_ROLLBACK2to3__test.sql,
a_1to2__test.sql,
a_2to3__test.sql,
a_2to2__test.sql
Run Code Online (Sandbox Code Playgroud)

我想写一个find命令来返回文件a_1to2__test.sql,a_2to3__test.sql并且a_2to2__test.sql该文件a_ROLLBACK2to3__test.sql不应该包含在搜索中.

我的find命令看起来像

find . -name "*_*to*__*.sql"
Run Code Online (Sandbox Code Playgroud)

但这会返回所有文件,但我不想要a_ROLLBACK2to3__test.sql.

基本上不应该包括ROLLBACK第一个之后的文件_..

任何人都可以帮我写出我的要求的搜索模式吗?

谢谢

unix linux shell find

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

什么是./lks.sh:运行shell脚本时Linux中的权限被拒绝了?

当我lks.sh在我的系统中运行文件时,显示权限被拒绝:

./lks.sh  bash: ./lks.sh: Permission denied
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能运行这个shell脚本?

这是我的.sh档案:

lokesh = "wait"
if[$lokesh == "wait"]
        echo "$lokesh"

else
        sudo shutdown -h now
Run Code Online (Sandbox Code Playgroud)

unix linux bash shell

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

如何在重定向<< EOF期间运行bash命令

我知道有一些方法可以在重定向期间运行bash命令,但我不知道它是如何完成的.

我想做这样的事情:

#!/bin/bash
mysql -uUser -pPasswd << EOF
echo 'I wanna echo something by using echo which is run by bash'
use Mydb
some sql commands here
commit;
EOF
Run Code Online (Sandbox Code Playgroud)

我曾经错误地使用"在"<< EOF中",但是现在没有成功.

mysql bash shell eof io-redirection

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

如何使用cURL从文件中读取标头?

我找到了这个.

我写了这个变种:

#!/bin/bash
while read line ; do
  headers="$headers -H '$line'"
done < public/headers.txt
echo $headers
curl -X PUT \
     $headers \
     -d @'public/example.json' \
     echo.httpkit.com
Run Code Online (Sandbox Code Playgroud)

在headers.txt我有:

X-PAYPAL-SECURITY-USERID:123
X-PAYPAL-SECURITY-PASSWORD:123
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时,我./public/curl.sh没有得到我发送的标题.

我用env var隔离了这个问题:

$ x='-H some:asd'
$ curl $x echo.httpkit.com
=> header was NOT present
$ curl -H 'some:asd' echo.httpkit.com
=> header was present
$ curl -H some:asd echo.httpkit.com
=> header was present
Run Code Online (Sandbox Code Playgroud)

如何在标题部分正确插入变量?

linux shell curl

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

在shell脚本中执行mysql查询

假设我有2个数据库nm和nm_history.我需要从两个数据库中获取记录.如果我在mysql中执行查询,它的工作正常.但是如果我在bin/bash中执行该查询,则会返回以下错误

**

mysql: option '-e' requires an argument
./get_rec.sh: line 4: subscriber_2: command not found
./get_rec.sh: line 4: a_party: command not found
./get_rec.sh: line 4: subscriber_2: command not found
./get_rec.sh: line 4: prov_channel: command not found
./get_rec.sh: line 4: subscriber_2: command not found
./get_rec.sh: line 4: created: command not found
./get_rec.sh: line 4: svc_mgmt_07: command not found
./get_rec.sh: line 4: created: command not found
./get_rec.sh: line 4: subscriber_2: command not found
./get_rec.sh: line 4: svc_mgmt_07: command not found
./get_rec.sh: line …
Run Code Online (Sandbox Code Playgroud)

mysql sql linux bash shell

3
推荐指数
2
解决办法
2万
查看次数

在ksh中获取字符串的最后n个字符

假设我有一个变量name持有一些字符串值

要获取最后n个字符,在bash中我们写:

$ echo "${name: -n}"
Run Code Online (Sandbox Code Playgroud)

什么是相同的方式ksh,我已经看到sed和awk方法,但我正在寻找的是一个线或管道解决方案类似于bash提取最后的字符

到目前为止,这些是错误和努力:

AB12 $ name="123456"

AB12 $ echo ${name:(-3)}
ksh: ${name:(-3)}: bad substitution

AB12 $ echo${name:0:-3}
ksh: echo${name:0:-3}: bad substitution

AB12 $ print ${name%?}
12345

AB12 $  echo "some string" | tail -c -1
tail: cannot open input

AB12 $ echo -n "my string discard"| tail -c -1
tail: cannot open input

AB12 $ echo "foo"| cut -c 1-2
fo

AB12 $ echo "foo"| …
Run Code Online (Sandbox Code Playgroud)

linux string shell ksh solaris

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

解释dumpsys cpuinfo

我在android shell中寻找命令"dumpsys cpuinfo"的结果的解释.

:# dumpsys cpuinfo
Load: 17.78 / 16.97 / 16.29
CPU usage from 35983ms to 21604ms ago:
  97% 25268/com.firstprocess: 78% user + 19% kernel / faults: 19938 minor
  36% 25680/com.secondprocess: 19% user + 17% kernel / faults: 950 minor
  11% 25151/com.anotherprocess: 8.8% user + 2.4% kernel / faults: 13794 minor 6 major
  18% 739/system_server: 13% user + 5.4% kernel / faults: 3803 minor 2 major
  14% 1242/android.process.media: 11% user + 2.7% kernel / faults: 2413 minor
  8.4% 333/adbd: …
Run Code Online (Sandbox Code Playgroud)

shell cpu android dumpsys

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

标签 统计

shell ×10

linux ×6

bash ×5

unix ×3

mysql ×2

string ×2

android ×1

arrays ×1

awk ×1

cpu ×1

curl ×1

daemon ×1

dumpsys ×1

eof ×1

find ×1

io-redirection ×1

jar ×1

ksh ×1

solaris ×1

sql ×1

svn ×1

version-control ×1