Can we build a tool for Windows to retrieve data from UNIX servers (putty console)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Can we build a tool for Windows to retrieve data from UNIX servers (putty console)
# 1  
Old 07-28-2014
Read your putty documentation again. Chapter 9 describes using pagent to supply authentication. Once pagent is running you can do stuff like this:
Code:
C:\Windows\System32>
C:\Windows\System32>
C:\Windows\System32>plink joeblow@corp-linux4  uname -a
Linux corp-linux4.dulles.orbital.com 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64

C:\Windows\System32>

This means you can write batch files (or powershell or vbscript, etc) that log into a unix system and run a command.
These 2 Users Gave Thanks to Perderabo For This Post:
# 2  
Old 07-30-2014
Hi Guys,

So i was able to run putty from command line and login to a server by using following command.
Code:
 
 
D:\putty.exe -ssh -t -t uname@ipaddress -pw passwd -m D:\commands.txt

However, after logging into the server1, it is not performing any command. What am i doing wrong.

Content of commands.txt

Code:
 
ssh server1
VAR1=$(/tmp/abc.sh server1)
echo "$VAR1"

# 3  
Old 07-30-2014
Quote:
Originally Posted by srkmish
Hi Guys,

So i was able to run putty from command line and login to a server by using following command.
Code:
 
 
D:\putty.exe -ssh -t -t uname@ipaddress -pw passwd -m D:\commands.txt

However, after logging into the server1, it is not performing any command. What am i doing wrong.
What does it do? Quit instantly? Just sit there?

Quote:
Content of commands.txt

Code:
 
ssh server1
VAR1=$(/tmp/abc.sh server1)
echo "$VAR1"

Aren't you in server1 already? Or if not, why not ssh to server1 directly?

Code:
echo $HOSTNAME
sleep 1

I had to add the 'sleep 1' because, without it, it ran and quit almost instantly, too fast to see. It works otherwise.
# 4  
Old 07-30-2014
Quote:
Originally Posted by Corona688
What does it do? Quit instantly? Just sit there?



Aren't you in server1 already? Or if not, why not ssh to server1 directly?

Code:
echo $HOSTNAME
sleep 1

I had to add the 'sleep 1' because, without it, it ran and quit almost instantly, too fast to see. It works otherwise.
(i) I cant ssh directly to that server. I have to login to a main server. From there i can ssh to any server
(ii) IF the command contains ssh server1 and then other commands, it just logs in to the server1 and it just sits there. Instead, if i just try to run a script ( from the main server) directly by including it in commands.txt , it quits instantly . Ill try including sleep command after running the script. Can you also tell me how to store the output of the script into a variable in command prompt.
# 5  
Old 07-30-2014
Try this:

Code:
VAR=$(ssh server1 /tmp/abc.sh server1)

# 6  
Old 08-01-2014
Quote:
Originally Posted by Corona688
Try this:

Code:
VAR=$(ssh server1 /tmp/abc.sh server1)

Actually i have to store value of the script output in DOS command prompt variable i.e. the command line logs into putty runs the script and then outputs the result to a variable which i can then utilize. Currently while running the following command it runs the script displays the value and exits after 100 seconds.

Code:
 
D:\putty.exe -ssh -t -t uname@ipaddress -pw passwd -m D:\commands.txt

Content of commands.txt
Code:
 
./Scripts/abc.sh
sleep 100

# 7  
Old 08-01-2014
Quote:
Originally Posted by srkmish
Actually i have to store value of the script output in DOS command prompt variable
PUTTY cannot do that. PUTTY is graphical, and displays the result graphically.

The plink utility I mentioned earlier is non-graphical, and prints to the CMD prompt, which you can capture with for -- for is a very, very versatile word in Window CMD.

Code:
c:> plink

PuTTY Link: command-line connection utility
Release 0.61
Usage: plink [options] [user@]host [command]
       ("host" can also be a PuTTY saved session name)
Options:
  -V        print version information and exit
  -pgpfp    print PGP key fingerprints and exit
  -v        show verbose messages
  -load sessname  Load settings from saved session
  -ssh -telnet -rlogin -raw -serial
            force use of a particular protocol
  -P port   connect to specified port
  -l user   connect with specified username
  -batch    disable all interactive prompts
The following options only apply to SSH connections:
  -pw passw login with specified password
  -D[listen-IP:]listen-port
            Dynamic SOCKS-based port forwarding
  -L[listen-IP:]listen-port:host:port
            Forward local port to remote address
  -R[listen-IP:]listen-port:host:port
            Forward remote port to local address
  -X -x     enable / disable X11 forwarding
  -A -a     enable / disable agent forwarding
  -t -T     enable / disable pty allocation
  -1 -2     force use of particular protocol version
  -4 -6     force use of IPv4 or IPv6
  -C        enable compression
  -i key    private key file for authentication
  -noagent  disable use of Pageant
  -agent    enable use of Pageant
  -m file   read remote command(s) from file
  -s        remote command is an SSH subsystem (SSH-2 only)
  -N        don't start a shell/command (SSH-2 only)
  -nc host:port
            open tunnel in place of session (SSH-2 only)
  -sercfg configuration-string (e.g. 19200,8,n,1,X)
            Specify the serial configuration (serial only)

C:> for /F %i in ('plink -l username -pw password myserver echo $HOSTNAME') do SET VAR=%i

C:> echo %VAR%

gentoo

C:>

So your command might look like:

Code:
for /F %i in ('plink -l username -pw password myserver ssh server1 /tmp/abc.sh server1') do SET VAR=%i

This is a complicated command... The stuff in green happens on your windows machine, the stuff in red happens on myserver, and the stuff in blue happens on server1. If it doesn't work, try each level individually to see where it is breaking down.

-agent insead of -pw would be better if you can use an agent, of course.
This User Gave Thanks to Corona688 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

I need to build a tool for Automatic GUI Validation

Hi Friends, So we have an internal link in my project. We generally login into it with our ids , then enter some generic values to check whether the functionality is working fine. If it is fine, the webpage delivers a successful preview or else throws error. What i want to do is write a... (3 Replies)
Discussion started by: srkmish
3 Replies

2. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

3. Windows & DOS: Issues & Discussions

Connecting to UNIX from Windows without using putty

Hi Is there any command which we can try connecting unix from windows without using any third party tool. Thanks in advance KVB (9 Replies)
Discussion started by: bikky6
9 Replies

4. Solaris

M5000 XSCF Console disconnecting when putty session is closed

Hi, I would appreciate some help. I remotely access, across a VPN, an M5000 and when I connect to the XSCF I can then access the OS using console -d0 and then I can get to the console. The problem I have is that I need to run something which will take many hours and I can't run it in the... (6 Replies)
Discussion started by: giles.cardew
6 Replies

5. Shell Programming and Scripting

regarding Color scheme in linux console connected through putty.

Hi All, I am connecting to SunOs 5.8 server from windows machine through putty. My problem is commands are not showing any colours results. I want to see 'ls' command should list directories in 'red' and files in 'green' etc. How to do it . Please help. Also How to enable syntax colouring in... (6 Replies)
Discussion started by: Sooraj_Linux
6 Replies

6. UNIX for Dummies Questions & Answers

startX windows application during boot.....putty connection takes the windows

Dear all i am new to linux/debian i run my application on the computer...during startup in bashrc i wrk wid dis script to invoke startx..i do this above command and it works perfectly... if && ; then startx -- -br 1>/dev/null exit 0 fi i use winscp for file transfer and putty for... (1 Reply)
Discussion started by: venkat_330
1 Replies

7. UNIX for Dummies Questions & Answers

tool scan my network and get all Unix servers

Hello, is there any tool where I can scan my netwrk and get all types of Unix servers? (2 Replies)
Discussion started by: fsmadi
2 Replies

8. UNIX for Dummies Questions & Answers

Windows to Linux remote console using VNC brings up blank console screen with only mouse pointer

:confused:Hi This was installed on the Linux box a few weeks back by a guy that no longer works for us. All worked fine until last week. Now when we connect its just a blank screen with no icons. I get a whole bunch of errors when starting the service too: Tue Feb 23 14:29:45 2010 ... (1 Reply)
Discussion started by: wbdevilliers
1 Replies

9. UNIX for Dummies Questions & Answers

Script runs fine on UNIX Server...Not through MSK Tool kit on Windows Server

I have a .sh script which was running fine on all the UNIX Servers (AIX, SunSolaris). The script requires two mandatory parameters and many optional parameters. Now at a different client place who are on a Windows Server, when I try to execute the script through MKS Toolkit, there are couple of... (5 Replies)
Discussion started by: madhunk
5 Replies
Login or Register to Ask a Question