我想在我的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) 我如何使用shell命令获取分支的创建日期。我只需要将在脚本中用作变量的完整日期(例如2010-06-20 13:05:57)。
谢谢
我的数据集(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访问这些值以进行图像处理.但是,我无法正确执行上述步骤
我有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第一个之后的文件_..
任何人都可以帮我写出我的要求的搜索模式吗?
谢谢
当我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) 我知道有一些方法可以在重定向期间运行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中",但是现在没有成功.
我找到了这个.
我写了这个变种:
#!/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)
如何在标题部分正确插入变量?
假设我有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) 假设我有一个变量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) 我在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)