导航:首页 > 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脚本服务器相关的知识