Putty batch script example

Hi In order to send a batch of commands correctly to router, we could use script to send command line by line in Putty. Anyone can give some suggestions how to do that? The below is link for CRT. Do you think Putty has similar way to do that? Go to Solution. I don't know anything regarding this for Putty, but an alternative solution could be using "load set terminal" instead of just pasting commands in configuration mode.

Example with only two commands but it can easily be of set commands. It means it still send some error commands. Moreover this is a flow control issue.

Writing your First Shell Script for Linux Tutorial

To overcome this if the config changes are much big; please change the script to ftp the config changes to the box and later merge it with. WaitForString " " crt. Sign In. Global Communities. Community Resources. Turn on suggestions. Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for. Search instead for. Did you mean:. How to use script in Putty to send command line by line? Message 1 of 9 14, Views. All forum topics Previous Topic Next Topic.

Accepted by topic author eesunj. Re: How to use script in Putty to send command line by line? Message 2 of 9 14, Views. Thank you. Message 3 of 9 14, Views.

Message 4 of 9 14, Views.Previous Contents Index Next. Plink is a command-line connection tool similar to UNIX ssh. It is mostly used for automated operations, such as making CVS access a repository on a remote server. Plink is probably not what you want if you want to run an interactive session in a console window. Plink is a command line application. This means that you cannot just double-click on its icon to run it and instead you have to bring up a console window. It should be available from the Programs section of your Start Menu.

In order to use Plink, the file plink. To add the directory containing Plink to your PATH environment variable, type into the console window:. This will only work for the lifetime of that particular console window. BAT to include a set command like the one above.

This section describes the basics of how to use Plink for interactive logins and for automated processes. Once you've got a console window to type into, you can just type plink on its own to bring up a usage message.

This tells you the version of Plink you're using, and gives you a brief summary of how to use Plink:. To make a simple interactive connection to a remote server, just type plink and then the host name:. You should then be able to log in as normal and run a session. The output sent by the server will be written straight to your command prompt window, which will most likely not interpret terminal control codes in the way the server expects it to. So if you run any full-screen applications, for example, you can expect to see strange characters appearing in your window.

Interactive connections like this are not the main point of Plink. In order to connect with a different protocol, you can give the command line options -ssh-telnet-rlogin or -raw. To make an SSH connection, for example:.

If you have already set up a PuTTY saved session, then instead of supplying a host name, you can give the saved session name. This allows you to use public-key authentication, specify a user name, and use most of the other features of PuTTY:. You can also use the -load command-line option to load a saved session; see section 3.

If you use -loadthe saved session exists, and it specifies a hostname, you cannot also specify a host or user host argument - it will be treated as part of the remote command.

More typically Plink is used with the SSH protocol, to enable you to talk directly to a program running on the server. To do this you have to ensure Plink is using the SSH protocol. You can do this in several ways:. Usually Plink is not invoked directly by a user, but run automatically by another process. Therefore you typically do not want Plink to prompt you for a user name or a password.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

I have a Sun OS server with oracle configured on it ; with database 11g i want to take backupnow am connecting to terminal using ssh on putty console butwhat i need is finding a way to make it possible to connect using batch to ssh to the server then login then login to oracle then take the backup, is that possible and how.

If you really want to use putty to do this you can use the below in your command prompt in Windows this will open the putty and its terminal and execute the passed argument in you text file :. Where profileName is the profile saved in putty and the commandPath is your local directory text file containing the commands you want to execute and the username is the server user and ip is the IP address for the serverthe password is your server password then you can put whatever commands you want in your textFile.

Reference the. Learn more. How to open putty using batch and login then execute list of commands on bash [closed] Ask Question. Asked 3 years, 11 months ago. Active 3 years, 11 months ago. Viewed 37k times. Thank you. But what's happening here.

putty batch script example

Did you plan to do a tutorial? I am not sure about logging in to oracle server. Never used it But if it is possible via command line, it should be possible to automate it. If someone could help me-- how is this a Linux server, if it has Solaris operating system on it?

Active Oldest Votes. If you really want to use putty to do this you can use the below in your command prompt in Windows this will open the putty and its terminal and execute the passed argument in you text file : putty.

Tell me please how to prevent this? What - t mean at the end of first command line? The Overflow Blog.Previous Contents Next.

To do this, it will need either to be on your PATH or in your current directory. At this point you can type open server. The -l option is an alternative way to specify the user name to log in as, on the command line. Instead of typing psftp user hostyou can also type psftp host -l user. If the host you specify is a saved session, PSFTP uses any port number specified in that saved session. However, this may not always be appropriate.

If you are running PSFTP as part of some automated job, it will not be possible to enter a password by hand. Since specifying passwords in scripts is a bad idea for security reasons, you might want instead to consider using public-key authentication; see section 6. In normal operation, PSFTP is an interactive program which displays a command line and accepts commands from the keyboard.

If you need to do automated tasks with PSFTP, you would probably prefer to specify a set of commands in advance and have them executed automatically. The -b option allows you to do this. You use it with a file name containing batch commands. For example, you might create a file called myscript.

When you run a batch script in this way, PSFTP will abort the script if any command fails to complete successfully.

To change this behaviour, you can use the -be option section 6. With the -bc option, PSFTP will display prompts and commands just as if the commands had been typed at the keyboard.

So instead of seeing this:. When running a batch file, this option causes PSFTP to continue processing even if a command fails to complete successfully. You might want this to happen if you wanted to delete a file and didn't care if it was already not present, for example. If you use the -batch option, PSFTP will never give an interactive prompt while establishing the connection.

If the server's host key is invalid, for example see section 2. This may help PSFTP's behaviour when it is used in automated scripts: using -batchif something goes wrong at connection time, the batch job will fail rather than hang.

You can now type commands to perform file-transfer functions. This section lists all the available commands. For example, the command ren oldfilename newfilename splits up into three words: ren the command nameoldfilename the name of the file to be renamedand newfilename the new name to give the file. Sometimes you will need to specify file names that contain spaces. In order to do this, you can surround the file name with double quotes. This works equally well for local file names and remote file names:.

The double quotes themselves will not appear as part of the file names; they are removed by PSFTP and their only effect is to stop the spaces inside them from acting as word separators. If you need to use a double quote on some types of remote system, such as Unix, you are allowed to use double quotes in file namesyou can do this by doubling it.

This works both inside and outside double quotes.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. Super User is a question and answer site for computer enthusiasts and power users.

It only takes a minute to sign up. I often find myself opening an SSH session to run the same single command. I have everything setup to login without entering a password Via SSH Key-Based Authso I wondered if there was a way to create a shortcut or a batch file in Windows that would load PuTTY or a similar program, then fire off that command and likely exit if result is good.

Use the commandline PuTTY version plink. Use the -ssh switch to connect with SSH. With the -m switch you can include a command file:. You can download plink. Last step would be to create a shortcut including plink. Check out the Plink documentation for other various parameters: Plink. If you want to keep using PuTTY, you can use -m switch to specify a command file Plink supports the -m switch too. Then, before clicking " Open ", go back to the " Session " tab at the topand save your configuration.

Now, create a shortcut to putty.

putty batch script example

If you're using Windows 10, you might be interested to know that Microsoft reportedly has a beta of OpenSSH client and server :. The idea of running another remote service on Windows can be daunting so we do not blame you if you do not want to install the server.

Once installed, you can simply fire up your command line and use the OpenSSH client by typing ssh followed by the command such as ssh ubuntu someIP.

Putty: Using pscp/plink for automated file transfer and command execution from a Windows host

Just thought I'd insert the script I made to hopefully save some people hours of syntax and man page research. This is mostly useful for having a single script such as updating an SSL certificate across a range of machines. Sign up to join this community. The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. Asked 2 years, 3 months ago. Active 10 months ago. Viewed 24k times. Active Oldest Votes. With the -m switch you can include a command file: plink.

Smeerpijp Smeerpijp 1, 5 5 silver badges 15 15 bronze badges. No need to use -m switch with Plink, as it allow to specify command directly on its command-line, see my answer.

You can do plink site command the same way as with PuTTY except for command. Plink and PuTTY has basically the same set of command-line options. Plink accepts a command on its command line: plink. Martin Prikryl Martin Prikryl 14k 4 4 gold badges 46 46 silver badges bronze badges. You can use putty configurations to achieve this.

Load putty and configure your session. Enter the remote command that you'd like to run here: Then, before clicking " Open ", go back to the " Session " tab at the topand save your configuration.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up. I often find myself opening an SSH session to run the same single command. I have everything setup to login without entering a password Via SSH Key-Based Authso I wondered if there was a way to create a shortcut or a batch file in Windows that would load PuTTY or a similar program, then fire off that command and likely exit if result is good.

Use the commandline PuTTY version plink. Use the -ssh switch to connect with SSH. With the -m switch you can include a command file:.

You can download plink.

How to use script in Putty to send command line by line?

Last step would be to create a shortcut including plink. Check out the Plink documentation for other various parameters: Plink. If you want to keep using PuTTY, you can use -m switch to specify a command file Plink supports the -m switch too. Then, before clicking " Open ", go back to the " Session " tab at the topand save your configuration. Now, create a shortcut to putty. If you're using Windows 10, you might be interested to know that Microsoft reportedly has a beta of OpenSSH client and server :.

The idea of running another remote service on Windows can be daunting so we do not blame you if you do not want to install the server.

Once installed, you can simply fire up your command line and use the OpenSSH client by typing ssh followed by the command such as ssh ubuntu someIP. Just thought I'd insert the script I made to hopefully save some people hours of syntax and man page research.

This is mostly useful for having a single script such as updating an SSL certificate across a range of machines.

Sign up to join this community. The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. Asked 2 years, 3 months ago. Active 10 months ago. Viewed 24k times. Active Oldest Votes. With the -m switch you can include a command file: plink. Smeerpijp Smeerpijp 1, 5 5 silver badges 15 15 bronze badges. No need to use -m switch with Plink, as it allow to specify command directly on its command-line, see my answer. You can do plink site command the same way as with PuTTY except for command.

Plink and PuTTY has basically the same set of command-line options. Plink accepts a command on its command line: plink. Martin Prikryl Martin Prikryl 14k 4 4 gold badges 46 46 silver badges bronze badges. You can use putty configurations to achieve this. Load putty and configure your session. Enter the remote command that you'd like to run here: Then, before clicking " Open ", go back to the " Session " tab at the topand save your configuration.

putty batch script example

Attie Attie 15k 4 4 gold badges 42 42 silver badges 55 55 bronze badges. Yes, the session will end when the command terminates. If you'd like PuTTY to hang around once done e. Do you need to have the ssh client on the machine you are remoting into?In your command that runs psftp. Particularly when implementing the script from scratch, it is recommended to isolate the script from the graphical mode configuration to avoid the script breaking, when the GUI configuration changes.

If your psftp. That makes your script non-portable. WinSCP requires the script to end with the exit command for the process to close automatically. Use a chmod command with the same arguments. Use a get command with the same arguments. WinSCP downloads directories recursively by default. So remove a -r switch, if used. When downloading file s to a specific directory, make sure you terminate a target path with a backslash:.

Use a lcd command with the same argument. The WinSCP command get can accept multiple files as its arguments, but the last argument needs to be a target path. Use a mkdir command with the same argument. The WinSCP command put can accept multiple files as its arguments, but the last argument needs to be a target path. When moving file s to a different directory, make sure you terminate the target path with a slash:.

PSFTP aliases to the mv command, a rename and a renconvert the same way. When uploading file s to a specific directory, make sure you terminate the target path with a slash:. To explicitly resume transfer for example with an FTP protocoluse get -resume. To explicitly resume transfer for example with an FTP protocoluse put -resume. Use a rmdir command with the same arguments. WinSCP does not support exiting to a local shell.

For more advanced tasks, consider using WinSCP. NET assembly from PowerShell script. Associations SourceForge TeamForge. Specify the username and the hostname in a session URL in an open command in the script. Use an option echo on command at the beginning of the script.

Use an option batch on command at the beginning of the script to counter the default option batch abort. Though this makes the script dependent on GUI configuration see below. Specify the username in a session URL in an open command in the script.


comments

Leave a Reply

Your email address will not be published. Required fields are marked *