導航:首頁 > IDC知識 > linux腳本伺服器

linux腳本伺服器

發布時間:2021-01-26 03:17:58

1、多台linux伺服器之間,如何實現互相之間免密碼登錄及執行命令腳本?

ssh無密碼訪問
cd /root/.ssh/
ssh-keygen -t rsa
cat id_rsa.pub >> authorized_keys
在各節點執行
ssh-keygen -t rsa
ssh-copy-id -i node1
Node1執行
chmod 600 authorized_keys
將授權文件拷貝到節點:
scp authorized_keys node2:/root/.ssh/
node1是第一台主機,可專以提前編輯好屬hosts同步下去。
新加的機器只需要執行
ssh-keygen -t rsa
ssh-copy-id -i node1
然後再把node1上的authorized_keys 同步到每台主機就可以了。

2、學校Linux伺服器上如何跑R腳本

只需要在R腳本首行,加入下圖中的代碼即可:

R --no-save <mergefiles.r

 

nohup R [options] [< infile] [> outfile]

nohup 後台運行程序

options:

--version 查看R版本;

--slave 只列印R腳本的輸出,而不顯示腳本具體執行情況; 

--vanilla是 --no-save, --no-restore, --no-site-file, --no-init-file 和 --no-environ的綜合;

--args 後面是需要傳遞的參數。

注意:options必須選擇--save,--no-save, --vanilla三個中的一個。

比如編輯一個mergefiles.r文件如下:

R --slave --vanilla <mergefiles.r

3、linux跨伺服器批處理腳本如何編寫

知不知道expect這個東西啊,這個可以自動幫你輸入密碼的,

你先將你要執行的命令寫出來專

expect <<EOF

spawn ssh root@$ip//發送ssh請滶

expect {   //返回屬信息匹配 "*yes/no" { send "yes "; exp_continue} //第一次ssh連接會提示yes/no,繼續 "*password:" { send "$password " }//出現密碼提示,發送密碼

"]#" {send "cmd "}        執行命令,你可以將命令寫成腳本或者函數

}

EOF

4、linux伺服器,shell搭建腳本 我這個是一鍵搭建腳本

可以閃的那種是不是?
echo 好像是可以修改字的

5、在linux伺服器上部署的時候腳本應該怎麼編寫

vim test.sh
按i編輯
#!/bin/bash
#
腳本內容,你要部署什麼。。。
esc 退出編輯
:wq保存退出
sh test.sh #執行腳本

6、求高人寫個Linux雲伺服器腳本

root 目錄下,,你得有root賬號,,,
cd root
tar -zcvf adb1.tar.gz adb/
tar -zcvf ddb1.tar.gz ddb/
這兩個就是打包備份啦

7、誰會寫在linux伺服器上運行java程序的運行腳本

你是要單制次運行還是不掛斷在後台運行?單次直接java -jar xxx.jar 就可以了,不掛斷的話,可以編寫一個shell腳本,start.sh 內容如下
#!/bin/sh
nohup java -jar -XX:PermSize=64m -XX:MaxPermSize=128m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:SurvivorRatio=8 xxx.jar>/dev/null 2>&1 &
具體的參數你自己把握,然後保存,給這個腳本賦於可執行許可權,chmod +x start.sh
然後執行這個腳本,sh start.sh ,然後查看一下java進程,看這個服務起來沒有,jps

8、shell腳本 ,在linux 下運行一個shell腳本登陸遠程unix 伺服器,請問這個腳本如何寫?

^#!/bin/bash
tmptty=``
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

9、高分求教:有一台Linux伺服器,求教怎麼通過bat批處理命令自動登錄伺服器並執行某個shell命令

裝了 expect 的話:

#!/usr/bin/expect -f

spawn telnet 10.1.18.8
expect "login:"    #等待輸入用戶名提示
send "root "      #輸入用戶名
expect "Password:"    #等待輸入密碼提示
send "root "      #輸入密碼  
expect "# "        #根據實際提示符修專改
send "sh /update.sh "    #執行腳屬本
expect "# "        #根據實際提示符修改
send "exit "      #退出telnet
expect eof

 

沒有 expect:

#! /bin/bash
(
sleep 1
echo 'root'    #用戶名
sleep 1
echo 'root'    #密碼
sleep 1
echo 'sh /update.sh'    #執行腳本
sleep 1
) | telnet 10.1.18.8

與linux腳本伺服器相關的知識