Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometimes my Windows server reboots at night to install new updates. Then the next day I find out that my cygwin instance has been stopped.

What I want is on Windows start, also run Cygwin AND run a specific command.

so, step 1: Right now I have a cygwin.bat to start cygwin:

@echo off
C:
chdir C:\cygwin\bin
bash --login -i

step 2 is to enter the command in the command windows that appears after running cygwin.bat:

cd /cygdrive/e/solr/apache-solr-4.0-2010-10-12_08-05-48/example/;java -Dsolr.solr.home="./example-DIH/solr/" -jar start.jar

But this command is what I want to have called automatically when i run cygwin.bat

How can I combine step 1 and step 2 into a single bat file which I can run on Windows start?

share|improve this question

migrated from stackoverflow.com Mar 10 '11 at 22:10

This question came from our site for professional and enthusiast programmers.

    
How goes the battle, Peter? – Dan Garthwaite Feb 2 '15 at 2:39

I try to keep my windows experience as UNIX like as possible. The first thing I would reach for would be installing cron and using @REBOOT to run a script on startup.

I found a good writeup on installing cron here: http://stackoverflow.com/a/7900158/1607020

Then, make a file in /etc/cron.d/myservicename with

@REBOOT /path/to/bash/script > /tmp/myservicename.log 2>&1 
share|improve this answer

You can create a new .bat file that runs on startup, and use the bash -c option to pass commands to bash when you start it. For example:

@echo off
C:
chdir C:\cygwin\bin
bash -c "echo 'it works'; read -n 1 -p 'Press any key to continue...' "

You could also make the changes to your cygwin.bat, but then the commands would run every time you start a shell.

share|improve this answer

I now have this:

@echo off

C:

chdir C:\cygwin\bin

bash -c cd /cygdrive/e/solr/apache-solr-4.0-2010-10-12_08-05-48/example/;java -Dsolr.solr.home="./example-DIH/solr/" -jar start.jar

bash -c "echo 'it works'; read -n 1 -p 'Press any key to continue...' "

But that doesnt seem to start cygwin with the commands I want to...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.