Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Putty and command file

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
US
Hi All,
I am using Putty to SSH into our server and issue some application commands. This works fine when doing it directly.
I am trying to automate the process by executing Putty from the command line and specifying a command file to use.
This is not working.

When I manually connect to the server using the Putty GUI everything works. When I connect via command line it seems like different security is applied against the logon ID. The prompt is different and the application folders appear not to be within the path because the application commands fail while commands like ls work normally.
I am using the same login credentials as I do from the GUI.

Any ideas?

I am trying to automate a cleanup process that will involve a number of commands be executed one after another. Executing the command "opscmd" fails unless I specify the full path to the file but then it fails because it relies on other application files from other folders being somewhere in the path.
For some reason connecting by executing Putty from the command line seems to apply different restrictions on the logon ID.


At my age I still learn something new every day, but I forget two others.
 
Unrelated to your issue, but if you're running stuff from the command-line plink.exe (which is delivered with the full PuTTY package) is probably a better choice of utility.

When you run an ssh client with a supplied command it doesn't actually perform a full login, so the user's .profile is not run, hence the missing path. You may need to run it explicitly using something like:

Code:
"C:\Program Files\PuTTY\plink.exe" @hostname . ./.profile ; your_script_command

Annihilannic.
 
Thanks but unfortunately we did not get the full package and do not have plink.exe to use. To get it would require quite a challenge justifying the application and getting it approved for use. Lots of red tape.

I managed to work around the issue using a bit of VBS code to run putty with WshShell which actually launches the GUI and passes the parameters. The VBS code sends all the commands for me so it no longer needs to read the command file.

It is a kludgy way to do it but it works.
I have to connect to the server and issue a command that lists out all of the print jobs in the system then disconnect and read the log file that was generated and parse through for lines that contain the word INTERRUPTED, then extract all the job numbers from those lines and re-connect to the server to issue a command to put each job on hold.
I could not safely do it all in one pass because I am relying on the log file that is being generated by the session and the log file is not instantly updated.

I have it working, it's just not ideal as the script can only pause between commands, not actually watch for responses and handle them intelligently. I may write something better in the future but this is only a temporary method while waiting for a fix on the mainframe for the way these jobs come into the system.

Thanks.

At my age I still learn something new every day, but I forget two others.
 
I could be wrong but to me is sounds like you should be creating a script that runs on the server instead iof issuing the commands from the client machine.

once you have a working bash script you could even add it as a CRON job to execute automaticaly at regular intervals
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top