Michael Lazin on 2 Jul 2015 09:26:14 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] not entirely off topic, killing a windows process with cron using cygwin


That's exactly what I did, I used the windows task manager to call /bin/bash in cygwin to run taskkill /PID `tasklist | grep Agent | awk '{print $3}'` /F"

It's messy but it does what I want.  I basically have to shut down a program before I leave work every day so I have automated it shutting down after I am gone because I keep forgetting.  I would rather automate it and forget about it.

On Thu, Jul 2, 2015 at 12:21 PM, Thomas Delrue <delrue.thomas@gmail.com> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

One thing I just realized, if you really need to run grep and other unix
executables in your script to figure out which PID to terminate, and
therefore really need Cygwin (although I doubt this); I'm pretty sure
that you can invoke cygwin from the Task Scheduler (thus solving the
scheduling problem) while passing as a parameter to cygwin, the script
to execute which will now have the ability to run grep and ls and awk.

Lastly, I remember that there is a grep for windows
(http://gnuwin32.sourceforge.net/packages/grep.htm and
http://gnuwin32.sourceforge.net/), which was always one of the first
tools I deployed on any windows machine I took on.

There is also findstr which is like the 'not-so-bright windows cousin of
grep'.

On 07/02/2015 11:54 AM, Michael Lazin wrote:
> You're right, I hate windows and I really want to use grep, but it
> seems that I can automate the running of  /bin/bash in the windows
> task scheduler too.  Thank you.
>
> On Thu, Jul 2, 2015 at 11:51 AM, Thomas Delrue
> <delrue.thomas@gmail.com> wrote:
>
>> I understand I'm pushing back against "doing this in Cygwin" but I
>> think that the 'native' windows solution is going to be easiest to
>> set up as well as maintain (e.g. remote maintenance, EventLog
>> integration, etc).
>>
>> Task Scheduler is pretty easy: you can specify the command (which
>> can be an exe, batch file, ...), the 'user context' to run it in,
>> the time when to run and the frequency. It's all there with a
>> simple UI to do. This would eliminate the question of 'should
>> cygwin be running'.
>>
>> On 07/02/2015 11:43 AM, Michael Lazin wrote:
>>> I did use the taskkill command coupled with bash, I want it to
>>> run at a certain time of day, that's why I'm using cron.  Cygwin
>>> will let you mix windows and linux commands, I used awk and grep
>>> to get the windows PID. It's pretty beautiful, I just need to
>>> make sure that cron runs as
>> expected.
>>>
>>> On Thu, Jul 2, 2015 at 11:39 AM, Thomas Delrue
>>> <delrue.thomas@gmail.com> wrote:
>>>
>>>> Here's a suggestion that doesn't require cygwin (or it being
>>>> open) $> taskkill /im something.exe /f
>>>>
>>>> Taskkill /? will show you the different options including one
>>>> for specifying a PID
>>>>
>>>> You can use a scheduled task to kick it off whenever you want
>>>> under whichever credentials you provide
>>>>
>>>> On 07/02/2015 11:18 AM, Michael Lazin wrote:
>>>>> I have a windows process that I should shut down every night.
>>>>> I am more comfortable with bash than I am with windows
>>>>> anything.  I used cygwin and a small bash one-liner to kill
>>>>> my process.  I have tested my bash one liner and it does kill
>>>>> said process, my question is, do I have to leave my cygwin
>>>>> bash terminal open for cron to run my bash script?
>>>>>
>>>>> I checked stack overflow and they say this:
>>>>>
>>>>>
>>>>
>> stackoverflow.com/questions/707184/how-do-you-run-a-crontab-in-cygwin
- -on-windows
>>>>>
>>>>>
>>
I don't have admin on my windows machine, I can't make it run as a
>>>>> service
>>>>>
>>>>> I don't want to use the windows schedular, I want to use
>>>>> bash dammit.
>>>>>
>>>>> My question to the group is is anyone familiar enough with
>>>>> cygwin to know if the cron function will work if I don't run
>>>>> cygwin as a service, do I need my cygwin bash window to be
>>>>> open for this to work?
>>>>>
>>>>> I might try scheduling a task for tonight when I'm still here
>>>>> to see if it succeeds, but I was just wondering if anyone has
>>>>> experience scheduling with cron in cygwin.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBCgAGBQJVlWUfAAoJEKosl9oIs/pOR60QALqUQ9oMz8uGD2RIhrjeOfB4
JqvQW2k8RmNPcgInVnumxO07ZyT2Ew1PVfedIUTYIFWsSPT0De7BllpzoawhP0cV
dRT1OKkgHtxskHxje6beSZY8VsPaTgW+WdAk4gkjG2kLFgJFJxJT5t1AE2I2C88i
K3egG2t9bc9rRAGhQeUYxWiapLy4j2xPmadPI7jM8dvzDi/5JE1bZJi/gnRFKWcL
dxFdv7D8B3cNBzLvCJqzpx2cwXWdVaaUIeTMfPI5SrOS+pZfqdG2uOJbQ2ICa4dc
IU+EiDHq+0E56I3GQAfK0fwGFsKECuDSQCyVfpnzl9V1f/fjY0hSvw4fB37bmf29
2/o79fTPJy8GBNWYhoTOMzFNOG5wbzGuT/lnsqDP6HSFcmi4IB7HogcuDSsOygL6
dTalMpAh5FQEw809hCAdU/Br2Z8SiGaMLZE5ZzOq0b3TLxjrijxVutd9IpW5G7GS
QQr8OPvzbC4rx2Mx95XrbyxDPQSjvyNJVwMNaY2/vEIdrxxxE6cr0VNSnlvT4qCH
rDK8Y2An1GXOBQyRzBnBwNvMuC9DL0p9A4IAKiW8G+bhCaHHlgPB+d54G0HoVTvC
2oLDaWv+wGho/jvCx8X6/RFte1EdGzN2FqVQXK8ixPepgvPizXADQN6no5SPHF4m
GSNclWign3bV68PnDR1R
=bTBu
-----END PGP SIGNATURE-----
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug



--
Michael Lazin

to gar auto estin noein te kai ennai
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug