‘壹’ 求助linux,编写Linux登陆shell脚本
#!/usr/local/bin/expect
set timeout 10
spawn ssh root@ip
expect "*password*"
send "123456\r"
expect "#"
send "service crond restart\r"
expect eof
‘贰’ 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
‘叁’ Linux 能否实现用户登录运行脚本
可以。用户登录时,Bash 首先执行全局登录脚本(由 root 建立) /etc/profile,然后在用户起始目录下依次寻找 .bash_profile、.bash_login、.profile 三个文件,执行最先找到的一个。可以用这种办法像 Netware 一样为不同的用户定制运行环境。 此外,用户退出登录时还可以运行 .bash_logout 脚本。
免费提供最新Linux技术教程书籍,入门自学书籍《linux就该这么学》,为开源技术爱好者努力做得更多更好
‘肆’ 在LINUX系统下,如何使用SHell脚本,SSH登陆上路由器
1.登陆linux系统,打开终端命令。输入 rpm -qa |grep ssh 查找当前系统是否已经安装
2.如果没有安装SSH软件包,可以通过yum 或rpm安装包进行安装
3、安装好了之后,就开启ssh服务。Ssh服务一般叫做 SSHD
4、命令行输入 service sshd start 可以启动 或者使用 /etc/init.d/sshd start
5、输入:ssh 账号@IP地址即可。
比如:ssh [email protected]
然后按照提示输入密码. 一切无误则进入该远程主机.
‘伍’ Linux自动登陆脚本怎么写
题主你好,
可以借助在家目录下编写.netrc文件来实现问题中所述需求.
举例来说: 我要实现: 直接使用 "ftp 1.1.1.1" 命令,回车后会:
a.自动使用用户名: hello 密码: world 登录.
b.在a步完成登录后, 自动切到ok目录下.
-------------------------------------------------------
实现:
1.在家目录下新建".netrc"文件:
希望可以帮到题主, 欢迎追问.
‘陆’ linux远程登陆的shell脚本for循环无结果
我比较认同“ssh之后是远程主机执行的命令
本地变量不起作用”这种说法
你的脚本之所以$aaa能回显,是因为在本地定义了这个变量,但本地没有定义$i这个变量,所以无法显示变量值,把aaa="u1 u2"一块塞<<ff.......ff这个内联重定向数据中去。再试试看。
‘柒’ Linux自动登录脚本
${@:3};只是一个提取
子串
的操作
$@
表示所有些参数都分别被
双引号
引住若脚本接收两参数$@等价于$1$2
${@:3};表示第三个参数后面的所有参数(包括第三个参数)
‘捌’ linux下如何使用ssh远程登录主机 执行shell脚本
知道linux的ip,用户和密码就可以远程登陆了。在你的SSH 客户端会有一个linux的终端。在这执行命令就可以了。
‘玖’ 在linux下编写shell脚本,判断当前登录用户是否为学号命名的用户
#!/bin/bash
id="123"
[ `whoami` = "$id" ] && echo 'yes' || echo 'no'
例如:
sh check.sh
#!/bin/sh
echo "Input username:"
read username
if grep -q $username /etc/passwd
then
awk -F: /$username/'{print $7}' /etc/passwd
else
echo "$1 not local user"
fi
(9)linux登陆脚本扩展阅读:
Shell就是一个命令行解释器,它的作用就是遵循一定的语法将输入的命令加以解释并传给系统。它为用户提供了一个向Linux发送请求以便运行程序的接口系统级程序,用户可以用Shell来启动、挂起、停止甚至是编写一些程序。 Shell本身是一个用C语言编写的程序,它是用户使用Linux的桥梁。