久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 cronjob 運(yùn)行 bash 腳本失敗,并顯示“沒有這樣

Running a bash script from a cronjob fails with quot;No such file or directoryquot;(從 cronjob 運(yùn)行 bash 腳本失敗,并顯示“沒有這樣的文件或目錄.)
本文介紹了從 cronjob 運(yùn)行 bash 腳本失敗,并顯示“沒有這樣的文件或目錄".的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試運(yùn)行以下 bash 腳本,該腳本在激活 conda 環(huán)境后運(yùn)行 Python 程序.

send.bash

#!/bin/bash源激活 manage_oam_userspython ~/path/to/script/send.py源停用

crontab

30 * * * * source/path/to/script/send.bash

我從 cron 收到以下錯誤,盡管運(yùn)行 source send.bash 可以完美運(yùn)行.我也嘗試過使用 bash send.bash,它在手動運(yùn)行時工作正常,但在從 cron 運(yùn)行時會導(dǎo)致相同的錯誤.

/path/to/script/send.bash: line 2: activate: No such file or directory

解決方案

activatedeactivate 可能是位于 $PATH 中某個條目的腳本代碼>變量指向.通常,為一位用戶在本地安裝的軟件會將語句添加到您的 .profile 文件或 .bashrc 以擴(kuò)展您的 $PATH 變量,以便您可以使用不使用完整路徑的軟件腳本.

當(dāng)您的 bash 自動加載 .profile.bashrc 時,CRON 不會這樣做.對此至少有兩種解決方案.

A) 無處不在的完整路徑

您可以在 CRON 作業(yè)執(zhí)行的腳本中使用完整路徑,如下所示:

#!/bin/bash源/path/to/activate manage_oam_userspython $HOME/path/to/script/send.py源/路徑/到/停用

也使用 $HOME 代替 ~.您可以在 shell 中使用 which activatewhich deactivate 找出完整路徑.

B) 源碼.profile.bashrc

或者,您可以獲取 .profile(或 .bashrc;您必須查看哪個文件擴(kuò)展了您的 $PATH 變量anaconda 目錄)在您的 CRON 選項(xiàng)卡中:

30 * * * * source $HOME/.profile;源/path/to/script/send.bash

補(bǔ)充:來源是什么意思?

<塊引用>

source 是一個 Unix 命令,它評估命令后面的文件,作為在當(dāng)前上下文中執(zhí)行的命令列表.

– 來自維基百科,很棒的百科全書

source 命令的常用別名是單點(diǎn) (./path/to/script).

相關(guān)但更多通用問題可以在 UNIX 和 Linux Stack Exchange 上找到.

I'm trying to run the following bash script which runs a Python program after activating a conda environment.

send.bash

#!/bin/bash
source activate manage_oam_users
python ~/path/to/script/send.py
source deactivate

crontab

30 * * * * source /path/to/script/send.bash

I get the following error from cron, although running source send.bash works perfectly. I've also tried using bash send.bash which works fine when run manually, but results in the same error when run from cron.

/path/to/script/send.bash: line 2: activate: No such file or directory

解決方案

activate and deactivate are probably scripts located somewhere an entry in your $PATH variable points to. Usually, software installed locally for one user adds statements to your .profile file or .bashrc that extend your $PATH variable so that you can use the software's scripts without using full paths.

While your bash loads .profile and .bashrc automatically, CRON won't do that. There are at least two solutions for this.

A) Full Paths everywhere

Either you use full paths in the script executed by your CRON job, like this:

#!/bin/bash
source /path/to/activate manage_oam_users
python $HOME/path/to/script/send.py
source /path/to/deactivate

Also use $HOME instead of ~. You can find out the full paths using which activate and which deactivate in your shell.

B) Source .profile or .bashrc

Alternatively you can source your .profile (or .bashrc; you will have to look which file extends your $PATH variable with the anaconda directories) in your CRON tab:

30 * * * * source $HOME/.profile; source /path/to/script/send.bash

Extra: What does source mean?

source is a Unix command that evaluates the file following the command, as a list of commands, executed in the current context.

– from Wikipedia, the something something great encyclopaedia

A commonly used alias for the source command is a single dot (. /path/to/script).

A related, but more generic question can be found on the UNIX and Linux Stack Exchange.

這篇關(guān)于從 cronjob 運(yùn)行 bash 腳本失敗,并顯示“沒有這樣的文件或目錄".的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現(xiàn)問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節(jié)點(diǎn))
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應(yīng)并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標(biāo)記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 久草视频2 | 国产亚洲精品久久情网 | 自拍中文字幕 | 国产精品欧美一区二区三区不卡 | 亚洲精品在线视频 | 精品一区二区久久 | 免费同性女女aaa免费网站 | 日韩一区二区三区在线视频 | 午夜影院在线观看免费 | 国产精品亚洲精品日韩已方 | 欧美乱码精品一区二区三区 | 日韩av在线中文字幕 | 国产精品不卡 | 最新中文字幕一区 | av中文字幕在线 | 黄色一级大片在线免费看产 | 成人毛片视频免费 | 国产超碰人人爽人人做人人爱 | 一区二区三区精品视频 | 欧美国产激情 | 亚洲一区二区三区免费观看 | 国产精品视频免费观看 | 精产国产伦理一二三区 | 欧美video | 免费99视频 | av片在线免费看 | 午夜视频在线观看网站 | 激情国产| 色欧美日韩| 国产午夜精品一区二区三区在线观看 | 国产黄色av网站 | 一区二区三区四区国产精品 | 国产在线观看av | 欧美视频在线播放 | 91动漫在线观看 | 91精品国产综合久久精品 | 在线观看电影av | 美女精品一区 | 国产免费色 | 成人国产精品久久 | 久久精品久久精品久久精品 |