Automated Changing File Permissions via bash in Matlab

10 visualizaciones (últimos 30 días)
Miranda Ramirez
Miranda Ramirez el 18 de Sept. de 2019
Respondida: Sourabh Kondapaka el 11 de Ag. de 2020
I am having difficulties automating changing file permissions. There are files I'm moving to a remote server that I'm trying to access from my local machine. However, the file permissions need to be changed before I am able to accesss them. The bash script is as follows:
-----------------------------------------
ssh user@hostname
password
cd user/laptops
sudo chmod -R 744 */
password
exit
-----------------------------------------
I tried doing a system call, but MatLab doesn't allow password inputs. How can I make this script possible in Matlab? Thanks!

Respuestas (1)

Sourabh Kondapaka
Sourabh Kondapaka el 11 de Ag. de 2020
Hi,
You can use the “system()” function in MATLAB to achieve this. The system()” function takes a string or character array as input which would be your command.
I see that you are trying to a connect to a remote linux host.You can use the following:
Assume password, username and hostname are 3 variables which have the password, username and hostname of the remote host respectively.
[status, cmdout] = system('exit');
command = ['sshpass -p ',password,' ssh-o StrictHostKeyChecking=no ', username,'@', hostname ' ' '''echo -n'''];
[status, cmdout] = system(command);
% 'status' is 0 if the command was successfully executed
% ~0 otherwise
% 'cmdout' is the output of executing the command
% Close connection once tests are over
[status, cmdout] = system('exit');
A similar question has been answered here.
SSH/SFTP/SCP For Matlab (v2) is one of the several submissions in MATLAB File Exchange on MATLAB Central which is a forum for our product users to interact, exchange information and knowledge, without MathWorks' involvement. Feel free to contact the author of this submission directly for specific questions about the implementation.

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by