I want to execute shell script whenever I start my ec2 (Linux )instance first time
Any Suggestion Please.
For the time being you can add the entries/command in initrd file and you can create a softlink for it. This will help you to execute the shell script whenever u will start your linux machine whether it is on EC2 or on linux.
See "Running Commands on Your Linux Instance at Launch".
You can use "user data" or "cloud-init" to do it. There's a section when manually launching EC2 instances to add the user data, and you can do it through APIs too.
Related
I had a project where I need to run a command at EC2 reboot. I found only information about User Data but that works only at first launch which is not exactly what I needed. I need a command to run everytime I connect to the machine.
You can store a shell script in this directory:
/var/lib/cloud/scripts/per-boot/
It will be automatically run after every boot. (This is done by cloud-init, which also runs User Data scripts.)
After a little bit of research, I found a very easy solution. You can simply run.
echo "YOUR_COMMAND" >> .bashrc
This works also if you write it in the User Data section when launching your EC2 instance so that you don't have to SSH into it after launch.
Enjoy!
I went through Get Start Guide and api_request_doc to find a way to execute a script when start a microVM? But there is not way to do it.
Is there a way to achieve it? I want to run some script when a vm startup or execute a script without login.
So, far firecracker has not provided any support to start a script on startup.
You can use system daemons like openrc (for alpine based) and systemd to start the script on the startup.
to start script using systemd on startup, check https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux
I'm trying to start a script every time I start my amazon micro instance (amazon linux ami).
I tried to put it in /etc/init.d/ and linkted it to /etc/rc.d/ but the script is not executed.
I've also looked at user-data scripts, but as I understand the documentation they are only executed on the first startup of the instance.
What do I have to do to run my script on every startup?
Init.d/rc.d are primarly used for services. Any scripts that you install here have to be enabled to run at boot chkconfig service on.
Since it sounds like you are really just running a one time script. You can set it up to run with cron using the #reboot flag instead of providing a time.
On an OpenSuSE linux machine, I want to run a script when the machine is booted. As the script does not start a service, is /etc/rc.d the correct place for the script?
Thanks.
That's where I've always put them. There are several scripts in rc.d already which don't actually start a process. However, you need to write it in a similar fashion to the other startup scripts - have a look at a few to see how they are set up. Specifically, you should make sure that it's possible to run the script using /etc/rc.d/myscript start.
My operating system is windows xp and my server is Linux. I have developed a code in perl(saved in shell file).
I want to connect to Linux machine from Windows using your script only and then run a script on linux and this should be done on daily basis and automatically also.
Is it possible to do that?
Shell file under windows? that's called a batch file
Here is an example how you can set up a scheduled task on windows
If your remote machine is on linux, you can read here how you can set them.
You have several options to run the script on remote machine:
copy the file on the remote machine in the same location with the same file name (with ftp or ssh you can do this with another script) and set the linux machine's cron job to execute that same file daily
install a (web) server on the linux machine and create a web page through which's interface to upload and execute the script (this way you don't have to set up a cron job on linux)
create a script on the linux machine which to connect to another service (like a ftp location), download the needed script (the one which you want to execute) and execute it. Put the downloading script in your cron to execute whenever you want
use Net::SSH::Perl in your script to run commands on the linux machine (for this, you need ssh access to that machine, obviuosly)
Yes. Create a Scheduled Task which runs the PERL.exe with the script file name as an argument.