フィルターのクリア

is it possible to send data from the matlab to run in the terminal ??

43 ビュー (過去 30 日間)
mostafa haggag
mostafa haggag 2018 年 4 月 22 日
コメント済み: HiWave 2022 年 1 月 14 日
hello i hope everybody is fine i have a question i usually do the following in the terminal and i want to do it using matlab the following is: i log in into another computer and i am asked for the password to i enter it i then change the directory of the new computer and i run a command . the terminal commands are :
1)ssh -X xxxx1234@xxxx.yyy.yyy-yyyyyyyyyyy.yy ( to login into my account on the other computer)
2)xxxxxxxxxxx (for my password)
3)cd palm/currentversion
4)mrun -d example neutral -b -h xxxxx -K parallel -X 48 -T 24 -t 1800 -q xxxx.p -r "d3# ts# pr# xy#"
5)i need to send y character for the simulation to run
6)exit
what i need to do is to automate the procedure so that I can run this command through a script in Matlab this is what i was able of doing till now to log in but it failed
if true
sayyes_file = [tempname() 'xxxxxxxx'];
fid = fopen(sayyes_file, 'wt');
fprintf(fid, 'password');
fclose(fid);
cmd_pattern = ('"ssh -X xxxx1234@xxxx.yyy.yyy-yyyyyyyyyyy.yy" < "%s"');
cmd = sprintf(cmd_pattern, sayyes_file);
[status] = system(cmd)
end
this part only the part to login but it does not want to work i donot know what i am not doing correctly thank you sooo sooo much grateful for your help

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 4 月 22 日
編集済み: Ameer Hamza 2018 年 4 月 22 日

Using system for doing ssh inside a script is not a good idea. You can use this file exchange submission to establish an ssh connection to a machine from MATLAB. You can refer to detailed examples included insides the referred file exchange submission. For your case, you can run

ssh2_simple_command(hostname, username, password, 'cd palm/currentversion; ...
mrun -d example neutral -b -h xxxxx -K parallel -X 48 -T 24 -t 1800 -q xxxx.p -r "d3# ts# pr# xy#"');

this will run the command, print the terminal result and close the connection. If you want to main the connection you will need advanced setup as given in example file.

  7 件のコメント
mostafa haggag
mostafa haggag 2018 年 4 月 22 日
編集済み: mostafa haggag 2018 年 4 月 22 日
I am very grateful for your help and guidance
thank you so much
yours
Mostafa haggag from egypt
HiWave
HiWave 2022 年 1 月 14 日
"Using system for doing ssh inside a script is not a good idea" .... can you explain why?

サインインしてコメントする。

その他の回答 (3 件)

Marcus Lundmark
Marcus Lundmark 2019 年 3 月 18 日
Will sshpass help?
Execute ssh with password authentication via windows command prompt
The sshpass utility is meant for exactly this. First, install sshpass by typing this command:
sudo apt-get install sshpass
Then prepend your ssh/scp command with
sshpass -p '<password>' <ssh/scp command>
This program is easiest to install when using Linux.
User should consider using SSH's more secure public key authentication (with the ssh command) instead.

Marcus Lundmark
Marcus Lundmark 2019 年 3 月 18 日
This works on a Linux machine.
First install sshpass as shown above.
Create a shell file containing one command or an entire set of commands on the remote machine.
On the local machine, run the following:
sshpass -p "<password>" ssh user@remotehost 'sh shell_filename.sh'
or
sshpass -p "<password>" ssh user@ipaddress 'sh shell_filename.sh'
Now the trick is how to get this to work with the MATLAB 'system' command?

Marcus Lundmark
Marcus Lundmark 2019 年 3 月 18 日
編集済み: Marcus Lundmark 2019 年 3 月 21 日
Here's a command that works on the MATLAB Command Window.
In this example, I am commanding a remote Raspberry Pi at 192.168.86.1 to collect data from an RTL-SDR.
% call the shell command to start a new rtlsdr collection
system("sshpass -p 'raspberry' ssh pi@192.168.86.1 'sh rtl.sh'");
Yeah, I'm still using the default username and password.
You can also use the ./ operator.
% call the shell command to start a new rtlsdr collection
system("sshpass -p 'raspberry' ssh pi@192.168.86.1 './rtl.sh'");
To be more secure, you are advised to change the password of your Raspberry Pi.
The shell file on the remote Raspberry Pi is named rtl.sh
(The shell file must be made executable.)
#!/bin/bash
# run rtl_sdr (full path must be provided)
echo "----------run RTL-SDR program"
/home/pi/rtl-sdr/build/src/rtl_sdr -f 107.7e6 -n 1e6 -s 2.048e6 "iq_data_"$(date +"%Y%m%d_%H%M00.dat")
To make a file executable
chmod +x filename.sh

カテゴリ

Help Center および File ExchangeInstallation Setup and Configuration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by