gpt4 book ai didi

linux - Bash 脚本输出到文件从脚本失败但从 bash 工作

转载 作者:太空宇宙 更新时间:2023-11-04 12:05:25 25 4
gpt4 key购买 nike

我有这个脚本来检查 dcos 身份验证登录是否有效,但是我将输出重定向到的文件大小始终为零,当我从 bash shell 运行脚本时,文件大于零。我究竟做错了什么 ?? ,我在下面使用的两个函数:

try_to_login()
{
# first needs to be logged as skyusr
# try to login and log the result to tmp file
# Sometimes the file is empty so we try again to login
# if the second time is OK it jumps to check the output
cd /home/skyusr/scripts/
dcos auth login --username=admin --password=admin > /home/skyusr/scripts/tmp.sal
}

check_login_result()
{
# Checks if the output of the login is "Login Successful!"
# If YES then writes to log file, if not sends mail and writes to log.
#export mail_to="salim.bisharat@amdocs.com,anis.faraj@amdocs.com"
export mail_to="salim.bisharat@amdocs.com"
now=$(date)
text_to_check=$(cat /home/skyusr/scripts/tmp.sal)
if [ -s /home/skyusr/scripts/tmp.sal ]
then
if [ "$text_to_check" = "Login successful!" ]
then
echo "$now - Check Successful" >> /home/skyusr/scripts/logs/login_log.log
else
cat /home/skyusr/scripts/logs/mail_temp.log | mailx -s "!!! CRITITCAL -- Check DCOS login !!!" $mail_to
echo "$now - !! ERROR ! Sent mail !! " >> /home/skyusr/scripts/logs/login_log.log
fi
fi
}

最佳答案

在此脚本中您定义,但不调用函数。简单地追加函数调用:

    # ...
echo "$now - !! ERROR ! Sent mail !! " >> /home/skyusr/scripts/logs/login_log.log
fi
fi
} # ... the last line of your script here

try_to_login # calls here ...
check_login_result

关于linux - Bash 脚本输出到文件从脚本失败但从 bash 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50907139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com