遇到需要在ecs部署個定時監控的情況,第一次實際用到shell,雖然是很簡單的指令碼,作為初學者就做了下記錄~
個人而言,需要注意的是,在sh裡啟用虛擬環境時需要進行conda initialize,另外定時作業應該建立相應的logs,再有就是bash裡雙引號關閉部分元字元特殊意義,單引號關閉所有元字元特殊意義。
**示例:
#!/bin/bash
# !! contents within this block are managed by 'conda init' !!
__conda_setup="$('/root/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/root/miniconda3/etc/profile.d/conda.sh" ]; then
. "/root/miniconda3/etc/profile.d/conda.sh"
else
export path="/root/miniconda3/bin:$path"
fifiunset __conda_setup
# <<< conda initialize <<<
workdir='/home/test/test_text'
echo $workdir
run_date="`date +%y%m%d`"
run_time="`date +%y%m%d%h%m%s`"
if [ ! -d $/logs/$ ];then
mkdir $/logs/$
else
echo dir exist
fishell_log_file=$/logs/$/$.log
echo `date` > $
conda activate test_env
python3 /home/test/test_text/test.py >> $ 2>&1
之後通過crontab上定時作業就可以了。 初次接觸bash指令碼檔案
在 tmp 目錄下新建乙個檔案sum.sh用於寫簡單的指令碼內容 指令碼檔案用.sh字尾名,雖然linux系統沒有像windows那麼注重字尾名與檔案型別的關聯,但在寫指令碼時固定字尾名有利於以後對指令碼檔案的分辨查詢等等,這是一種好習慣。root server01 tmp vim sum.sh 指...
Shell指令碼之Bash內部命令
本文是自己學習的總結,僅以作分享。若有不對的地方歡迎指正。bash內部命令 有些內部命令在目錄列表是看不見的,他們有shell本身提供,常用的內部命令有 echo eval exec export readonly read shift wait exit和 echo 將變數名錶指定的變數顯示到標準...
第乙個shell指令碼(bash指令碼)
首先它是乙個指令碼,並不能作為正式的程式語言。因為是跑在linux的shell中,所以叫shell指令碼。說白了,shell指令碼就是一些命令的集合。運維工作中把常用的一系列的操作都記錄到乙個文件中,然後去呼叫文件中的命令,這樣一步操作就可以完成。其實這個文件呢就是shell指令碼了,只是這個she...