环境变量问题,我就直接在脚本第二行加入以下代码:
source /etc/profile
source ~/.bashrc
执行后就正确了。目前写了一个脚本,定时执行,去检测spark中,sparkstreaming的状态,如果没有流,则用脚本拉起来。脚本如下:
#! /bin/bash
source /etc/profile
source ~/.bash_profile
func()
{
curl -H "Content-Type:application/json" -X POST -d "{\"jobId\":\"1\"}" http://ip:port/job/sparkstreaming/start
touch finished
}
ttt=`yarn application -list |grep 'streaming' -c`
echo "stream exit num $ttt" >> /usr/local/stream/log.txt
if [ $ttt -eq 0 ];then
echo 'streaming is down'
strDate=$(date)
strStart="start streaming $strDate"
echo "$strStart" >> /usr/local/stream/log.txt
func &
echo "sleep 15"
sleep 15
echo 'bring streaming finished'
fi