Python Forum
Automating putty for daily repetitive task
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automating putty for daily repetitive task
#1
I have a daily work on putty.
1)login to putty
2)type commands to give file path
3)run .sh file
This sh file has 43 options. I have to enter 1 to 43 from keyboard.
4)quit and close the putty session

Again I have to repeat the entire steps from connecting to putty for 50 times.

How can I automate the entire steps.
Can python do this? As I am new to python Please suggest how it can be achieved.
Reply
#2
Assuming you're using putty for SSH, your Python code can skip putty entirely and use Paramiko (https://github.com/paramiko/paramiko). Should solve your problem pretty well.
Reply
#3
Alternatively, if the remote machine is Unix-like, you may be able to set up a cron job. Cron can run scheduled tasks for you removing the need to SSH into the machine at all.

What is the nature of the input to the .sh file? Is it always the same or predictable?
Reply
#4
What I do is-
1) connecting to remote desktop.
2) connecting to putty.
3)login in to putty by entering username and password
4)type command:-
bash
cd my_folder
ls
my_file. sh BR0001
5)A menu option comes displaying 43 options.
6)press 1 once it is executed press 2 and so on up to 43.
7)press 0 to exit
8)close the session.
9) again start connecting to putty and repeat the next steps.

After running my_file.sh BR0001
It opens and a menu providing 43 options displays.
And for each steps there are sh files associated with it.when I press 1 then sh file associated with it executes when it completes then press 2 associated sh file executes and so on.

(Aug-30-2018, 06:27 PM)micseydel Wrote: Assuming you're using putty for SSH, your Python code can skip putty entirely and use Paramiko (https://github.com/paramiko/paramiko). Should solve your problem pretty well.
Thank you for the solution.It's helpful.
As I am new to python I am understanding paramiko to achieve it.

(Aug-30-2018, 07:21 PM)heras Wrote: Alternatively, if the remote machine is Unix-like, you may be able to set up a cron job. Cron can run scheduled tasks for you removing the need to SSH into the machine at all.

What is the nature of the input to the .sh file? Is it always the same or predictable?
Thanks for the solution.
The input to .sh is always same. The main sh file takes branch code of customer as an input and it provides menu option, that has 43 options. When I enter 1 this is for changing the bussing date and sh file is written for this so it executes this. Other options also has sh files for different tasks.
There are 20 branch codes and I have to to this 20 times giving their branch code as input.Each branch code is different.

Please guide me
1)How to set up connection with remote desktop.
2) after connecting to remote desktop open putty
3)login to putty
4)typing commands in putty

How can I code these using paramiko?
Any useful links so that I can get idea on how to start and proceed to achieve this.
Reply
#5
From your description it sounds like you are connecting to a linux machine. Once you have connected with putty, can you run the command uname -a and tell us the output?

So you run:
my_file.sh BR0001
enter: 1, 2, 3, 4, 5 ... 43, 0
my_file.sh BR0002
enter: 1, 2, 3, 4, 5 ... 43, 0
my_file.sh BR0003
enter: 1, 2, 3, 4, 5 ... 43, 0
etc, etc?

Are the branch codes always the same?

Can you talk to the people who made my_file.sh?
Without knowing more about my_file.sh it will be difficult to know how to enter 1,2,3 ... 43 into it.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020