Automated Changing File Permissions via bash in Matlab

11 次查看(过去 30 天)
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!

回答(1 个)

Sourabh Kondapaka
Sourabh Kondapaka 2020-8-11
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.

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by