Run .bat script in unix - unix

I have one .bat script on my windows share that is mounted to my UNIX machine. Bat script is set to make file transfer between 2 windows shares, but I would like to trigger this script from a unix machine if that is possible. I was reading that you can do it with wine or dosbox, but I don't have that installed on my unix. Is it possible to resolve this problem with some additional .sh script that will trigger my .bat script correctly?
Thank you in advance.
Best regards.

You cannot run a .bat script on a Unix machine for several reasons :
Unix has not the same commands (on the command line) as Windows. The POSIX standard defined a set of commands, if you use them you'll be portable on various POSIX systems (but not on Windows); for example to list a directory, you'll use DIR on MSDOS and Windows but ls on Unix and POSIX; to copy a file it is COPY on MSDOS and Windows but cp on Unix and POSIX; etc....
Unix has not the same command interpreter as Windows. The POSIX standard and the Unix tradition provides a Unix shell and POSIX has standardized /bin/sh (a.k.a. POSIX shell). Windows has CMD (inherited from MSDOS) and PowerShell.
The way of interpreting commands is different (on Windows look also into PowerShell, which I don't know). On Unix it is the shell (not the invoked programs) that is expanding your command and globbing. See this answer for more. The notion of current working directory is different.
the operating system concepts are (slightly or significantly) different on Windows and on Unix or POSIX. For example, files, directories, processes, libraries are different (for example, a file can be written by a process and removed by another one on Unix and it can have several names on Linux thru hard links), .... etc.... You could read Operating Systems: Three Easy Pieces for an overview.
the Unix philosophy is not (always) applicable to Windows.
So you need to study Unix (or POSIX) and write your own shell script from scratch. Don't try to "translate" a bat script to a Unix shell script, but redesign it entirely (starting from the problem you want it to solve).
(and Wine or DosBox is not helpful in your case)
Read also about SCP and perhaps FTP. Perhaps using some distributed version control system like git could be relevant for you (e.g. to share scripts, source code, etc...).
If you need to run remotely some Windows .bat script on a distant Windows machine (e.g. from a Unix machine), you should use some remote command running service (that is, find and use some equivalent of SSH service on Windows, and use the corresponding client on Unix). See this.
So if you need to remotely run on a Windows server something (e.g. some program, some script, some command) from a Unix machine you should ask a different question (or at least improve a lot the current one).
Read about the client-server model and about application layer to use the correct terminology. You should name what protocol, server, client, service you want to involve. Nothing is magically "triggered" without using them.
PS. I'm using Unix since 1987, Linux since 1993. I never used Windows.

Related

Difference between iTerm2, zsh and oh-my-zsh

I have been using the default bash of linux for over 1 year and one of colleague recommended me switch over to using iTerm2 alongwith zsh and oh-my-zsh. He also recommended this post to install and configure those :
https://www.freecodecamp.org/news/how-to-configure-your-macos-terminal-with-zsh-like-a-pro-c0ab3f3c1156/
When i asked what are they the answer he gave me was kind of confusing, so i ask you overlords kind do tell mewhat actually those are and if you have some insights about what actually a bash is, i would be happy to learn that too :)
Thank you all
Pawan
When you are at a command line, typing in commands and reading output you are working in a program called a terminal (or console on windows). The terminal is taking your commands and forwarding them to a program, called a shell, who's job is to actually execute the commands you type in to the terminal and possibly print some output. The output from the shell is then displayed in your terminal window.
The terminal is like the web browser and the shell is like the javascript engine. Your browser takes your input (click, keypresses, mousemoves) and sends them along to javascript which processes those actions and the browser displays the results.
iTerm2 is a terminal emulator meant to be a replacement for macOS terminal and is far more feature rich. It's the terminal program providing you with a command line interface.
ZSH is a specific shell, as is bash, the same way linux is a specific operating system. There are different shells that provide different syntax, features and functionality. There's bash, cshell, fish, powershell, zsh and others.
Installing ZSH, you are essentially downloading a new program and telling your terminal to use that program (say, instead of bash) to process the commands and run scripts.
oh-my-zsh provides a way of managing your zsh configurations, themes and plugins to extend the look and functionality of your shell.
I can't reccomend this setup enough- it's like the cadillac of command lines. You have a good friend there.

Triggering a windows batch script from unix shell script

I Have a unix shell script, after it runs, it will ftp a file to windows server. Then i need to manuallu schedule a windows batch script. couls you please suggest me method where i can call the batch script from the unix shell script.
Thanks in advance
Take a look at this:
https://stackoverflow.com/a/16720186/2471910
It talks specifically about invoking a windows program from another windows machine (instead of a unix machine) but the concepts are the same since ssh is available on unix as well.

Using SSH in Cygwin - Invoking local programs

I'm working on an assignment where I need to remote connect into my company's UNIX boxes and parse out a particular set of log entires. I've figured out a method for doing so with Grep and the -C flag, but the version of UNIX installed on these machines doesn't support that functionality. One alternative I've considered is doing the work on my local machine through Cygwin and using the local version of Grep to handle this task. However, these logs are especially larges, upwards of 50 megabytes and the connection to the boxes are very slow so it would take several hours to complete the downloads.
My main question, is it possible to remote connect through SSH to a remote server, but be able to invoke the locally installed versions of certain programs? For example, if I SSH into the server, can I make use of the local version of Grep instead of the remote system's version of Grep?
I've attempted to do something similar using Awk and Sed but I haven't had much success. At this point, aside from a long period of downloading, I'm not sure what other options I have. Any advice? Thanks in advance. :)
Even if you could use a remote file with a local application, you'd still be downloading the entirety of the log files - ssh allows output/input to pass between boxes, but you're not actually running your local grep on the local machine - it'd be the remote machine sending its file to your local grep.
One alternative is to gzip the logfiles before sending them through ssh,e.g.
ssh user#remotebox 'gzip -9 - logfile'|gzcat -|grep whatever
You'd still be sending the entirety of the log files, but log files tend to compress very well, so you'd only be sending a small fraction of the original data (e.g. a couple megs v.s. 50 uncompressed).
Or, in the alternative, you could try compiling gnu grep from source on the remote machines, assuming there's an appropriate compiler toolchain on those machines.

R help files on different OS

Is there some way to access the Windows version of a helpfile on a Linux computer within R?
I write a decent amount of R code on my Linux machine, but I do have to make sure the code will run on a Windows machine for collaborators.
I've been burned a number of times by reading a help file on my Linux machine, writing my code, and then spending hours wondering why it's not working on the Windows machine until I check the helpfile on that machine and realise that it is different to the one on the Linux machine.
It'll usually have a "NOTE: On Windows, xxxx behaves differently...", and I wish I knew that while I was writing the code on my Linux machine!
I do realise that many help files are system-specific (for example ?system), but sometimes I would like to read the Windows version on my Linux computer. Today I found myself wanting to read ?windows but had to boot up my Windows laptop just to read that helpfile, because that function isn't available on Linux and so there's no help file.
cheers.
You can always look at the source which gives you clear conditionals -- this is from man/system.Rd:
#ifdef windows
Only double quotes are allowed on Windows: see the examples. (Note: a
Windows path name cannot contain a double quote, so we do not need to
worry about escaping embedded quotes.)
[...]
#endif
#ifdef unix
Unix-alikes pass the command line to a shell (normally \file{/bin/sh},
and POSIX requires that shell), so \code{command} can be anything the
shell regards as executable, including shell scripts, and it can
contain multiple commands separated by \code{;}.
[...]
#endif

shell script running by sensing a file

i am working on unix.
i want to write a shell script which will check for a file called "temp_file.txt" on windows
and then execute some commands.
is this possible?
how could we connect to the windows and go to a specific directory and check for a file?
Share the directory on the Windows machine using the "regular" Windows file sharing facilities. On the Linux side, you have two options:
Use smbclient to connect to the Windows machine and check if the file exists or
Use smbmount to mount the shared directory into your Linux file system and check file existence using "standard" Linux commands (e.g. test).
The exact implementation details will depend on the scripting language that you use, but your pseudo-code will look something like this:
loop:
check if file exists
if yes: do something useful
sleep for some reasonable time
(I am assuming that you want to execute the commands on the Linux machine.)
If you're using Linux (you specify that you're using Unix, but not what variant), check out the inotify API --- this will allow you to set up event responders for filesystem events (much more efficient than polling).
From a shell script, you can use the inofitywait command --- see http://linux.die.net/man/1/inotifywait for more information.
you could set up SSH on Windows and then write a script on Unix using the SSH client to connect to Windows and execute the command. The alternative, if you can afford to, it to write a windows batch, and execute your command on Windows itself. Or you can turn on Windows terminal services, and use telnet protocol from Unix to issue the command. Programming languages that support telnet includes Perl (Net::Telnet) and Python(telnetlib)
As ghostdog74 suggested, ssh is your best bet. You can run something like (I assume you have Cygwin or SFU installed)
ssh "[ -e $file ] && do_something.sh" > do_something.log
If your command logs to stdout, you get the log on your Linux box as well.
If you set up private key authentication, it gets even better.

Resources