Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Expect Script for backing up files on different servers Post 302919745 by richw92201 on Friday 3rd of October 2014 12:30:52 PM
Old 10-03-2014
Expect Script for backing up files on different servers

Hello,

I am trying to create an expect script that backups up data from multiple servers with the same username, but with different passwords for each server. For example, I have two servers with the "myuser" account with different passwords for that account for each server.

I went ahead and created a file called "IP_Passwords.txt" with the IP addresses of the servers as well as the passwords.
ex. "10.x.x.x changeme"

I am having difficulty trying to get the script to read the whole line of data so that I can separate them into separate variables to be referenced later on in the script.

I have tried the following commands, but the host variable only contains the server IP addresses:
Code:
set hostf [open "/var/tmp/IP_Passwords.txt" "r"]
foreach host [read $hostf]

Code:
set hostf [open "/var/tmp/IP_Passwords.txt" "r"]
foreach host [read -nonewline $hostf]

Is there any way for this command to read both the server IPs/Passwords so that I can use them later on? I have included my code below:

Code:
log_user 1
set hostf [open "/var/tmp/IP_Passwords.txt" "r"]
set user "myuser"
set timeout 60
set fullname ""


foreach host [read $hostf] {
   puts ""
   puts "Host: $host"
   spawn sftp -o StrictHostKeyChecking=no $user@$host
   set pass1 [read $hostf]
   puts "Password is: $pass1"
   expect {
                "*ssword:" {send "$pass1\r"}
                "(yes/no)?" {send "yes\r"; exp_continue }
                "Connection Refused" {puts "$host: Connection Refused"; continue}
                "No address associated to the name" {puts "$host: No address associated to the name"; continue}
                "no more authentication methods available" {puts "$host: Has no more authentication methods available"; continue}
                "node name or service name not known" {puts "$host: node name or service name not known"; continue}
                timeout {puts "$host: Script Timed Out"; continue}
          }
   sleep 2
   send "get /files_to_backup/*\r"
   expect "sftp> "
   sleep 1
}
close $hostf
exit

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Backing up files to a remote host question.

I need to know how to successfully back up(and compress) files from a local machine to a remote host. Will this work? tar -cvf backup.tar -C /user/somedir | gzip backup.tar | rsh some.domain.com/user/somedir thanks in advance! (3 Replies)
Discussion started by: WeNdeL
3 Replies

2. UNIX for Dummies Questions & Answers

Backing up or Archiving files in UNIX

Hi All, I am very new to the UNIX world and find myself in a new position at work that requires me to archive large CADD files based in both UNIX and Windows environments on CD's. I have one engineer that wants to export these files as a table (I guess) and it appears to have a lot of paper... (2 Replies)
Discussion started by: Dsartelle
2 Replies

3. UNIX for Advanced & Expert Users

automate backing up uploaded files

Hi, We are running FTP Server on UNIX (Solaris 9). Users login and upload (also download) files whenever required. Now, we have to automate the process which makes a copy of every file immediately after it gets uploaded to the FTP server (by any user). I've ruled out rsync,mirror,filesync... (2 Replies)
Discussion started by: prvnrk
2 Replies

4. UNIX for Dummies Questions & Answers

Script to login to several servers and get files

Hi ppl, I am looking out for a shell script a. That would have to login(from a main server) to say 16 servers individually. b.On each server go to a particular location, check if a particular file is generated on a date(say every sunday it gets generated and i would be interested in the latest... (0 Replies)
Discussion started by: yohasini
0 Replies

5. UNIX for Advanced & Expert Users

Script to login to several servers and get files

Hi ppl, I am looking out for a shell script a. That would have to login(from a main server) to say 16 servers individually. b.On each server go to a particular location, check if a particular file is generated on a date(say every sunday it gets generated and i would be interested in the latest... (1 Reply)
Discussion started by: yohasini
1 Replies

6. Shell Programming and Scripting

Script to login to several servers and get files

Hi ppl, I am looking out for a shell script a. That would have to login(from a main server) to say 16 servers individually. b.On each server go to a particular location, check if a particular file is generated on a date(say every sunday it gets generated and i would be interested in the latest... (8 Replies)
Discussion started by: yohasini
8 Replies

7. Shell Programming and Scripting

Help on Backing up all the files in the subdirectories under a parent directory

Hi, I am not too familiar with Unix scripting but I have to write code to find all the files under all the sub directories under a parent directory of unix location and move them to the corresponding Windows location. For eg: I have \home\sreenu\Files\ Under neath this I have multiple sub... (3 Replies)
Discussion started by: raj.sreenu
3 Replies

8. Solaris

Backing up Solaris 10 servers

Got 5-6 Solaris 10 servers in remote location - power work being done. At the moment, we just back up the application database that these servers run with the idea that if it all goes wrong we can rebuild and then restore the application. However, requirement is to provide a complete backup... (3 Replies)
Discussion started by: paulfoel
3 Replies

9. Shell Programming and Scripting

Shell script using expect to login to couple of remote servers and read "crontab -l"

I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP... (4 Replies)
Discussion started by: jaipsharma
4 Replies

10. Shell Programming and Scripting

Shell Script to delete files from 5 different servers

Hello, I'm new to shell scripting and need a quick note on how to write a shell script to perform deletion of files from 5 different hostnames in various locations. Found out to delete files from one path by using below command and made it to work on cron job but need to do it in a shell... (2 Replies)
Discussion started by: Teja G
2 Replies
fblocked(3tcl)						       Tcl Built-In Commands						    fblocked(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
fblocked - Test whether the last input operation exhausted all available input SYNOPSIS
fblocked channelId _________________________________________________________________ DESCRIPTION
The fblocked command returns 1 if the most recent input operation on channelId returned less information than requested because all avail- able input was exhausted. For example, if gets is invoked when there are only three characters available for input and no end-of-line sequence, gets returns an empty string and a subsequent call to fblocked will return 1. ChannelId must be an identifier for an open channel such as a Tcl standard channel (stdin, stdout, or stderr), the return value from an invocation of open or socket, or the result of a channel creation command provided by a Tcl extension. EXAMPLE
The fblocked command is particularly useful when writing network servers, as it allows you to write your code in a line-by-line style with- out preventing the servicing of other connections. This can be seen in this simple echo-service: # This is called whenever a new client connects to the server proc connect {chan host port} { set clientName [format <%s:%d> $host $port] puts "connection from $clientName" fconfigure $chan -blocking 0 -buffering line fileevent $chan readable [list echoLine $chan $clientName] } # This is called whenever either at least one byte of input # data is available, or the channel was closed by the client. proc echoLine {chan clientName} { gets $chan line if {[eof $chan]} { puts "finishing connection from $clientName" close $chan } elseif {![fblocked $chan]} { # Didn't block waiting for end-of-line puts "$clientName - $line" puts $chan $line } } # Create the server socket and enter the event-loop to wait # for incoming connections... socket -server connect 12345 vwait forever SEE ALSO
gets(3tcl), open(3tcl), read(3tcl), socket(3tcl), Tcl_StandardChannels(3tcl) KEYWORDS
blocking, nonblocking Tcl 7.5 fblocked(3tcl)
All times are GMT -4. The time now is 12:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy