Use the commands expect
and autoexpect
to automate the backup script and avoid the script to prompt for input. This is recommended in order to not require the user running the scrips to supply the password via the CLI and also allow for permissions on the file containing the password to be locked down.
First, we need to build the expect
script by running a backup with expect to record the process.
Start by typing the following command in the preferred home directory.
This creates a file called backup_password.exp
which is essentially a recording of the prompts used during the running of the script.
# autoexpect -f backup_password.exp /opt/PrimeKey/support/system_backup.sh
CODE
The backup_password.exp
file now has the contents of the options we used in the running of the backup.
WARNING The backup_password.exp
file contains the password used to protect the backup in plan text.
If you are uncomfortable with this, remove the file or proceed to protect the file with permissions.
# sudo chown ec2_user backup_password.exp //make ec2_user the owner.
# sudo chmod 700 backup_password.exp //make file only readable by ec2_user.
CODE
Next, run the backup with the file containing the recording of the process by using the expect
command:
# expect -f backup_password.exp /opt/PrimeKey/support/system_backup.sh
CODE
The backup file was created and the prompts filled out as specified.
Add this script to cron (if desired) in the next section Optional - Automating the Backup Script.