Calling Linux command line in MATLAB - linux

I have recently learned, that in MATLAB, the "!" mark runs the code in a command line and follwed by the "&" will pull up the command window, FOR EXAMPLE:
!RUN_FILE.bat&
It was a great day when I discovered this, or should I say when someone told me this. Anyways I was wondering if there was a way to run this batch file on a linux machine that I am connecting to remotley with a Windows desktop? (I am a newbie when it come to anything Linux, so if it doesn't make sense let me know and please dumb down you answers if you don't mind) haha
THANKS,
ME

The Linux shell doesn't understand batch files. That's not to say that the batch file can't be re-written to work in the Linux shell. Post some more information about the Linux shell you are using and your batch script and perhaps we can help you port it to Linux.
On a second read of your question, I interpreted it a different way. Are you running Matlab on a Linux machine that you are remotely connected to, or are you running Matlab on your local Windows machine and you want to send the ! command to the remote Linux box?
If the latter is true, then you should probably be able to write a batch file (to run from Matlab) that will launch the remote script on the Linux box. How are you connected to the Linux machine? VNC? SSH?

Windows and Linux use different shell scripting languages, so you couldn't run a .bat directly on Linux, but could create a bash script to perform the same actions.

You might want to see this bat2bash online converter (I prefer re-writing though):
http://www.filegod.netfirms.com/Bat2Bash.html

Related

Can anyone explain how to shutdown the Linux system using system command?

I stuck in a problem, I want to shutdown the Linux PC using system command but my machine is asking to enter the password.
here is the scenario: I'm using 2 systems one is windows and another one is Linux. I'll send the command to Linux for shutdown, this Linux PC application made it as Service file, once I receive the command for shutdown, My Linux PC run the system function which is written like this system("shutdown -P now"); if I run this command my machine won't execute the command.
Kindly help me out in this!
Thanks & Regards
thank you Some programmer dude for your valuable feedback. Posting your suggestion as answer to help other community members.
The shutdown command needs super-user privileges. You can use some
additional commands to elevate the privileges along with the command
you are currently using.

Making bash on ungraphical debian look neat and tidy, like when sshing to it

OH GOD I'M SUCH A NOOB
wait let me explain this.
I am somewhat familiar with linux, and i own a raspberry pi which i use as a ssh server, but i recently got hold on a old Dell Precision M4300 Laptop, so i got a minimal debian installation on that as well.
Howerver, as i logged in directly (as using the display and keyboard on the machine) to the laptop, i discovered a strange thing:
When executing a command resulting in a new menu, for example
nano .bashrc
, and than exiting that menu, the output gets shown where previously only the list of typed in commands and outputs was. This seems somewhat logical, as the "menue" is a "command output" as well, but when sshing to the machine from my windows machine (via gygwin or putty), the "menue" closes and i see the list of prompts and command outputs again, the same happens when sshing to the raspi. Is this a speciality of Putty / Cygwin? Can i make bash on the machine clean up after nano?
Thanks for any replys, i am really out of ideas here, i don't even know the right search term...
The functionality you are talking about is implemented by smcup and rmcup which can be used by editors such as nano and other applications to save and restore the screen when they are invoked and exited. This functionality is known as alternate screen and you can find more documentation regarding it here. Some people actually are quite annoyed by it.
Unfortunately, if you're using the linux virtual console instead of X windows or even connecting into the machine via ssh from another computer, then it seems like this feature is not available, according to this other post.

Remote commands execution and file acces in Linux and Windows

Suppose I have a server application installed in a few Linux and Windows machines. Now I would like to control it remotely. That is, I would like to start and stop the application, update the application configuration files, reads the logs remotely.
It looks to be easy in the Linux worlds. I can use ssh, scp, and probably nfs to execute commands in remote Linux machines and access files there. The problem is that I would like to execute commands and access files in remote Linux and Windows machines uniformly from a Windows machine. I need also some scripting capabilities too.
What is the best way to do that?
You can try to use cygwin http://www.cygwin.com/ on your windows machines and install a ssh server with it.
If you need graphical tools, use VNC
there is an OpenSS implementation targeting Windows at http://sshwindows.sourceforge.net/download/
since there is (besides Cygwin/MinGW) no possibility to run bash code (ksh/csh/tcsh code as well) you should make yourself familiar with the windows scripting host.

Launch process from CGI in Linux

I need to launch server executables from terminal. They are running through wine (because those executables are for Windows) in the background. If I launch them normally, from Terminal, those work without any problem.
Now I'm trying to make CGI (bash) script and launch servers from website, but script doesn't launch processes. I thought that it has something to do with wine, but no, script doesn't launch any processes at all.
I'm building that system on Ubuntu 12.04.1 LTS, after that scripts would go onto Debian server.
So, the question is: is it even possible to run background process from CGI scripts? If yes, would you please explain how?
A CGI program is like any other program, except that it is supposed to run quickly and to follow the CGI protcol (in particular, regarding to stdout output).
As with any other Linux program, you can (subject to limitations and permissions on your system) run processes, using syscalls like e.g. fork(2), execve(2) and many others.
I suggest to read a good Unix programming book like Advanced Unix Programming abd Advanced Linux Programming. We can't teach all that here in a few minutes.
You could also run processes using the library system(3) and popen(3) functions (of course these functions are implemented using syscalls, inside GNU libc)
Don't forget the stateless property of CGIs; you may consider using FastCGI or SCGI instead.
(A program started thru wine from a CGI might fail, e.g. because it has no X11
server to talk to; For C# programs, consider Mono on Linux).
Another possibility could be to run Windows in some VM, and have your CGI interact with such virtualized Windows programs. Not knowing Windows, I have no idea about the issues of such an approach.

Running Matlab tasks on remote machine

I am working on machine learning task in Matlab (using Neural networks toolbox of Matlab). Thus I need to run computations that are very demanding in terms of RAM and processor time. My computer is not sufficient for that task but I have an access to Linux server that is powerful enough.
I am looking for the way how to run computational tasks from Matlab GUI that is running on my own computer on that server. Ideally it should work given these condition:
My computer is running Windows 7, the server Red Hat Linux
I can connect to the server only using SSH protocol (currently I'm using putty for that task)
The server does not have Matlab installed. I can ask server admin to install it but that may take some time, it would be better if that is not needed. There is Java virtual machine (and development kit) installed on the server.
I prefer to use Matlab GUI on my computer (not Matlab command line)
How can I do that? If you need more information about the settings or if you know other solutions please leave a comment. I'll be happy to respond.
If you do not have matlab on the server, the only way is to:
modify the code such that it outputs a file
compile your code using mcc (toolbox required)
send it to your server (do you have a shared disk?, otherwise use pscp http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html )
execute it (using putty from command line)
get back the output file (same than sending)
We are all doing that in my lab (except that we are on ubuntu)
As hinted at in the comments, Parallel Computing Toolbox + MATLAB Distributed Computing Server could address this, and if you're actively updating the code, it may be simpler than the mcc approach. However, you do have to install the MDCS piece on the server and get things set up. If you're not using any MEX files, the difference in architecture should be irrelevant. If you are using MEX files, you need to ensure that you can compile them for the server architecture and make them available there.
You can run MATLAB jobs on remote Linux server from your local PC without the MDCS setup however for large scale and multiple users the MCDS is highly recommended. You can use plink to automated the putty command line execution from MATLAB.
We are executing our Simulink model simulations with multiple iterations on a more capable remote Linux server. You will require the following:
1) MATLAB installation on both client and server machine with parallel computing toolbox
2) Mapped Linux server shared network drive (for data I/O)
3) Plink for automated Putty
4) Command line script for silent MATLAB execution on the remote machine
MATLAB code example:
plinkFile = which('plink.exe');
command = [plinkFile ' -ssh ' [ServerUrl] ' -l ' [Username] ...
' -pw ' [Password] ' matlab -nodesktop -nosplash ' ...
'-r "' [RemoteScriptName] ...
'\(\''' InputDataSharedDriveFilePath] '\''\);" &'];
[status,cmdout] = system(command);

Resources