Linux command line automation

I am using linux screen command to run different directory files one by one. I have a 33 vm folder, each folder contains images to execute.

Root directory      = /home/root/
VM folder avaialble = /home/root/vm1,vm2,vm3...vm32

      

I need to start all vm at the same time, for this reason I am using the screen command. each screen command will execute 1 vm. You need to move the entire 33 vm folder and execute all 33 vm images at the same time.

ctrl + A c = new screen

      

Follwing is my code

     for (( i=0; i<=33; i++))
        do
        screen
        ls
        vm1 vm2 vm3 vm4 ....vm33
        cd vm1
        ls
        qemu-system-x86_64 -kernel image -hda core-image-full-cmdline-qemux86-64.ext3 -smp 4 -m 512 -nographic --append \
    "root=/dev/hda console=ttyS0 rw mem=512M oprofile.timer=1"  
        cd ..
        screen
        qemu-system-x86_64 -kernel image -hda core-image-full-cmdline-qemux86-64.ext3 -smp 4 -m 512 -nographic --append \
"root=/dev/hda console=ttyS0 rw mem=512M oprofile.timer=1"
        cd ..
        .
        .
        .
        done

      

qemu exits as soon as it starts up and looks with it on how to fix this issue.

Thanks in advance.

+3


source to share


2 answers


Finally I got a solution, thanks for user2053215 - https://unix.stackexchange.com/questions/47271/prevent-gnu-screen-from-terminating-session-once-executed-script-ends

1.Create a shell script to execute qemu name as "vm.sh"

    cd $1
    qemu-system-x86_64 -kernel image -hda core-image-full-cmdline-qemux86-64.ext3 -smp 4 -m 512 -nographic --append \ "root=/dev/hda console=ttyS0 rw mem=512M oprofile.timer=1

      

2. Then we need to create another shell script which is the main script



for (( i=1; i<=32; i++ ))
do
  cd vm$i
    screen -dmS vm$i sh -c "./vm.sh vm${i}; exec bash" 
    cd ..
done

      

3. Now do the -ls screen; It will display the entire captured screen with pid.

4.Do " screen -r pid

"

Done :) Special thanks to user2053215 and pietro

0


source


When the screen is launched with no parameters, the result is the opening of the interactive screen session.

One way to achieve what you want (assuming the current working directory is the one that contains all the vms folders):

for (( i=1; i<=33; i++ ))
do
   cd vm${i}
   screen -dmS vm${i} qemu-system-x86_64 -kernel image -hda core-image-full-cmdline-qemux86-64.ext3 -smp 4 -m 512 -nographic --append "root=/dev/hda console=ttyS0 rw mem=512M oprofile.timer=1"
   cd ..
done

      

And here's the explanation:

for all of your 33 virtual machines, go to the vm folder, then launch a separate screen named "vmX" which will launch qemu.



After that, you can enter each screen by calling:

screen -r vmX

      

where X is the number of the virtual machine to manage (for example, kill with CTRL-C qemu or see its stdout / stderr output).

Example:

screen -r vm1

      

+1


source







All Articles