Page 1 of 1

Sending a Signal from windows to linux to run the script

Posted: Fri 16 Aug 2013, 02:28
by A Gobiraj
Hi All,

I need desperate help to run the shell script on Linux from windows PC .
I only have script on Linux which is used to kill the process on Linux but that script needs to be run from windows.

So can some one please help me out how to start solving this issue as I have zero knowledge on this. Some how I wanted understand the whole concept from one of good explanation from anyone else.

Thanks
Gobi

Posted: Fri 16 Aug 2013, 04:02
by Nathan F
Two things come to mind at present.

Install Putty on your Windows PC and use it to ssh into the Linux box. Probably easier.

The second would be to put a watch on a file using something like "inotifywait". If you access the file it sends a signal to the process watching it, which can then run some code. You could use ftp, sftp, or even samba to access the watched file.

The code for doing this with "inotifywait" is fairly simple:

Code: Select all

inotifywait -m -e access <some-file> | while read EVENT
do <some command>
done
Replacing <some file> and <some command> with the watched file and the command you want to run. Note that this method will keep the inotifywait program running as a background daemon until you kill it. If you only want to execute the script once, leave out the -m option.

Posted: Fri 16 Aug 2013, 05:53
by A Gobiraj
Hi Nathan,
Thanks for your prompt reply. The script file in the Linux needs to be executed from windows with some conditions. But I know C but I do have zero knowledge in handling the systems. I couldn't about watchfiles which you have mentioned.

But this my plan I need to write down exe file in C on windows which should control the script on Linux .

if { send the signal to Linux to execute the script}

else
{ nothing}

but I don't know how to call the signals in C and which signal needs to be called. Also I even don't know how to interface with Linux system to send this signal to execute the script. ( all our pcs are connected via intranet)
Thanks
Gobi

Posted: Fri 16 Aug 2013, 06:01
by Nathan F
Just to clarify then, do you need to have a windows program communicate with a linux program? Or is it enough to just be able to control the program from the windows computer?

Posted: Fri 16 Aug 2013, 06:13
by A Gobiraj
Hi Nathan,

I just want to control the process on Linux from windows PC.

Posted: Fri 16 Aug 2013, 06:38
by Nathan F
Then easy, install Putty and use ssh to log into your linux pc.
http://www.chiark.greenend.org.uk/~sgta ... on a LAN.

Posted: Fri 16 Aug 2013, 07:13
by A Gobiraj
HI Nathan,

any comments??

Posted: Fri 16 Aug 2013, 07:40
by 8-bit
A Gobiraj wrote:Hi Nathan,

I just want to control the process on Linux from windows PC.
Since linux and windows use different base kernels and linux uses script files while windows uses batch files, getting windows to understand and execute a linux script file would be rough.
If one can transfer a control file/application/script to linux in such a way that th file is executed by the linux box, then you have a door.
But there is the rub.
Figuring out where to place the file with instructions to the kernel to execute said file and the file having the executable parameters set.

Lets say that one was able to place an executable into the Startup folder in linux from windows.
On a reboot of the linux system, the file would execute if its parameters had been set correctly.

If I may ask though, what is your purpose of wanting to be able to execute a file on a networked linux box using windows??

Posted: Fri 16 Aug 2013, 07:41
by Nathan F
Don't know what happened there...

What I had type before was just reiterating that Putty is probably a good solution for what you need. It's a Windows program that includes a terminal and ssh client.
http://www.chiark.greenend.org.uk/~sgta ... nload.html
You'll need an ssh server running on the linux pc. Dropbear is a good solution if it's only going to be used over the LAN.

With that setup you can log into your Linux PC from the Windows PC and run any commands you wish.

Posted: Fri 16 Aug 2013, 08:01
by A Gobiraj
Hi Nathan,
So using putty and SSH server can I still invoke the script on Linux automatically using some code not manually.

Posted: Fri 16 Aug 2013, 08:06
by Nathan F
Well, that's what I was asking about before. If you want to have some program in windows control some program on a linux conputer, that's beyond the scope of what I mentioned.

Posted: Fri 16 Aug 2013, 08:08
by A Gobiraj
Actually we have two system for our Simulator system.
one with Linux and other one with windows. now we have some issue on Linux part of the simulator but we need to restart the process on Linux after we have some certain number of runs on windows PC. Because windows PC is the controller so that execution should be decided by the widows PC after the certain period of times.

Posted: Fri 16 Aug 2013, 08:11
by A Gobiraj
But this my plan I need to write down some coding on windows which should control the script on Linux .

if { then send the signal to Linux to execute the script}

else
{ nothing}

but I don't know how to call the signals in C and which signal needs to be called. Also I even don't know how to interface with Linux system to send this signal to execute the script. ( all our pcs are connected via intranet)

Posted: Sat 17 Aug 2013, 04:30
by 8-bit
What about having the linux script check for a ping or a sequence of them and act on that as a switch?
I am not sure if one could use the pings as a sort of morse code.
But having the linux script look for pings is a thought.

Posted: Sat 17 Aug 2013, 18:01
by akash_rawal
You can use TCP connections. This works whenever both computers are connected via network/internet.

On linux end you could use nc to listen at a particular port number, say 1234:

Code: Select all

nc -l -p 1234
On windows computer you have to open a TCP connection to the linux computer and write the message.

nc command running in linux machine will then output the message and exit. Then your script could evaluate the message and execute commands and optionally start all over again.

Posted: Mon 19 Aug 2013, 22:41
by Karl Godt
No idea how to code scrips on Windows .
I installed http://www.cygwin.com/install.html and am running
find command when Windows search gets on my nerves or
wget -c if downloads by Firefox disrupt
from it's bash shell .
It's a learning curve, though !