Reading file from remote host?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading file from remote host?
# 1  
Old 02-27-2013
Question Reading file from remote host?

flamingo:~ jnojr$ ssh -t macbook sudo -v
Connection to macbook closed.
flamingo:~ jnojr$ ssh -t macbook sudo cat /etc/cma.conf | grep CMABuildNumber
Connection to macbook closed.
flamingo:~ jnojr$ ssh -t macbook sudo -k
Connection to macbook closed.
flamingo:~ jnojr$ ssh -t macbook sudo cat /etc/cma.conf | grep CMABuildNumber

And here it sits until I Ctrl-C it.

The problem is, doing this inside of a loop for a number of hosts means I need to enter my password over and over and over again. I can use expect to feed the password to 'sudo -v', but it doesn't persist outside of the expect section. Inside of expect, supposedly there are variables like $expect_out(buffer) or $expect_out(0,string) but I'm still trying to figure out how to use them.

How can I get my above result without changing anything on the remote host?

Last edited by jnojr; 02-28-2013 at 11:53 AM..
# 2  
Old 02-27-2013
How about this:


read -sp "Remote passwd: " PASS

for host in macbook tleepermacbook
    ssh -tt $host sudo grep CMABuildNumber /etc/cma.conf << EOF

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 02-28-2013
Because that will echo the value I want to stout, which doesn't do me any good... the value needs to be available to the script to echo out later. Every other value, which does not require root access, is loaded into a variable. There may be some other mechanism that can accomplish the same end, so I don't want to be fixated on variables.

ETA: You got me steered in the right direction, though! I wound up with:

  ssh $host ls /etc/cma.conf >/dev/null 2>&1
  if [ "$?" -eq 0 ]; then
    if [ -f /tmp/ ]; then rm -f /tmp/; fi
cat >/tmp/ <<EOF
ssh -tt $host sudo grep CMABuildNumber /etc/cma.conf <<EOS
    chmod 755 /tmp/
    HBSSVER=`/tmp/ | grep CMABuildNumber | cut -d'>' -f2 | cut -d'<' -f1`
    #if [ -f /tmp/ ]; then rm -f /tmp/; fi

It's messy and kludgy, but it works!

Last edited by jnojr; 02-28-2013 at 12:15 PM..
# 4  
Old 02-28-2013
This should work without the need to create a dummy /tmp/ script:

if ssh $host [ -f /etc/cma.conf ]
    HBSSVER=$(ssh -tt $host sudo grep CMABuildNumber /etc/cma.conf <<EOS 2> /dev/null | awk -F'[<>]' '{ print $3}'
    echo "Cannot contact $host or /etc/cma.conf does not exist"

Last edited by Chubler_XL; 02-28-2013 at 04:32 PM.. Reason: Added check for remote file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

SFTP file check through a remote host

Hi all, posting my first time, hope not breaking posting rules with it, if yes, let me know. I'm trying to build a script to check a file in an sftp server through a remote server. The intention is to check the file in a sftp host, and if the file is found or not, it should send an email.... (4 Replies)
Discussion started by: MrShinyPants
4 Replies

2. Shell Programming and Scripting

Check/get the exit status of a remote command executed on remote host through script

Geeks, Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s). Here's the complete... (5 Replies)
Discussion started by: lovesaikrishna
5 Replies

3. Shell Programming and Scripting

Pause processes in remote host and resume execution in another remote host

Hi, Given addresses of 2 remote machines, using a shell script is it possible to get the state of running processes in "src" stop all the processes in "src" exit out of "src" ssh into "dest" resume the state of executing processes captured in step 1 in "dest" Assumption: "src" is... (3 Replies)
Discussion started by: Saeya Darsan
3 Replies

4. Shell Programming and Scripting

Not able to execute the file in remote host using except utility

I am automating the SFTP keys setp process: So i created the expect script for controlling the output of shell below is my main code: #!/usr/bin/expect set fd set password close $fd set df set app close $df spawn ssh servername << pb Pb file: set df set app close $df (4 Replies)
Discussion started by: Manoj Bajpai
4 Replies

5. Shell Programming and Scripting

Polling for existence of file on remote host

I am polling a file on remote host. I have this code that works, but can't explain why it works. while 'ls /user/app1/.done'` ] do echo Sleeping for 5 secs sleep 5; done This code works in the way that when the .done file exists on the remote host, the script... (1 Reply)
Discussion started by: starlatch
1 Replies

6. UNIX for Advanced & Expert Users

Help! How to find the local host after few ssh hops to remote host???

I do a ssh to remote host(A1) from local host(L1). I then ssh to another remote(A2) from A1. When I do a who -m from A2, I see the "connected from" as "A1". => who -m userid pts/2 2010-03-27 08:47 (A1) I want to identify who is the local host who initiated the connection to... (3 Replies)
Discussion started by: gomes1333
3 Replies

7. Shell Programming and Scripting

running commands to remote host from centralized host

Gurus/Experts We have a centralized UNIX/Solaris server from where we can actually ssh to all other UNIX/Solaris servers...I need to write a script that reside on this centerlized server and do FileSystem monitoring (basically run df -h or -k) of other remote servers and then send an email to me... (6 Replies)
Discussion started by: anjum.suri
6 Replies

8. Solaris

define .rhost file for tape backup to remote host

howdy experts, i am using 2 server- Solaris 5.9 i have tape device attached with 1 of my solaris server. But others not. # modinfo|grep tape 152 13d43e4 1333c 33 1 st (SCSI tape Driver 1.231) now i want to Backup DATA file and System File in Tape Drive. How do I take data and... (3 Replies)
Discussion started by: thepurple
3 Replies

9. Shell Programming and Scripting

Reading from Remote Host

Hi I have a different architecture for my perl application. I have apache one server and data on another(not database). i need to read the data from other machine and that too securely. Also opening ports on apache machine is also restricted. Can anyone help me on this (2 Replies)
Discussion started by: Aditya_IT
2 Replies

10. Solaris

How to delete the files from local host to remote host

Hi all, i am copying .gz files from production server to development server using "scp" requirement is after copying .gz files i want to delete old .gz files(two days back) in development server from production server. like this way i need to delelte .log ,.z and .dmp files... (3 Replies)
Discussion started by: krishna176
3 Replies
Login or Register to Ask a Question

Featured Tech Videos