Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cygwin startup script

How can I run a script inside cygwin after it launches?

I want to automatically add some mounts and run other scripts inside cygwin whenever it starts. I see that in linux it is as simply as adding a shell file inside etc/init.d However, i tried adding this dir and chmod +x add a shell, chmod that shell file, but does not work.

Also if there is a way to run scripts when closing like umount, rmdir and others.

like image 742
codiac Avatar asked Mar 10 '13 17:03

codiac


People also ask

How do you autostart a script?

On Windows, the simplest way of running a program at startup is to place an executable file in the Startup folder. All the programs that are in this folder will be executed automatically when the computer opens. You can open this folder more easily by pressing WINDOWS KEY + R and then copying this text shell:startup .

How do I write a bash script in Cygwin?

So you have to use simply /bin/ as path for bash. Do a simple check: into a CygWin terminal type the command ls /bin/bash.exe : it list the executable for bash. open a windows CMD and type the command dir C:\cygwin\bin\bash.exe : it list the executable for bash.


2 Answers

What you are looking for is

~/.bash_profile

AKA

C:\cygwin\home\CPJ\.bash_profile

With a stock install this file is read on Cygwin startup. If you would like to add more files you can edit the .bash_profile file, for example

source foo.sh
source bar.sh
source baz.sh

Bash man page

like image 89
2 revs Avatar answered Sep 20 '22 12:09

2 revs


I am sorry to add to this very old question, but I think the accepted answer above has a glitch.

Try to add a command to your .bash_profile as follows which I use for example to open a local SSH port:

ssh -D1080 root@localhost -g localhost

When you login interactively, another SSH session starts, which starts another, and another, and you're in an endless loop.

Thought this might help someone..

.bash_login is what you actually need :P

like image 22
Ruslan Abuzant Avatar answered Sep 18 '22 12:09

Ruslan Abuzant