1

我的问题主要在于对不同的 linux 命令的无知。当我不知所措来正确查找我需要的命令时,我遇到了困难。

但是,我想将 schemer (github.com/thefryscorer/schemer" 输出的字符串插入到我的 Terminator 配置中以 "palette=" 开头的行中,替换现有的信息。

目的是将其设置为间隔运行,以使用我的 bash 颜色更新我的自行车壁纸列表。

如果您能给我指出一个学习这种自动化和命令用法的地方,我将不胜感激。

4

2 回答 2

1

在 Arch Linux 上运行 Cinnamon 2.6.13,我编写了这段代码,从定义的目录中获取一个随机文件并将其应用为墙纸。然后它运行 schemer 并将新生成的配置复制到 Terminators 配置目录中。

#!/bin/bash
#Todo; 
currentmonth=August2015 
#directory of wallpaper
currentfilename="$(ls ~/Pictures/wallpapers/"$currentmonth" | shuf -n 1)"
#set $currentfilename to random filename from $currentmonth
gsettings set org.cinnamon.desktop.background picture-uri file:///home/cogitantium/Pictures/wallpapers/"$currentmonth"/"$currentfilename" 
#set wallpaper as current filename from default directory.
~/Go/bin/schemer -term="terminator" ~/Pictures/wallpapers/"$currentmonth"/"$currentfilename" > ~/Scripts/temp/currentpalette 
#generate palette and redirect output to temporary palette file
echo "$currentmonth - $currentfilename - $currentpalette"
currentpalette="$(cat temp/currentpalette)"
#set $currentpalette to currentpalette
touch "temp/config"
sed -i "s/^.*\bpalette\b.*$/$currentpalette/g" "temp/config"
#insert generated palette into terminator config
cp "temp/config" "~/.config/terminator/config"

它确实包含一些错误并且有时行为不规则。此外,即使在杀戮之后,终结者似乎也没有对这些变化做出反应。如果我找到解决方案,我会更新我的答案。

于 2015-08-27T17:57:15.233 回答
0

您需要的两件事是sedcron

sed是一个流编辑器。特别是,它使用正则表达式允许您搜索文本文件并替换部分文本。

特别是,如果您有

#conf.config
palette=REPLACE_ME
other.var=numbers

你可以说sed s/REPLACE_ME/replaced_text/g conf.config

sed 将用第二个参数(“替换文本”)替换 conf.config 中的文本。

所以这将在您编写的 bash 脚本中。

然后你想要做的是定期执行你的脚本,你可以通过设置一个cron作业来完成。这将定期执行一个文件。

您可以将您的 shell 脚本放在 /etc/cron 文件夹中的任何一个文件夹etc/cron.hourlyetc/cron.daily或者

在终端输入crontab -e以打开您的个人 cron 配置文件,以便更细粒度地控制您的命令何时执行。

cron 命令的格式如下:

minute hour day-of-month month day-of-week command

因此,您可以在星期一下午每周执行一次命令(如下面的资料中所述)

30 17 * * 1 /path/to/command(30=min,17=5pm,1 是星期一,因为星期日是 0 索引)。

或每 15 分钟一次

*/15 * * * * /path/to/command

您的命令将是~/scripts/myscript.sh或任何 bash 脚本具有您的 sed 命令。

因此,您可以让您的 cron 作业运行计划程序,然后在同一个脚本中,将该字符串放入您的配置文件中。您可能需要重新加载配置文件,并且该命令(粘贴在脚本末尾)是source [path_to_config]

你去吧。定期运行 schemer,获取字符串,将其粘贴到配置文件中,然后重新加载文件。 cron,一些基本的bash(因为我不熟悉schemer,或者它的输出性质超出了“它是一个字符串”)sed,和source.

cron 作业的来源,因为我对它们的熟悉程度不如对 sed 的熟悉:

https://help.ubuntu.com/community/CronHowto

https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job

于 2015-08-26T16:09:08.683 回答