帮我用shell实现当rviz启动时开始自动录制rviz的画面,当rviz进程被杀死时保存录制的视频
时间: 2023-06-04 09:03:20 浏览: 155
Shell实现判断进程是否存在并重新启动脚本分享
Sure, 我可以帮你实现。你可以使用以下命令:
```
#!/bin/bash
# Path where to save the video
VIDEO_PATH="/path/to/save/video"
# Start recording when rviz process starts
while true; do
if pgrep -x "rviz" > /dev/null; then
echo "rviz process found, starting to record video"
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
gnome-terminal -e "rosrun image_view video_recorder image:=/rviz/camera1/image_raw _filename:=${VIDEO_PATH}/rviz-${current_time}.avi"
break
fi
done
# Stop recording when rviz process is killed
while true; do
if ! pgrep -x "rviz" > /dev/null; then
echo "rviz process is no longer running, stopping video recording"
sleep 5
killall gnome-terminal
break
fi
done
```
这个脚本会等待rviz进程启动,一旦找到rviz进程,它将在新的终端窗口中运行rosrun image_view video_recorder节点,开始记录rviz画面。当rviz进程被杀死时,脚本将停止录制并关闭视频记录器节点。
阅读全文