Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am new to LINUX operating system. I am using ROS (Robotic Operating System) where I type few commands in separate terminal windows for doing the setup.

ie Before I run my program, I have to do(each in separate terminal) :-

karthik@Satellite-C640:~$ roscore

karthik@Satellite-C640:~$ rosrun nodelet nodelet standalone velodyne_pointcloud/CloudNodelet

karthik@Satellite-C640:~/Desktop/OpenCV$ source setup.bash

karthik@Satellite-C640:~/Desktop/OpenCV$ rosrun pcl_tutorial front_view_bag input:=/velodyne_points

karthik@Satellite-C640:/media/BE8C6D3A8C6CEDF9/Users/KARTHICK/Desktop/project/ros_datas$ rosbag play file2.bag

The above commands are a must before I can actually run my C++ program and it is to be in the above order, issued from the respective directories.

I am using ubuntu12.04. Is it possible to write a program or something (sorry i am not familiar with linux) so that if I run that single program, all the above commands will be properly executed in separate terminals at the respective directories rather than manually executing them each time.

Thanks in advance

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

You can make a shell script, to do so, open a Terminal with Ctrl + Alt + T and type:

touch daily-script.sh

Now we need to edit this file contents

xdg-open daily-script.sh

Next copy paste the below code to your file:

#!/bin/bash

cd $HOME
xterm -hold -e "roscore" &
xterm -hold -e "rosrun nodelet nodelet standalone velodyne_pointcloud/CloudNodelet" &
cd $HOME/Desktop/OpenC
xterm -hold -e "source setup.bash; rosrun pcl_tutorial front_view_bag input:=/velodyne_points" &
cd /media/BE8C6D3A8C6CEDF9/Users/KARTHICK/Desktop/project/ros_datas
xterm -hold -e "rosbag play file2.bag"

exit 0

Once you save the file open a Terminal and type:

chmod +x daily-script.sh

Finally your file is executable, to run it:

./daily-script.sh

share|improve this answer
    
I did exactly as you said... and get a terminal window in which the first command roscore is being executed... when I do ctrl+C it closes and another window having second command opens... They are not executing simultaneously ...which is what I want as I mentioned in my question... the commands start a process which depends on the previous one...so the order is necessary and they are executed simultaneously in separate terminal windows normally. –  KARTHIK Feb 22 '13 at 8:22
    
I tried the edited answer... Now the commands execute in separate terminals simultaneously as I wanted... But the fourth command is not executing... This command runs the executable for a program front_view_bag .The executable is located by doing source setup.bash in the ~/Desktop/OpenCV/ directory allowing all packages in this path to be found by ROS.. –  KARTHIK Feb 22 '13 at 8:38
    
@KARTHIK I updated my post –  efthialex Feb 22 '13 at 9:08
1  
Thank you @efthialex...Its working now... Can you provide me some links to learn about shell scripts... –  KARTHIK Feb 22 '13 at 9:31
    
Well I had bought a book called Pro Bash Programming: Scripting the Linux Shell (Expert's Voice in Linux). Publication Date: October 19, 2009 | ISBN-10: 1430219971 | ISBN-13: 978-1430219972. You can find this book on Amazon. Also google learn shell scripts and you will find some useful resources. –  efthialex Feb 22 '13 at 9:46
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.