Automated Changing File Permissions via bash in Matlab
15 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Sourabh Kondapaka
on 11 Aug 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');
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.
0 Comments
See Also
Categories
Find more on Software Development Tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!