如果脚本从命令行运行良好,那么为什么相同的脚本在通过 cron 运行后变成僵尸状态,以及如何解决相同的问题?
下面是真实的例子:
[root@abc ~]# ps ax | grep Z
23880 ? Zs 0:00 [checkloadadv.sh] <defunct>
23926 pts/0 S+ 0:00 grep Z
[root@abc ~]# strace -p 23880
attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted
[root@abc ~]# pstree | grep checkload
init-+-crond---crond-+-checkloadadv.sh
[root@abc ~]# bash /usr/bin/checkloadadv.sh
System Load is OK : 0.05
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 bash 脚本中创建操作系统检测可移植功能,
所以我只想知道,该文件"/etc/issue"对所有 Linux Flavors 都是通用的吗?
如果/var生产服务器上的分区已满,那么解决方案是什么?
以下是我的解决方法:
请建议我更多可能的方法来解决和克服这个问题。
如果你能分享你曾经遇到过的这个问题的经验,那对我会很有帮助。
我创建了这个函数,它打印输出,如示例图像中所示。但是,这个功能的实现似乎太复杂了。
有什么方法可以改进它或实施替代解决方案吗?

#!/bin/bash
function box_out() {
input_char=$(echo "$@" | wc -c)
line=$(for i in `seq 0 $input_char`; do printf "-"; done)
# tput This should be the best option. what tput does is it will
# read the terminal info and render the correctly escaped ANSI code
# for you.
# Code like \033[31m will break the readline library in some of the
# terminals.
tput bold
line="$(tput setaf 3)${line}"
space=${line//-/ }
echo " ${line}"
printf '|' ; echo -n …Run Code Online (Sandbox Code Playgroud) 我的 Apache 服务器 IP 地址是 192.168.1.100,域名是test.local.
我怎样才能做到这一点?
我正在尝试删除数组元素的范围,但失败了..
我的数组
root@ubuntu:~/work# echo ${a[@]}
cocacola.com airtel.com pepsi.com
Run Code Online (Sandbox Code Playgroud)
打印 0-1 数组看起来没问题
root@ubuntu:~/work# echo ${a[@]::2}
cocacola.com airtel.com
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用以下方法仅删除这些元素:
root@ubuntu:~/work# unset a[@]::2
root@ubuntu:~/work# echo ${a[@]}
Run Code Online (Sandbox Code Playgroud)
这是删除整个数组..
我做错了什么?
我找到了其他删除数组范围的方法,但为什么上面的东西不起作用?
for ((i=0; i<2; i++)); do unset a[$i]; done
Run Code Online (Sandbox Code Playgroud)
编辑我也试过但没有运气
unset -v 'a[@]::2'
Run Code Online (Sandbox Code Playgroud) 我试图搜索并替换文件的一些线,但是当我运行sed,如果该正则表达式不匹配,那么sed不返回所以不是增加一个条件与任何状态代码grep,有没有办法sed?为什么sed不返回退出状态?
问题 :

我有休文件,其中包含以下详细信息:
define host{
use generic-host ; Name of host template to use
host_name ServerA_172.29.16.102
alias ServerA_172.29.16.102
address 172.29.16.102
check_command check-host-alive
max_check_attempts 3
notification_interval 120
notification_period 24x7
}
define host{
use generic-host ; Name of host template to use
host_name ServerB_172.29.16.103
alias ServerB_172.29.16.103
address 172.29.16.103
check_command check-host-alive
max_check_attempts 3
notification_interval 120
notification_period 24x7
}
Run Code Online (Sandbox Code Playgroud)
我想要什么,搜索"address 172.29.16.102"和删除 5 行上方和之后的 4 行。
我试过用 sed 跟踪但没有用
sed '$N;$N;N;/address 172.29.16.102/,+5d' hosts
Run Code Online (Sandbox Code Playgroud) 我在脚本中使用以下选项在终端以及 /var/log/messages 上打印
echo "System Load is OK : $Current_loadadv"
echo "System Load is OK : $Current_loadadv" | logger
Run Code Online (Sandbox Code Playgroud)
但我怎么能在单行中做到这一点?
我一直在测试使用最大 inode 的查找目录,并且在测试时我已经运行
touch test_{1..1391803}.txt
Run Code Online (Sandbox Code Playgroud)
但它给了我错误"-bash: /usr/bin/touch: Argument list too long",现在我在命令下运行,但似乎需要 Hugh 时间
ruby -e '1.upto(1391803) { |n| %x( touch "test_#{n}.txt" ) }'
Run Code Online (Sandbox Code Playgroud)
所以问题是:有没有办法在短时间内创建多个文件?我应该每个循环触摸 1 个 lac 文件还是更好的方法?
测试结果 :
1号
[root@dc1 inode_test]# time seq 343409 | xargs touch
real 0m7.760s
user 0m0.525s
sys 0m4.385s
Run Code Online (Sandbox Code Playgroud)
2号
[root@test-server inode_test]# time echo 'for (i=1;i<=343409;i++) i' | bc | xargs touch
real 0m8.781s
user 0m0.722s
sys 0m4.997s
Run Code Online (Sandbox Code Playgroud)
3号
[root@test-server inode_test]# time printf '%s ' {1..343409} | xargs touch
real 0m8.913s
user …Run Code Online (Sandbox Code Playgroud) bash ×2
sed ×2
apache-httpd ×1
array ×1
disk-usage ×1
etc ×1
files ×1
logger ×1
login ×1
portability ×1
printf ×1
process ×1
shell ×1
shell-script ×1
touch ×1
tput ×1