is it possible to send data from the matlab to run in the terminal ??
Show older comments
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 :
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
Accepted Answer
More Answers (3)
Marcus Lundmark
on 18 Mar 2019
0 votes
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
on 18 Mar 2019
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
on 18 Mar 2019
Edited: Marcus Lundmark
on 21 Mar 2019
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
Categories
Find more on Communications Toolbox 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!