如果仅在某些时候需要输入,是否可以使用 Crontab 来管理包
Can Crontab be used to manage packages if it requires input only some of the time
我基本上有一套 python 包、二进制文件和其他需要不断更新的程序,我想看看我是否可以创建一个 crontab 条目,运行 一个 BASH 基本上只是 运行s 这些每月更新的脚本。我已经成功地创建了一个 crontab 条目,它调用了我为此编写的一个较短的测试脚本。脚本不是问题,但如果它有助于回答我怀疑的问题,如下所示。
#!/bin/bash
#Program update automator script
#Leveraging crontab to update all my neuroimaging, python, and conda packages monthly without having to do it myself because I forget and am a lazy POS
#Note - Am Using Conda and Pip for package management and not apt-get, which I don't think I have installed because I had read somewhere you can get discrepancies in processes if you have apt-get and one of the other ones both on the system
#Created 12.27.17
#Updated 12.27.17
#Updates Conda itself and cleans unused packages and tarballs out
conda update conda && conda update anaconda && conda clean --packages --tarballs
#Update AFNI binaries
@update.afni.binaries -defaults -do_extras
#Updating important Python libraries
conda update python ipython ipython-notebook matplotlib networkx numpy scipy sphinx traits dateutil nose pydot
#Update Nipype libraries
pip install --upgrade nibabel nipype rdflib nipy dipy pygraphviz graphviz
因为在创建此条目之前我刚刚 运行 所有这些命令,测试它导致它 运行 没有错误。问题是,当我 运行 只有其中一些更新需要更新时,你会得到整个:
The following packages will be updated: Proceed ([y]/n)? y
这需要用户输入。
有什么方法可以使输入 'y' 的过程自动化?
我可以看到几个问题。
- 显然,最紧迫的是,如果 cron 到达需要输入的位置,它就会崩溃,对吗?我自己还没有看到这个,但这是我读到的。
- 我不确定我需要提供多少次输入,因为它始终是可变的,哪些命令将有需要更新的程序,哪些不需要,所以我并不总是需要输入 3 'y's' 并且似乎相同的命令需要来自 运行 运行.
的相同输入
这是个坏主意吗?
我当前的crontab入口如下:
0 10 1 * * source /Users/mycomputer/.bash_profile; /bin/sh /Users/mycomputer/Desktop/auto_package_updater.sh
crontab(5) entries describe commands to be run periodically (or, with @reboot
at boot time). These commands are interpreted by /bin/sh
(the POSIX shell, see sh(1p)...) 并预先替换 %
字符。
请注意,这些命令 运行 在不同的环境中运行(请参阅 environ(7)...) than your interactive shell has. Hence, you may need to set your PATH
variable(如果需要,可能还有其他环境变量,例如 LD_LIBRARY_PATH
)明确地在您的 auto_package_updater.sh
shell 脚本(而不是 source /Users/mycomputer/.bash_profile
闻起来真的很糟糕 ...)。
is that cron will crash if it gets to a point where it needs input,
不,cron(8) is a daemon -started by init or systemd 在启动时 - 并且不会崩溃(除非你被 cron
本身的错误击中,这是不太可能的)。它总是 运行s(如果你崩溃了——这极不可能,你之后不能 运行 任何 crontab
工作)。可能发生的情况是您的特定 cron 作业被阻止...
Is there a way I can automate the process of inputting 'y'?
您可以考虑使用 yes(1) (which emits a potentially infinite stream of y
lines) and pipe its output (see pipe(7))。例如,如果 pip install --upgrade nibabel nipype
需要很多 y
,您可以在 shell 脚本中输入:
yes | pip install --upgrade nibabel nipype
(但要小心!你确定你总是想要那个吗?)
顺便说一句,我不确定完全自动更新您的软件是否明智。您将如何处理这些更新失败或更新到有缺陷的版本?我建议自动下载,但手动更新....而且你可能应该避免更新 Python 程序,而该程序正在 运行ning....
也许您只是想编写自己的更新 shell script(以避免键入重复的命令)但是 运行 update_my_python_packages
自己编写脚本,当您 知道这样做是合理的。
我基本上有一套 python 包、二进制文件和其他需要不断更新的程序,我想看看我是否可以创建一个 crontab 条目,运行 一个 BASH 基本上只是 运行s 这些每月更新的脚本。我已经成功地创建了一个 crontab 条目,它调用了我为此编写的一个较短的测试脚本。脚本不是问题,但如果它有助于回答我怀疑的问题,如下所示。
#!/bin/bash
#Program update automator script
#Leveraging crontab to update all my neuroimaging, python, and conda packages monthly without having to do it myself because I forget and am a lazy POS
#Note - Am Using Conda and Pip for package management and not apt-get, which I don't think I have installed because I had read somewhere you can get discrepancies in processes if you have apt-get and one of the other ones both on the system
#Created 12.27.17
#Updated 12.27.17
#Updates Conda itself and cleans unused packages and tarballs out
conda update conda && conda update anaconda && conda clean --packages --tarballs
#Update AFNI binaries
@update.afni.binaries -defaults -do_extras
#Updating important Python libraries
conda update python ipython ipython-notebook matplotlib networkx numpy scipy sphinx traits dateutil nose pydot
#Update Nipype libraries
pip install --upgrade nibabel nipype rdflib nipy dipy pygraphviz graphviz
因为在创建此条目之前我刚刚 运行 所有这些命令,测试它导致它 运行 没有错误。问题是,当我 运行 只有其中一些更新需要更新时,你会得到整个:
The following packages will be updated: Proceed ([y]/n)? y
这需要用户输入。 有什么方法可以使输入 'y' 的过程自动化? 我可以看到几个问题。
- 显然,最紧迫的是,如果 cron 到达需要输入的位置,它就会崩溃,对吗?我自己还没有看到这个,但这是我读到的。
- 我不确定我需要提供多少次输入,因为它始终是可变的,哪些命令将有需要更新的程序,哪些不需要,所以我并不总是需要输入 3 'y's' 并且似乎相同的命令需要来自 运行 运行. 的相同输入
这是个坏主意吗?
我当前的crontab入口如下:
0 10 1 * * source /Users/mycomputer/.bash_profile; /bin/sh /Users/mycomputer/Desktop/auto_package_updater.sh
crontab(5) entries describe commands to be run periodically (or, with @reboot
at boot time). These commands are interpreted by /bin/sh
(the POSIX shell, see sh(1p)...) 并预先替换 %
字符。
请注意,这些命令 运行 在不同的环境中运行(请参阅 environ(7)...) than your interactive shell has. Hence, you may need to set your PATH
variable(如果需要,可能还有其他环境变量,例如 LD_LIBRARY_PATH
)明确地在您的 auto_package_updater.sh
shell 脚本(而不是 source /Users/mycomputer/.bash_profile
闻起来真的很糟糕 ...)。
is that cron will crash if it gets to a point where it needs input,
不,cron(8) is a daemon -started by init or systemd 在启动时 - 并且不会崩溃(除非你被 cron
本身的错误击中,这是不太可能的)。它总是 运行s(如果你崩溃了——这极不可能,你之后不能 运行 任何 crontab
工作)。可能发生的情况是您的特定 cron 作业被阻止...
Is there a way I can automate the process of inputting 'y'?
您可以考虑使用 yes(1) (which emits a potentially infinite stream of y
lines) and pipe its output (see pipe(7))。例如,如果 pip install --upgrade nibabel nipype
需要很多 y
,您可以在 shell 脚本中输入:
yes | pip install --upgrade nibabel nipype
(但要小心!你确定你总是想要那个吗?)
顺便说一句,我不确定完全自动更新您的软件是否明智。您将如何处理这些更新失败或更新到有缺陷的版本?我建议自动下载,但手动更新....而且你可能应该避免更新 Python 程序,而该程序正在 运行ning....
也许您只是想编写自己的更新 shell script(以避免键入重复的命令)但是 运行 update_my_python_packages
自己编写脚本,当您 知道这样做是合理的。