bash脚本

以下是为您整理出来关于【bash脚本】合集内容,如果觉得还不错,请帮忙转发推荐。

【bash脚本】技术教程文章

linux – 如何使用bash脚本中的tmux将屏幕拆分为3【代码】

我正在编写一个bash脚本,将屏幕拆分为3并在每个窗格上运行命令. 我基本上想要运行bash脚本,bash脚本应该将我的屏幕拆分为3,然后在窗格中运行top,在另一个窗格中运行htop,在第三个窗格中运行perl re.pl 任何帮助或指示都是赞赏的!解决方法:直接的方法是创建一个分离的会话,创建窗格,然后附加到会话.# -d says not to attach to the session yet. top runs in the first # window tmux new-session -d top # In the most recently c...

linux – 选择文件时bash脚本中的意外标记’附近的语法错误【代码】

运行此脚本bash ./cleanup.bash#!/bin/bash ## going to dir moving stuff rm -rf !(composer.json|.git)给出错误:cleanup.bash: line 10: syntax error near unexpected token ‘(‘cleanup.bash: line 10: ‘rm -rf !(composer.json|.git)’但如果我直接在终端中运行没有问题rm -rf!(composer.json | .git) 我尝试剥离所有其他行,仍然得到错误. 如何在bash脚本中正确输入?解决方法:我想你的问题是由于从脚本运行时没有设置she...

linux – Bash脚本 – 不检测变量中的文件名【代码】

在BASH脚本中,我正在尝试检测文件是否存在.文件名在变量中,但-e命令似乎无法检测到该文件.以下代码始终输出“?/ misc / tasks / drupal_backup.sh不存在”filename="~/misc/tasks/drupal_backup.sh"if [ -e "$filename" ]; thenecho "$filename exists" else echo "$filename does not exist" fi另一方面,以下代码正确检测文件:if [ -e ~/misc/tasks/drupal_backup.sh ]; thenecho "$filename exists" else echo "$filename does ...

linux – 使用R Markdown将bash脚本作为Cron作业运行【代码】

我想尝试如何从R markdown文件渲染html,但是从作为Cron作业运行的bash脚本中渲染.我不知道为什么一切正常,除了作为Cron工作运行.我所做的: 我的脚本是Rstudio的演示脚本--- title: "test" author: "sms" date: "24 maja 2015" output: html_document ---This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <htt...

linux – Bash脚本启动铬,睡20秒,然后安静地关闭【代码】

我正在尝试创建一个bash脚本,它将启动铬,等待20秒,然后关闭铬. 这是为了xbmcbuntu所以我可以打开一个站点,然后它会在20秒后自动关闭(因为我无法用遥控器关闭它). 我有的是:#!/bin/bash openbox & /usr/bin/chromium-browser sleep 20 killall -9 openboxChromium打开确定,但永远不会关闭. 我错过了什么?解决方法:由于您没有在后台使用chrome-browser,因此在chrome-browser完成执行之前,chrome-browser命令之后的所有代码都不会执...

linux – 使用mailx和bash脚本解析邮件的正文【代码】

我试图使用电子邮件自动化我的工作的某些部分.是否有任何方法已经可以使用mailx和bash我可以用来提取邮件的正文?解决方法:如果这是通过类似sendmail的MTA传递到本地用户帐户的邮件,那么您可以使用procmail在发送邮件时对其进行解析. 在我使用的系统上,sendmail会检查?/ .forward文件,所以我在~username / .forward中有这个# pipe incoming mail to procmail # ref: http://www.panix.com/~elflord/unix/procmail.html # ref: http...

linux – 将whatis钩子添加到bash脚本中【代码】

我刚刚发现了whatis并希望在我的bash脚本中添加信息. 将信息添加到bash脚本中的最佳方法是什么?whatis捡起?解决方法:whatis从whatis数据库获取所有信息,这是使用命令makewhatis生成的. 有两种方法可以将条目添加到数据库中. >创建并安装程序或脚本的手册页,然后运行makewhatis.>手动编辑whatis数据库.(不建议) makewhatis从命令手册页的NAME部分获取第一行. whatis数据库在我的机器上的位置是/usr/share / man / whatis,这是它??...

linux – 在读取(stdin)循环后暂停bash脚本【代码】

我正在创建一个通过管道(stdin)获取输入的脚本,如(other_command | my_script).但是,在我读完整个标准输入后,我需要暂停脚本并等待用户按下回车键. 这是一个示例脚本.#!/bin/bashif [[ -t 0 ]]; thenecho "No stdin" elseecho "Got stdin"while read input; doecho $inputdone fiecho "Press enter to exit" read它就是这样的;$echo text | ./script Got stdin text Press enter to exit $它跳过我最后的阅读. 然而;$./script No s...

linux – 如何从另一个shell向bash脚本发送信号【代码】

我启动以下脚本,我在前台运行bash shell(比如说shell1),从另一个shell(shell2)运行kill -SIGUSR1 pidof(scriptA).什么都没发生.我究竟做错了什么 ?我尝试了其他信号(SIGQUIT等)但结果是一样的. test_trap.shfunction iAmDone { echo "Trapped Signal"; exit 0 } trap iAmDone SIGUSR1 echo "Running... " tail -f /dev/null # Do nothing在shell1中./test_trap.sh在shell2中kill -SIGUSR1 ps aux | grep [t]est_trap | awk '{p...

linux – Bash脚本:不使用$@或$*扩展参数【代码】

使用$@,您可以对bash中的文件列表执行操作.例: script.sh:#!/bin/bash list=$@ for file in $list; do _commands_; done然后我可以用这个程序调用~/path/to/./script dir1/{subdir1/*.dat,subdir2/*}这个参数将扩展为许多成为$list的参数.但现在我想要其他参数,比如1美元,2美元,这个名单是3美元.所以我想在脚本中发生dir1 / {subdir1 / * .dat,subdir2 / *}的扩展,而不是成为很多参数.在命令行上,您可以执行以下操作:find dir1/...