这周我在搞 PowerShell,发现你需要对你的脚本进行签名才能运行它们。Linux 中是否有任何与阻止 bash 脚本运行相关的类似安全功能?
我所知道的与此类似的唯一功能是需要特定密钥的 SSH。
我有一个文件夹,里面有很多文件(xyz1、xyz2,一直到 xyz5025),我需要在每个文件上运行一个脚本,得到 xyz1.faa、xyz2.faa 等等作为输出。
单个文件的命令是:
./transeq xyz1 xyz1.faa -table 11
Run Code Online (Sandbox Code Playgroud)
有没有办法自动做到这一点?也许是一个for-do组合?
我有一个 bash 脚本,只要 Linux 机器开机就可以运行。我按如下所示启动它:
( /mnt/apps/start.sh 2>&1 | tee /tmp/nginx/debug_log.log ) &
Run Code Online (Sandbox Code Playgroud)
启动后,我可以在ps输出中看到 tee 命令,如下所示:
$ ps | grep tee
418 root 0:02 tee /tmp/nginx/debug_log.log
3557 root 0:00 grep tee
Run Code Online (Sandbox Code Playgroud)
我有一个函数可以监视tee生成的日志的大小,并在日志达到一定大小时终止tee命令:
monitor_debug_log_size() {
## Monitor the file size of the debug log to make sure it does not get too big
while true; do
cecho r "CHECKING DEBUG LOG SIZE... "
debugLogSizeBytes=$(stat -c%s "/tmp/nginx/debug_log.log")
cecho r "DEBUG LOG SIZE: $debugLogSizeBytes"
if [ $((debugLogSizeBytes)) …Run Code Online (Sandbox Code Playgroud) bash 变量 LATLNG 在括号中包含纬度和经度值,如下所示
(53.3096,-6.28396)
我想将这些解析为一个名为 LAT 和 LON 的变量,我试图通过 sed 像这样
LAT=$(sed "s/(\(.*\),\(.*\))/\1/g" "$LATLNG")
LON=$(sed "s/(\(.*\),\(.*\))/\2/g" "$LATLNG")
但是,我收到以下错误:
sed: can't read (53.3096,-6.28396): No such file or directory
我遇到了一个有趣的情况,我有一个 Python 脚本,理论上可以由具有各种环境(和路径)和各种 Linux 系统的各种用户运行。我希望这个脚本尽可能多地在没有人为限制的情况下执行。以下是一些已知的设置:
我想在所有这三个上运行相同的可执行 python 脚本。如果它首先尝试使用 /usr/bin/python2.7 会很好,如果它存在,然后回退到 /usr/bin/python2.6,然后回退到 /usr/bin/python2.5,然后如果这些都不存在,就会出错。不过,我并不太喜欢使用最新的 2.x 版本,只要它能够找到正确的解释器之一(如果存在)。
我的第一个倾向是将 shebang 行从:
#!/usr/bin/python
Run Code Online (Sandbox Code Playgroud)
到
#!/usr/bin/python2.[5-7]
Run Code Online (Sandbox Code Playgroud)
因为这在 bash 中工作正常。但是运行脚本会给出:
/usr/bin/python2.[5-7]: bad interpreter: No such file or directory
Run Code Online (Sandbox Code Playgroud)
好的,所以我尝试以下操作,这也适用于 bash:
#!/bin/bash -c /usr/bin/python2.[5-7]
Run Code Online (Sandbox Code Playgroud)
但同样,这失败了:
/bin/bash: - : invalid option
Run Code Online (Sandbox Code Playgroud)
好的,显然我可以编写一个单独的 shell 脚本来找到正确的解释器并使用它找到的任何解释器运行 python 脚本。我只是觉得分发两个文件很麻烦,只要它在安装了最新的 python 2 解释器的情况下运行就足够了。要求人们显式调用解释器(例如,$ python2.5 …
当我在 shell 中运行 time 命令时,time ./myapp我得到如下输出:
real 0m0.668s
user 0m0.112s
sys 0m0.028s
Run Code Online (Sandbox Code Playgroud)
但是,当我运行命令时,\time -f %e ./myapp我失去了精度,我得到:
2.01s
Run Code Online (Sandbox Code Playgroud)
如果我使用该%E命令,我也会以同样的方式失去精度。如何将其更改为再次具有更高的精度,但仍然只输出秒数?
我的研究基于这个Linux / Unix Command: time and on this question
我知道两种命令如何相互连接:
我不知道这是否可行,所以我画了一个假设的连接类型:
怎么可能在命令之间实现循环数据流,例如在这个伪代码中,我使用变量而不是命令。:
pseudo-code:
a = 1 # start condition
repeat
{
b = tripple(a)
c = sin(b)
a = c + 1
}
Run Code Online (Sandbox Code Playgroud) 当我想在bash脚本中要求输入密码时,我会这样做:
read -s
Run Code Online (Sandbox Code Playgroud)
...但是当我bash在 POSIX 模式下运行时sh,该-s选项被拒绝:
$ read -s
sh: 1: read: Illegal option -s
Run Code Online (Sandbox Code Playgroud)
如何使用符合 POSIX 的命令安全地请求输入?
这是一个非常基本的问题,我对 bash 很陌生,无法弄清楚如何做到这一点。不幸的是,谷歌搜索没有让我到任何地方。
我的目标是使用 sftp 连接到服务器,上传文件,然后断开连接。
我有以下脚本:
UpdateJar.sh
#!/bin/bash
sftp -oPort=23 kalenpw@184.155.136.254:/home/kalenpw/TestWorld/plugins
#Change directory on server
#cd /home/kalenpw/TestWorld/plugins
#Upload file
put /home/kalenpw/.m2/repository/com/Khalidor/TestPlugin/0.0.1-SNAPSHOT/TestPlugin-0.0.1-SNAPSHOT.jar
exit
Run Code Online (Sandbox Code Playgroud)
问题是,这个脚本将建立一个 sftp 连接,然后什么都不做。一旦我在连接中手动输入 exit ,它就会尝试执行 put 命令,但由于 sftp 会话已关闭,它只显示 put: command not found。
我怎样才能让它正常工作?
谢谢
我有一个包含以下 2 行的 bash 脚本:
Hour=$(date +"%H")
Hour=$((10#$Hour))
Run Code Online (Sandbox Code Playgroud)
2号线有什么作用?