LIUWENCAIJIAYOU
HUHU_1208
2018-10-15 02:33
采纳率: 50%
浏览 3.3k
已采纳

shell脚本包含明文密码,如何隐藏明文密码?

shell脚本包含明文密码,如何隐藏明文密码?

 #!/bin/bash
partition_list=(`df -h | awk 'NF>3&&NR>1{sub(/%/,"",$(NF-1));print $NF,$(NF-1)}'`)
critical=80
notification_email()
{
    emailuser='Yuki_hu@1208.com'
    emailpasswd='明文密码'
    emailsmtp='smtpav.travelsky.com'
    sendto='kkk@tra.com'
    title='Server Disk Space Alarm'
    /home/jcf/huhu/sendEmail-v1.56/sendEmail -f $emailuser -t $sendto -s $emailsmtp -u $title -xu $emailuser -xp $emailpasswd
}
crit_info=""
for (( i=0;i<${#partition_list[@]};i+=2 ))
do
    if [ "${partition_list[((i+1))]}" -lt "$critical" ];then
        echo "OK! ${partition_list[i]} used ${partition_list[((i+1))]}%"
    else        
            if [ "${partition_list[((i+1))]}" -gt "$critical" ];then
                crit_info=$crit_info"Warning!!! ${partition_list[i]} used ${partition_list[((i+1))]}%\n"
            fi 
    fi
done
if [ "$crit_info" != "" ];then
    echo -e $crit_info | notification_email
fi

希望大神帮忙解答,谢谢~~

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • Lsx2018223
    老婆是云梦 2018-10-15 09:20
    已采纳

    password="明文"

    将密码放到文件中去,比如/root/pass.txt
    password=</root/pass.txt
    还怕密码泄露的话,就把pass.txt权限设置下。楼主可以参考以下链接:https://blog.csdn.net/wenxuechaozhe/article/details/52943852

    点赞 评论

相关推荐