2
3
I need to login into remote server daily and perform same set of tasks. I am using Windows platform and the remote server is Unix. I use PuTTY to login to remote server. To reduce the manual work, I need to automate this task.
I tried this code:
start putty.exe -ssh -load session -l username -pw password -m command.txt -t
The command.txt
contains:
sudo su - user1
ls
cd directory
Only the first command in command.txt
is working and then PuTTY is expecting input from user.
I need all the commands to be run without user input.
Things that matters :
I am not root user
Access granted to switch to the
user1
without passwordI have a constraint of using PuTTY only (Plink installation is not permitted)
Try to verify which initialization scripts you run (automatically) when you connect "normally" if they differs from the ones you go to execute with your
command,txt
. Remember that in Linux and in Windows the end of line are different. Did you check if thecommand.txt
is with the CRLF line terminator (windows) or with the unix-like one? – Hastur – 2016-02-03T13:22:59.940How do I change CRLF line terminator to unix line terminator ? Can you please help ? @Hastur – learner1 – 2016-02-04T06:38:26.670
The most easy way in Windows is to have a word processor that saves it with the right terminator (I suppose even word can do it). My suggestion is to use notepad++. See here or do
– Hastur – 2016-02-04T06:43:35.433tr -d '\r' < infile > outfile
in Linux, or look here or ... write it in a Linux computer and import in the windows machine..:) Did you think about to write a script in the Linux machine and execute with a single command line?