user8863627
user8863627

Reputation: 37

How to update php file using shell script

I want to update backup.php file with below details using shell script

$source_server_ip = ""; 
$cpanel_account = ""; 
$cpanel_password = ""; 

can someone please guide me how to ask below questions to user and update details in backup.php file ?

echo "Enter hostname: '$hostname'"
echo "Enter cPanel username: '$user'"
echo "Enter password: '$pass'"

I tried below code but got an error

#!/bin/bash
echo "Your hostname: "
read hostname
echo "Your username:"
read user 
echo "$source_server_ip = "$hostname;"" >> backup.php
echo "$cpanel_account = ""$user"";  >> backup.php

Thanks

Upvotes: 0

Views: 338

Answers (1)

enyard
enyard

Reputation: 174

By this way, you can try this

#!/bin/bash
read -p "Enter hostname: " hostname
read -p "Enter cPanel username: " user
read -p "Enter password: " pass

if [ -f "backup.php" ]
then
    rm backup.php
fi
echo "\$source_server_ip = \"$hostname\";" >> "backup.php"
echo "\$cpanel_account = \"$user\"; " >> "backup.php"
echo "\$cpanel_password = \"$pass\"; " >> "backup.php"

The built-in read command stops the script and waits for the user to type something from the keyboard. -p (prompt) is a shorthand feature that combines the printf and read statements. read displays a short message before waiting for the user to respond.

Upvotes: 1

Related Questions