Search code examples
amazon-web-servicesamazon-ec2cron

Stop Cron Job to close reboot infinite loop


I had created a script to reboot system after 90% Cpu utilisation. But for some testing purpose i changed the Vlaue of Cpu Utilisation to 0.7%. And script is programmed to run system reboot. Because of that Server never online it has got into some infinite reboot loop.

My Script :

#!/bin/bash
dstat| awk '{ if (int($1)>0.7) { 
              i=i+1; {
                       print i, $1
               }
              }
           
           if (int($1)>0.7) {
           j=j+1;
           }   
           if (j>2) {
                  print "system reboot";
                  cmd="sudo reboot";
                  system(cmd)
           }
        }'

N the script is programmed to run on reboot by using crontab :

@reboot /bin/bash /ubuntu/home/reboot.sh

So i am unable to login using SSH. Because the system is constant reboot. My Server is aws ec2 insatnce

I have tried passing user data through aws console.

sudo apt-get purge dstat
cd /ubuntu/home && sudo rm reboot.sh
sudo /etc/init.d/cron stop

But it doesn't work.

So, Any way to get my instance back would be highly Appreciated.


Solution

    • stop the instance
    • detach the root volume
    • attach it to another instance, already running, in the same availability zone
    • mount it at /mnt
    • fix the misconfiguration by editing the file, which you should find at /mnt/home/ubuntu/reboot.sh
    • unmount
    • detach
    • reattach to the original instance
    • start the instance