linux 用脚本打开多个terminal和多个标签页并分别执行命令

#! /bin/bash

source /opt/ros/kinetic/setup.bash
source /home/yake/catkin_ws/devel/setup.bash 

gnome-terminal -x bash -c "roslaunch kinova_bringup kinova_robot.launch kinova_robotType:=j2n6s200; exec bash; "
sleep 5

gnome-terminal --window -e 'bash -c "rosrun kinova_demo pose_action_client.py -v j2n6s200 mq 0.310199 0.202714 -0.082002 -0.73323 0.0342688 -0.0189734 0.678851;sleep 7;exec bash"' --tab -e 'bash -c "rosrun cv_camera cv_camera_node _device_id:=1;sleep 4; exec bash;"'

gnome-terminal --window -e 'bash -c "rosrun obj_tracking obj_tracking_node_pubuv; exec bash;sleep 4;exec bash"'

关键代码行为

gnome-terminal --window -e 'bash -c "rosrun kinova_demo pose_action_client.py -v j2n6s200 mq 0.310199 0.202714 -0.082002 -0.73323 0.0342688 -0.0189734 0.678851;sleep 7;exec bash"' --tab -e 'bash -c "rosrun cv_camera cv_camera_node _device_id:=1;sleep 4; exec bash;"'

--window表示打开一个终端窗口,--tab在其中新开辟一个标签页,如果还要加tab页就继续--tab。-x 只能出现一次,-e excute可以出现多次,要注意-e后面只能有一个参数,也就是说如果有空格,需要用引号。

[打开一个terminal并预先输好一段文字]

这个需求比较偏门,解决方法不错,就是利用expect这个工具,新建一个名为myprompt文件,包含的程序如下

#!/usr/bin/expect
#trap sigwinch and pass it to the child we spawned
#this allows the gnome-terminal window to be resized
trap {
  set rows [stty rows]
    set cols [stty columns]
    stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
set arg1 [lindex $argv 0]
# Get a Bash shell
spawn -noecho bash
# Wait for a prompt
expect "$ "
# Type something
send $arg1
# Hand over control to the user
interact
exit

调用方法(注意文件的路径要写全),将引号内得内容帮你提前输入到terminal,确认没问题后,回车就可以执行啦~~:

gnome-terminal -e "./myprompt \"rosrun kinova_yake camera_serviceMove_EyeInHand\""

最后我的文件代码如下

#! /bin/bash

source /opt/ros/kinetic/setup.bash
source /home/yake/catkin_ws/devel/setup.bash 

gnome-terminal -x bash -c "roslaunch kinova_bringup kinova_robot.launch kinova_robotType:=j2n6s200; exec bash; "
sleep 5

gnome-terminal --window -e 'bash -c "rosrun kinova_demo pose_action_client.py -v j2n6s200 mq 0.310199 0.202714 -0.082002 -0.73323 0.0342688 -0.0189734 0.678851;sleep 7;exec bash"' --tab -e 'bash -c "rosrun cv_camera cv_camera_node _device_id:=1;sleep 4; exec bash;"'

gnome-terminal --window -e 'bash -c "rosrun obj_tracking obj_tracking_node_pubuv; exec bash;sleep 4;exec bash"'

gnome-terminal -e "./myprompt \"rosrun kinova_yake camera_serviceMove_EyeInHand\""

 感觉terminal还是有点乱,下次看看能否限制窗口位置,或者使用terminator来执行脚本。

参考致谢:

https://blog.csdn.net/zong596568821xp/article/details/78623130

https://blog.csdn.net/qianzongCui/article/details/77877322

 https://blog.csdn.net/swust_long/article/details/7285147

========================

kinova_cnn_grasp.sh


#! /bin/bash

source /opt/ros/kinetic/setup.bash
source /home/user/catkin_ws/devel/setup.bash
source /home/user/baxter_ws/devel/setup.bash
source /home/user/kinova_ws/devel/setup.bash

# Kinova
{
gnome-terminal -x bash -c "roslaunch kinova_bringup 1kinovaJaco.launch;exec bash"
}&
sleep 3

# RealSense
{
gnome-terminal -x bash -c "roslaunch realsense2_camera rs_d435_camera_with_model.launch initial_reset:=true;exec bash"
}&
sleep 3

# Hand-eye calibration data
{
gnome-terminal -x bash -c "roslaunch kinova_yake realsense_in_hand.launch;exec bash"
}&
sleep 3

# Depth image to meter
{
gnome-terminal -x bash -c "roslaunch ggcnn_kinova_grasping wrist_camera_realsense.launch;exec bash"
}&
sleep 3

# cnn inference
{
gnome-terminal -x bash -c "rosrun ggcnn_kinova_grasping run_ggcnn.py;exec bash"
}&
sleep 3

# Robot move
{
gnome-terminal -x bash -c "rosrun ggcnn_kinova_grasping kinova_open_loop_grasp_key.py;exec bash"
}&
sleep 3

 

GitHub 加速计划 / li / linux-dash
6
1
下载
A beautiful web dashboard for Linux
最近提交(Master分支:3 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐