Tag: bash

crontab工作无法正常工作

Backgound 我试图使用crontab每分钟运行一个sh脚本,但它无法正常工作。 问题 当我手动运行脚本时,它会正确执行,但是crontab无法执行。 我使用crontab -e创建了作业,我可以看到cron正在运行,因为如果我键入pgrep cron我会得到PID作为回报。 我也知道我的时间格式是正确的,因为我用这个在线测试仪进行了测试 。 码 wallpaperSlider.sh : #!/bin/bash feh –randomize –bg-fill /home/username/Pictures/wallpapers/* crontab工作 : SHELL=/bin/bash * * * * * username /home/username/.crons/wallpaperSlider.sh 研究 我已经阅读了AskUbuntu中最常见的错误,我认为我没有遇到任何错误。 我明白也许我错过了一些环境变量,但我不知道如何检查。 我也知道crontab -e更改/创建了一个tmp文件,在我的例子中是/tmp/crontab.wCajAu/crontab 。 题 如何在cron中执行此脚本? 考虑到crontab -e更改了tmp文件夹中的文件,重启后是否会丢失所有更改?

可以将行绘制字符(或颜色)添加到Bash文件列表菜单中吗?

我使用我正在学习的第一个Linux工具BASH创建了世界上最丑陋的菜单。 菜单看起来像什么 The following /usr/local/bin/bell/sounds were found 1) /usr/local/bin/bell/sounds/Amsterdam.ogg 2) /usr/local/bin/bell/sounds/bell.ogg 3) /usr/local/bin/bell/sounds/Blip.ogg 4) /usr/local/bin/bell/sounds/default.ogg 5) /usr/local/bin/bell/sounds/Mallet.ogg 6) /usr/local/bin/bell/sounds/message.ogg 7) /usr/local/bin/bell/sounds/Positive.ogg 8) /usr/local/bin/bell/sounds/Rhodes.ogg 9) /usr/local/bin/bell/sounds/Slick.ogg ‘a’ to hear to all files, use number to hear a single file, ‘u’ to update last single file heard as new default, or ‘q’ to quit: 代码 #! /bin/bash […]

如何在关机时运行脚本?

如何才能在关机时运行bash脚本? 我已经搜索过它并且空手而归。 如果有链接或解释如何,我会没事的。

温度和RAM监控脚本

我有以下脚本: while : do clear; echo “—————————RAM Load——————————$ free -mt >> memory.txt; free -mt; echo “—————————Temperature—————————$ sensors >> temp.txt; sensors; sleep 1; clear; done 获取当前系统RAM和温度并将其写入两个文件,分别为memory.txt和temp.txt 我想在带有Dygraphs的Web服务器上使用这些数据,这是清理数据的最佳方法,因为它提供了这两个文件: memory.txt temp.txt 对于RAM部分,我只需要-/+ buffers/cache:行,而温度部分只需要温度。

有没有办法别名命令cd,以便它保护参数?

当我跑 cd My folder 有一个错误,因为我没有保护字符串。 bash: cd: My: No such file or directory 但这很好用 cd “My folder” 有没有办法将cd重新定义为别名或函数,以便它自动保护所有以下参数作为一个单独的字符串? 这种方法不起作用,因为我认为它不会: cd () { cd “$*” ; }

如何递归地比较两个目录并检查其中一个目录是否包含另一个目录?

我有两个目录,它们包含公共文件。 我想知道一个目录是否包含与另一个目录相同的文件。 我在网上找到了一个脚本但是我想要提升它来递归。 #!/bin/bash # cmp_dir – program to compare two directories # Check for required arguments if [ $# -ne 2 ]; then echo “usage: $0 directory_1 directory_2” 1>&2 exit 1 fi # Make sure both arguments are directories if [ ! -d $1 ]; then echo “$1 is not a directory!” 1>&2 exit […]

如何获取源文件的真实路径

我在~/.bashrc添加了这一行 . /mnt/c/Users/enzo/drive/projects/dotfiles/init.sh 并且在init.sh内部我试图获取init.sh的路径,但我无法做到。 到目前为止我试过这个: CURDIR=`/bin/pwd` BASEDIR=$(dirname $0) ABSPATH=$(readlink -f $0) ABSDIR=$(dirname $ABSPATH) REAL=$(realpath $0) echo “CURDIR is $CURDIR” echo “BASEDIR is $BASEDIR” echo “ABSPATH is $ABSPATH” echo “ABSDIR is $ABSDIR” echo “REAL is $REAL” 输出: CURDIR is /mnt/c/Users/enzo BASEDIR is /bin ABSPATH is /bin/bash ABSDIR is /bin REAL is /bin/bash 我在windows子系统下用于linux。

在bash脚本中的新终端实例中运行命令

我有一个bash脚本,我自动配置我的代理设置。 我在.bash_aliases文件中创建了一些别名。 现在有一个命令,我ssh到我的远程服务器并进行一些动态端口转发,并基本上创建一个socks代理。 所以我需要相应地配置我的代理设置。 该命令如下所示: proxy off && ssh -D @ 我给上面的命令别名,当我在终端中输入别名时,我已成功连接到我的远程服务器。 但是在完成此操作后,我需要在新的终端窗口中运行另一个命令来配置我新创建的socks代理。 基本上我只需要运行: proxy socks #It configures my laptop to use the socks proxy 我无法在同一个终端窗口中执行此操作,只能在ssh命令后执行&&它,因为这意味着我尝试在远程服务器上执行该命令。 我想在我的笔记本电脑上运行此命令。 有没有什么方法可以在一个新的终端窗口中运行第二个命令,就像我们管道或不同的命令一样? 每次我进入我的远程服务器时,在终端中打开一个新选项卡是非常低效的,这样我就可以键入一个命令来配置我的代理,然后关闭该选项卡,因为我不再需要它了。

为什么`which`指向不同的二进制文件?

我的系统上安装了2个curl版本,其中一个版本支持http2。 我以为我可以使用which来指向二进制文件,但它似乎不像我期望的那样工作。 $ curl –http2 -I https://something.example.com curl: (1) Unsupported protocol $ which curl /usr/local/bin/curl $ /usr/local/bin/curl –http2 -I https://something.example.com HTTP/2 200 server: nginx/1.10.0 (Ubuntu) date: Thu, 08 Jun 2017 20:55:09 GMT content-length: 928 last-modified: Thu, 08 Jun 2017 19:43:10 GMT cache-control: public, max-age=31536000 accept-ranges: bytes which是指向我本地构建的二进制文件/usr/local/bin/curl但实际命令正在执行包二进制文件/usr/bin/curl 我没有curl的别名,所以有人可以向我解释为什么会这样吗? 我应该运行什么命令来找到curl的实际路径,我碰巧知道是/usr/bin/curl

fsl.sh无法获取

我需要安装FSL和Freesurfer作为运行Connectome Mapper的一部分。 Freesurfer需要将shell更改为tcsh才能配置其文件夹。 现在对于FSL,我必须添加.profile行bash /etc/fls/5.0/fls.sh ,但是这行实际上什么也没做,所以当我登录到控制台并发送echo $FLSDIR我实际上什么都没有。 如何在tcsh控制台中使用此sh脚本? fsl.sh文件由下式给出: # FSL configuration file # – to be sourced by the user, typically in .bashrc or equivalent # – note that the user should set # Written by Mark Jenkinson, FMRIB Analysis Group, University of Oxford # Modified for Debian by Michael Hanke # clean out […]