2016-10-20 6 views
0

私は自分の.shスクリプトをcronジョブとして実行するたびにIPアドレスを表示できません。 ./myscript.shを使ってスクリプトを実行するたびに、htmlファイルに表示されるIPアドレスを取得することができます。何が間違っているか教えてください。cronジョブとしてスクリプトを実行してもデータが表示されません。

#!/bin/bash 
container_id=$(docker ps -a | cut -c 1-20) 
container_id_ele=($container_id) 
container_status=$(docker ps -a | cut -c 80-100) 
container_status_ele=($container_status) 
last_run=`date` 
hostip=`ifconfig eno1 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'` 
cat > /home/docker/index.html <<EOF 
<html> 
<body> 
    <table border=1> 
    <tr> 
     <td>Host</td> 
     <td>Container Id</td> 
     <td>Status</td> 
    </tr> 
    <tr> 
    <td> $hostip </td> 
    <td> ${container_id_ele[2]}</td> 
    <td> ${container_status_ele[1]} ${container_status_ele[2]} ${container_status_ele[3]} </td> 
</tr> 
    </table> 
Note : Status will be updated every 60 seconds <br/> 
Last run :$last_run 
</body> 
</html> 
EOF 
`docker cp /home/docker/index.html tomcat:/opt/tomcat/webapps/ROOT/` 

答えて

1

ニーススクリプト。ここに書き直しはほとんどありません。

#!/bin/bash 
export myhostip=`hostname -I` 
echo $myhostip 
cat > ./index.html <<EOF 
<html> 
     <body> 
       <h1>$myhostip</h1> 
     </body> 
</html> 
EOF 

これは機能しています。

関連する問題