Totally new to shell script's and I have a script that execute the following command in order to export my database from Vagrant:
export_folder="/var/www/projects/DatabaseBackup/local"
schema="wp"
tables="wp_8_options"
export_data="mysqldump -uroot -pmy-secret-password --opt $schema $tables > $file_name.sql"
sudo vagrant ssh --command "cd $export_folder && $export_data"
$export_folder : Is the path inside Vagrant, that corresponding on my host computer folder
$scema : The database to export from Vagrant mySql server
$tables : The tables to export from the selected schema
$export_data : The actual mysqldump command that exporting the data
sudo vagrant ssh --command "..." : The command that instruct the Vagrant to use the SSH in order to execute another command inside the Vagrant VM.
All the code above, run's from a shell script and until now it works properly. The reason I have write this script is to automate the database exporting when ever I commit something on my Git by using the Git hooks.
The problem with the above script, is that I cannot run it via the Git hooks, because it is using sudo.
Unfortunatelly the Vagrant requires sudo on my computer in order to get run. Also, you should know, that I am not a Vagrant expert, and the Vagrant got installed on my computer by another coworker, so I don't know how to modify it in order to run without sudo.
Additionally, I don't really care about this script security because will only run from inside my computer.
So the question is, how to run this script, without using the sudo command. What are the options for that ?
sudo? I am using it on Ubuntu and it worked withoutsudoout of the box. Did you install it in some weird way? Or perhaps initially create the Vagrant VM asroot?cat /etc/groupif there's a vagrant group. If so add your user to the group.vboxusers:x:126:that maybe is for the VirtualBox