當前位置:首頁 » 編程軟體 » 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命令表示傳輸二進制文件。

熱點內容
sql注入攻擊與防禦 發布:2024-05-08 12:58:38 瀏覽:316
dw網頁設計如何連接伺服器 發布:2024-05-08 12:33:02 瀏覽:465
linux文件隱藏命令 發布:2024-05-08 12:29:38 瀏覽:748
信息增益python 發布:2024-05-08 12:23:49 瀏覽:548
外置內存卡不能存儲 發布:2024-05-08 11:43:02 瀏覽:507
javalist合並 發布:2024-05-08 11:43:01 瀏覽:477
校園網內怎麼搭建伺服器 發布:2024-05-08 11:28:33 瀏覽:73
adb伺服器是什麼資料庫 發布:2024-05-08 11:27:43 瀏覽:364
一鍵編譯vscode 發布:2024-05-08 11:27:37 瀏覽:870
哪個型號的安卓機性價比好 發布:2024-05-08 11:05:10 瀏覽:658