Automated Changing File Permissions via bash in Matlab
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Sourabh Kondapaka
le 11 Août 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 commentaires
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!