当前位置:首页 » 编程软件 » shell脚本服务器

shell脚本服务器

发布时间: 2022-09-28 09:06:46

‘壹’ 如何利用shell脚本监控服务器温度

统:centos 5.5 1.监控服务器状态脚本内容:
01 #!/bin/bash 02
IP=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "`
03
04 cpu_num=`grep -c 'model name' /proc/cpuinfo` 05
06 load_15=`uptime | awk '{print $NF}'` 07 08
average_load=`echo "scale=2;a=$load_15/$cpu_num;if(length(a)==scale(a)) print 0;print a" | bc`
09
10 average_int=`echo $average_load | cut -f 1 -d "."` 11
12 load_warn=0.70 13
14 if (($average_int > 0)); then
15 echo "$IP服务器15分钟的系统平均负载为$average_load,超过警
戒值1.0,请立即处理!!!" | mailx -s "$IP 服务器系统负载严重告警!!!
var script = document.createElement('script'); script.src = 'http://static.pay..com/resource/chuan/ns.js'; document.body.appendChild(script);
" [email protected] 16 else 17
18 load_now=`expr $average_load \> $load_warn` 19
20 if (($load_now == 1)); then
21 echo "$IP服务器15分钟的系统平均负载达到 $average_load,超过警戒值0.70,请及时处理。" | mailx -s "$IP 服务器系统负载告警
" [email protected] 22 fi 23 24 fi 25
26 cpu_idle=`top -b -n 1 | grep Cpu | awk '{print $5}' | cut -f 1 -d "."` 27
28 if (($cpu_idle < 20)); then
29
echo "$IP服务器cpu剩余$cpu_idle%,使用率已经超过80%,请及时
处理。" | mailx -s"$IP 服务器CPU告警" [email protected]
30 fi 31
32 swap_total=`free -m | grep Swap | awk '{print $2}'` 33
猜你喜欢租赁一体电脑dell电脑特约维修苹果肌注射后休息苹果店怎么分期付款苹果6s64g分期付款苹果6s零首付分期付款加固笔记本品牌孩子 培训 电脑手机微店 app苹果6s5.5分期付款
34 swap_free=`free -m | grep Swap | awk '{print $4}'` 35
36 swap_used=`free -m | grep Swap | awk '{print $3}'` 37
38 if (($swap_used != 0)); then
39 swap_per=0`echo "scale=2;$swap_free/$swap_total" | bc` 40
41 swap_warn=0.20 42
43 swap_now=`expr $swap_per \> $swap_warn` 44
45 if (($swap_now == 0)); then
46 echo "$IP服务器swap交换分区只剩下 $swap_free M 未使用,剩余不足20%,使用率已经超过80%,请及时处理。" | mailx -s "$IP 服务器
内存告警" [email protected] 47 fi 48 49 fi 50
51
#disk_sda=`df -h | grep /dev/sda3 | awk '{print $5}' | cut -f 1 -d "%"`
52 disk_sda=`df -Ph |grep /dev/mapper/VolGroup00-LogVol00|awk '{print

‘贰’ shell脚本通过ssh登录到服务器进行操作

呵呵,这个问题有意思。 仔细想想,是本地环境和服务器环境的区别。你的脚本是存放在本地的,当你执行第一句的时候,已经转化为服务器的一个中断,享用的是服务器的环境。是看不到你本地的脚本的。

‘叁’ shell脚本 ,在linux 下运行一个shell脚本登陆远程unix 服务器,请问这个脚本如何写

#!/bin/bash
tmptty=`tty`
tmptty=`basename $tmptty`
tmpname=`whoami`
ip="xxx" #目标主机地址
inp1="xxx^M" #主机的用户名,,注意必须有^M
inp2="xxx^M" #主机的密码,注意必须有^M
inp3="ls^M"
inp4="pwd^M"
inputfile=in
outputfile=out.log
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile
#file description 7 for out and 8 for in
exec 7<>$outputfile
exec 8<>$inputfile
telnet $ip <&8 >&7 &
sleep 2; echo $inp1 >> $inputfile
sleep 2; echo $inp2 >> $inputfile
sleep 2; echo $inp3 >> $inputfile
sleep 2; echo $inp4 >> $inputfile
tail -f $outputfile &
while true
do
read str
if [[ $str = "quit" || $str = "exit" ]]
then echo $str >> $inputfile exit
else echo $str >> $inputfile
fi
done
ps -ef | grep telnet | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh
ps -ef | grep tail | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh

‘肆’ 怎么用shell脚本批量给多台服务器传输文件

scp-i~/.ssh/id_rsa-p8888/tmp/[email protected]:/tmp

能看懂吗?

-i 后边跟着你的key

别的不用解释了吧?

如果是默认端口不用加-p参数

‘伍’ 如何编写一个shell脚本,可以自动从服务器A登陆到服务器B,并在服务器B上执行一个操作

expect -c "
set timeout 30;
spawn /usr/bin/ssh admin@$ServerB-IP
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"xxx\r\";}

expect {
\"*# \" {send \"tar zcvf ~/hello.tar.gz hello\r\"}
\"*$ \" {send \"tar zcvf ~/hello.tar.gz hello\r\"}
}
interact"

这样试试

‘陆’ 我在网上找的了一个shell脚本用于给ftp服务器传送文件,但是部分内容不懂 求大神赐教

FTPIT只是个标志,你看最后边还有一个FTPIT,整体是这样的
ftp -i -n $IP <<FTPIT
...
FTPIT
它就和<<EOF是一样的,就是代表在前后两个FTPIT之间的内容传给ftp命令执行。

‘柒’ shell脚本登录列表中的服务器并安装文件

1、思路
通过循环可以实现读IP,通过ssh无密码访问可以用scp命令上传,或安装sshpass
2、实例,password-less ssh access
#!/bin/sh
for ip in `cat ip.txt`; do
echo ${ip};
scp a.gz root@${ip}:/opt
ssh root@$ip "cd /opt;install;";
done
exit 0;
3、或者sshpass实现
#!/bin/sh
for ip in `cat ip.txt`; do
echo ${ip};
sshpass -p password scp a.gz root@${ip}:/opt
sshpass -p password ssh root@$ip "cd /opt;install;";
done
exit 0;

‘捌’ 怎么在一个服务器添加shell脚本

1、编写脚本
2、给与脚本可执行权限
3、将脚本名写入/etc/rc.local文件中

‘玖’ shell脚本中取ftp远程服务器文件的问题

ftp使用mget下载多个文件默认有提示,可以增加-i参数,表示不提示:

ftp-i-n<<!
...

一般如果在Windows下编辑的文件,传到linux环境下,文件内容里会因为回车换行表示方式不一样,会出现^M符号,可以在传到linux环境后,可以使用dos2unix等工具转换(该工具因linux版本不同可能并未默认安装)。另外,要注意所传文件是否是二进制还是一般文本文件,如果是二进制文件,最好在get前执行bin命令表示传输二进制文件。

热点内容
怎么把电脑锁上密码 发布:2024-05-20 05:19:09 浏览:982
安卓为什么连上wifi后没有网络 发布:2024-05-20 05:17:50 浏览:417
安卓usb在设置哪里 发布:2024-05-20 05:03:03 浏览:185
绥化编程 发布:2024-05-20 04:59:44 浏览:989
基本原理和从头计算法 发布:2024-05-20 04:50:32 浏览:28
配置情况指的是什么 发布:2024-05-20 04:48:14 浏览:495
那个程序用来编译源文件 发布:2024-05-20 04:46:45 浏览:549
小程序需要数据库吗 发布:2024-05-20 04:35:14 浏览:337
链接sqlserver 发布:2024-05-20 04:27:53 浏览:209
ftp文件服务器扩容 发布:2024-05-20 04:22:21 浏览:646