First you would need to create a separate file containing all the commands you would like to be executed.
Example: I would like to download and install Drupal on my domain using PuTTY. To do that you must:
First create a .txt file. Within that file are the commands. Mine are: "drush dl drupal" next line, "drush si --account-name=[account name] --account-pass=[account pass] --db-url=mysql://[user]:[pass]@localhost/[database name] --y"
After saving that file, you are now going to create a BAT file or type it in the CMD prompt:
- ssh.cmd
- @echo on [for you to see what's going on]
- [Navigate to your PuTTY installation. Mine is:] cd C:\Program Files\Putty
- Start
putty.exe -ssh [domain name] -l [username] -pw [password] -m [the directory of the .txt file you created which contains the codes you want to be executed]
The target server needs to be configured to accept setting environment variables for the 1st option to work. The second is actually working fine, the problem is that it is designed to mimic
ssh user@foo command
which will just connect, run command
and exit. You can have it remain open by giving it command; bash
but that won't work for setting your variables sice a new shell will be started after the variable has been set.
So, short of having root access to the server so that you can enable the setting of environmental variables, the only way I can think of for you to do this is to edit ~/.bashrc
the server and define your PS1
there. Add this line to ~/.bashrc
:
PS1="some stuff"
Now, every time you log into that server, the prompt will be set for you.
Another way to do this would be to use a different rcfile for your bash session. Create a new file with these lines:
source /etc/profile
source ~/.bashrc
PS1='some stuff'
Save it as, for example, ~/.myps1
, then in your putty settings, set the command to run on the remote server to:
bash --rcfile ~/.myps1
This will open a new shell session o the remote server and read in the file above which first reads .bashrc
and then sets PS1
.
Best Answer
putty has a setting to do exactly what you want: http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter4.html#config-closeonexit