yanglgzh 发表于 2018-8-26 13:19:47

一个得到内存信息的shell以及遇到的一个坑

  #!/bin/bash
  for i in `cat /home/lee/hosts`
  do
  ssh -i/home/leeroot@$i"free -m>/root/${i}_memory.txt ;/bin/hostname >>/root/${i}_memory.txt"
  sleep 1
  scp -i/home/lee$i:/root/${i}_memory.txt/root/
  sleep 1
  done
  if [ ! -f /root/get_memory.txt ]
  then
  touch /root/get_memory.txt
  fi
  echo >/root/get_memory.txt
  for j in `ls 192*`
  do
  sed -n 3p $j | awk '{print $4}' >>/root/get_memory.txt
  host=`sed -n'$p'$j`
  ipadd=`ls $j`
  echo "${ipadd%_*}-$host" >>/root/get_memory.txt
  done
  gzexe加密
  注意:在ssh密匙登录执行命令遇到一台主机老是提示输入密码,找了半天终于在日志里面找到说/root目录的权限有问题,看来如果是设置好了免密登录,不管是密匙文件本身还是上层目录的权限都很重要.

页: [1]
查看完整版本: 一个得到内存信息的shell以及遇到的一个坑