1

I want to remove all the files and folders inside the particular directory at /var/www/example directory using user data script at AWS instance launch. Can you please help me.

slava
  • 3,887
  • Maybe you just need run bash script at system startup like here: https://askubuntu.com/questions/228304/how-do-i-run-a-script-at-start-up ? You can change script to rm -rf /var/www/example/* – slava Nov 13 '18 at 06:37

1 Answers1

0

From Amazon's Cloud Service website:


The following example shows how to specify a script using a text file. Be sure to use the file:// prefix to specify the file.

aws ec2 run-instances --image-id ami-abcd1234 --count 1 --instance-type m3.medium \
--key-name my-key-pair --subnet-id subnet-abcd1234 --security-group-ids sg-abcd1234 \
--user-data file://my_script.txt

The following is an example text file with a shell script.

#!/bin/bash
rm -rf /var/www/example