Linux shell脚本处理sudo ssh交互问题

 可以通过这种方式来以脚本形式执行ssh操作,并执行远程主机上面的命令

#!/usr/bin/expect -f

spawn ssh [email protected]
expect "*password:"
send "nvidia\r"

expect  "$*" { send "cd zhkj_uav/\r"}
expect  "$*" { send "./sensorfusion_ub.sh\r" }
interact

 可以用下面的方法,在不交互的前提下执行sudo命令,并创建新的终端并行执行程序

#!/bin/bash
echo "123456" | sudo -S chmod 666 /dev/video*
cd /home/zhihui/sensor_render
source cmake-build-release/devel/setup.bash

cd /home/zhihui/sensor_render/cmake-build-release
echo "CTRL + C to shutdown"
gnome-terminal -t "sensor render" -x bash -c "echo 'CTRL + C to shutdown';
/home/bf/sensor_render/cmake-build-release/sensor_render;exec bash"
 
gnome-terminal -t "camera" -x bash -c "echo 'CTRL + C to shutdown'; 
/home/bf/sensor_render/cmake-build-release/camera;exec bash"

 

你可能感兴趣的:(linux,shell)