bash

Execute command and compare it in a if statement

你说的曾经没有我的故事 提交于 2021-02-08 10:35:12
问题 I am using bash scripting to check whether two specific directories are containing some specific number of files. lets assume 20. Is it possible to check it in a line inside a if statement? #!/bin/bash if [ [ls /path/to/dir1 | wc -l ] != 20 || [ ls /path/to/dir2 | wc -l ] != 50 ]; then echo "do this!" elif echo "do that!" fi 回答1: The syntax is incorrect: if [[ $(ls /path/to/dir1 | wc -l) != 20 || $(ls /path/to/dir2 | wc -l) != 50 ]] then echo "do this!" else echo "do that!" fi (I move the

source bashrc doesn't work in cron

北战南征 提交于 2021-02-08 10:30:54
问题 All we know that cron ignores variables defined in “.bashrc” and “.bash_profile”, so we have to define it inside cron. I constantly do the same what was written inside the similar question https://unix.stackexchange.com/questions/67940/cron-ignores-variables-defined-in-bashrc-and-bash-profile but still global variables inside .bashrc still not working. I found way to execute it - by defining sh script with "set +a" bashrc script. But "source" still doesn't work. SHELL=/bin/bash BASH_ENV=/root

Escaping double quotation marks in sed

依然范特西╮ 提交于 2021-02-08 10:28:24
问题 Creating a search and replace function for my application, I am running a test scenario with 3 files, array tscript test I am trying to escape double quotation marks but it wont work script file contains variableName=$1 sed "s#data\-field\=\"${variableName}\.name\"#data\-field\=${variableName}\.name data\-type\=dropdown data\-dropdown\-type\=${variableName}#g" test test file contains data-field=“fee_category.name” data-field=“tax_type.name” array file contains fee_category tax_type There is

How to close file in awk while generating a list of?

笑着哭i 提交于 2021-02-08 10:18:37
问题 Guys I'm trying to find a way to don't have the awk error "too many open file" . Here's my situation: INPUT : ASCII file, lot of line, with this scheme: NODE_212_lenght.._1 NODE_212_lenght.._2 NODE_213_lenght.._1 NODE_213_lenght.._2 In order to split this file with every record with the same NODE number, I've used this one-liner awk command awk -F "_" '{print >("orfs_for_node_" $2 "")}' <file With a file composed by lots of lines, this command keeps sayin "too many open files" . I've tried

Corrent passing arguments to docker entrypoint

做~自己de王妃 提交于 2021-02-08 10:13:07
问题 I have a super dumb script $ cat script.sh cat <<EOT > entrypoint.sh #!/bin/bash echo "$@" EOT docker run -it --rm -v $(pwd)/entrypoint.sh:/root/entrypoint.sh --entrypoint /root/entrypoint.sh bash:4 Hello World But when I run script I got strange error: $ sh script.sh standard_init_linux.go:207: exec user process caused "no such file or directory" Why script does not print Hello world ? 回答1: standard_init_linux.go:207: exec user process caused "no such file or directory" The above error means

Find specific files and move them with smbclient

北战南征 提交于 2021-02-08 10:12:46
问题 $ find /opt/backup/test -name "*.gz" -exec smbclient -A \ /opt/backup/smbclient_authentication.txt //1.1.1.1/test -c put '{}' \; There are multiple directories and other files then *.gz under the dir and I want to move the files found with find with smbclient. Of course, this does not work, since I am missing the last bit. Connection to the share works, and find works, it's just the last bit that does not. Any ideas? 回答1: You can use xargs to create parameters from input stream xargs find

Find specific files and move them with smbclient

﹥>﹥吖頭↗ 提交于 2021-02-08 10:12:04
问题 $ find /opt/backup/test -name "*.gz" -exec smbclient -A \ /opt/backup/smbclient_authentication.txt //1.1.1.1/test -c put '{}' \; There are multiple directories and other files then *.gz under the dir and I want to move the files found with find with smbclient. Of course, this does not work, since I am missing the last bit. Connection to the share works, and find works, it's just the last bit that does not. Any ideas? 回答1: You can use xargs to create parameters from input stream xargs find

What is the correct way to use the bash if else && || shortcut?

守給你的承諾、 提交于 2021-02-08 09:56:53
问题 I have come across some strange behavious (well probably not strange but I don't understand it !) I want to write some if / e,se statements using the bash shorthand syntax: [[ 1 -eq 1 ]] && echo "true" || echo "false" The output of the above code gives: true Now the code above actually works fine. But this next code does not: [[ 1 -eq 1 ]] && infMsg "true" || infMsg "false" infMsg is just a function. The output from the above code gives: true false I only want it to say 'true'. Is there

Linux_修复GRUB引导故障的3种方法!

半城伤御伤魂 提交于 2021-02-08 09:49:34
修复GRUB引导故障 一.修复GRUB引导故障 1. 故障原因 2. 故障现象 3. 解决思路 4.修复GRUB引导故障 二.修复GRUB引导故障方法1 ——方法一:手动输入引导命令(笨拙繁琐,不建议使用) 三.修复GRUB引导故障方法2 ——方法二:进入急救模式,恢复GRUB引导程序 ——主引导程序记录被破坏 1.创建磁盘,格式化,挂载,备份文件 2.模拟对MBR中的GRUB引导程序的破坏,不破坏分区表 3.引导界面进入急救模式,从备份文件中恢复GRUB引导程序 四.方法二具体实验步骤: 1.创建磁盘,格式化,挂载,备份文件 2.模拟对MBR中的GRUB引导程序的破坏,不破坏分区表 3.引导界面进入急救模式,从备份文件中恢复GRUB引导程序 五.引导界面进入急救模式,方法3 重建GRUB菜单配置文件 ————配置文件丢失、删除 重新构建GRUB菜单的配置文件 退出chroot环境,并重启 六.引导界面进入急救模式,方法3实验步骤 重建GRUB菜单配置文件实验 重新构建GRUB菜单的配置文件 退出chroot环境,并重启 一.修复GRUB引导故障 1. 故障原因 MBR中的GRUB弓|导程序遭到破坏 grub.conf文件丢失、引导配置有误 2. 故障现象 系统引导停滞,显示“grub>" 提示符 3. 解决思路 尝试手动输入引导命令 进入急救模式,重写或者从备份中恢复grub

Bash Script - fswatch trigger bash function

余生长醉 提交于 2021-02-08 09:47:38
问题 I have a bash script where I want to trigger a method every time the filesystem is changed: #!/bin/bash function run { echo Do some magic // Do some magic } run fswatch . src | 'run' In this case I am watching the src folder. When I trigger the script via ./automater.sh the script executes the run function the first time correctly and when I then change some file, the script simply exits... 回答1: BUT then it runs in a loop.... , I also hit this, because after your ./automater.sh execution,